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