🐛 Fix spotify presence lease again
This commit is contained in:
@@ -23,10 +23,8 @@ public class SpotifyPresenceService(
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var connection in userConnections)
|
||||
{
|
||||
await UpdateSpotifyPresenceAsync(connection.Account);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the Spotify presence activity for a specific user
|
||||
@@ -59,7 +57,7 @@ public class SpotifyPresenceService(
|
||||
|
||||
// Get currently playing track
|
||||
var currentlyPlaying = await spotify.Player.GetCurrentlyPlaying(new PlayerCurrentlyPlayingRequest());
|
||||
if (currentlyPlaying?.Item == null || currentlyPlaying.IsPlaying == false)
|
||||
if (currentlyPlaying?.Item == null || !currentlyPlaying.IsPlaying)
|
||||
{
|
||||
// Nothing playing or paused, remove the presence
|
||||
await RemoveSpotifyPresenceAsync(account.Id);
|
||||
@@ -68,11 +66,20 @@ public class SpotifyPresenceService(
|
||||
|
||||
var presenceActivity = ParseCurrentlyPlayingToPresenceActivity(account.Id, currentlyPlaying);
|
||||
|
||||
// Update or create the presence activity
|
||||
await accountEventService.UpdateActivityByManualId(
|
||||
// Try to update existing activity first
|
||||
var updatedActivity = await accountEventService.UpdateActivityByManualId(
|
||||
"spotify",
|
||||
account.Id,
|
||||
activity =>
|
||||
UpdateActivityWithPresenceData,
|
||||
5
|
||||
);
|
||||
|
||||
// If update failed (no existing activity), create a new one
|
||||
if (updatedActivity == null)
|
||||
await accountEventService.SetActivity(presenceActivity, 5);
|
||||
|
||||
// Local function to avoid capturing external variables in lambda
|
||||
void UpdateActivityWithPresenceData(SnPresenceActivity activity)
|
||||
{
|
||||
activity.Type = PresenceType.Music;
|
||||
activity.Title = presenceActivity.Title;
|
||||
@@ -83,9 +90,7 @@ public class SpotifyPresenceService(
|
||||
activity.TitleUrl = presenceActivity.TitleUrl;
|
||||
activity.SubtitleUrl = presenceActivity.SubtitleUrl;
|
||||
activity.Meta = presenceActivity.Meta;
|
||||
},
|
||||
10 // 10 minute lease
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user