Skip to content

Commit

Permalink
fix: track watch sessions but don't sync remote
Browse files Browse the repository at this point in the history
Always track the watch session if syncing during or after playback
is enabled, but don't actually sync during the playback if syncing
during playback is not enabled. This is to make sure the syncing
after playback is not treated as an accidental event because it is
below the initial skip event count if we don't track the events
that would be fired during the playback.
  • Loading branch information
revam committed Sep 21, 2023
1 parent 58646fe commit 1be3cf9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Shokofin/Sync/UserDataSyncManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public bool ShouldSendEvent(bool isPauseOrResumeEvent = false)

public void OnSessionStarted(object sender, SessionEventArgs e)
{
if (TryGetUserConfiguration(e.SessionInfo.UserId, out var userConfig) && userConfig.SyncUserDataUnderPlayback) {
if (TryGetUserConfiguration(e.SessionInfo.UserId, out var userConfig) && (userConfig.SyncUserDataUnderPlayback || userConfig.SyncUserDataAfterPlayback)) {
var sessionMetadata = new SessionMetadata(Logger) {
ItemId = Guid.Empty,
Session = e.SessionInfo,
Expand All @@ -114,7 +114,7 @@ public void OnSessionStarted(object sender, SessionEventArgs e)
ActiveSessions.TryAdd(e.SessionInfo.UserId, sessionMetadata);
}
foreach (var user in e.SessionInfo.AdditionalUsers) {
if (TryGetUserConfiguration(e.SessionInfo.UserId, out userConfig) && userConfig.SyncUserDataUnderPlayback) {
if (TryGetUserConfiguration(e.SessionInfo.UserId, out userConfig) && (userConfig.SyncUserDataUnderPlayback || userConfig.SyncUserDataAfterPlayback)) {
var sessionMetadata = new SessionMetadata(Logger) {
ItemId = Guid.Empty,
Session = e.SessionInfo,
Expand Down Expand Up @@ -177,7 +177,7 @@ public async void OnUserDataSaved(object sender, UserDataSaveEventArgs e)
sessionMetadata.SkipCount = userConfig.SyncUserDataInitialSkipEventCount;

Logger.LogInformation("Playback has started. (File={FileId})", fileId);
if (sessionMetadata.ShouldSendEvent())
if (sessionMetadata.ShouldSendEvent() && userConfig.SyncUserDataUnderPlayback)
success = await APIClient.ScrobbleFile(fileId, episodeId, "play", sessionMetadata.Ticks, userConfig.Token).ConfigureAwait(false);
}
else {
Expand All @@ -190,7 +190,7 @@ public async void OnUserDataSaved(object sender, UserDataSaveEventArgs e)
sessionMetadata.SentPaused = true;

Logger.LogInformation("Playback was paused. (File={FileId})", fileId);
if (sessionMetadata.ShouldSendEvent(true))
if (sessionMetadata.ShouldSendEvent(true) && userConfig.SyncUserDataUnderPlayback )
success = await APIClient.ScrobbleFile(fileId, episodeId, "pause", sessionMetadata.Ticks, userConfig.Token).ConfigureAwait(false);
}
// The playback was resumed.
Expand All @@ -200,7 +200,7 @@ public async void OnUserDataSaved(object sender, UserDataSaveEventArgs e)
sessionMetadata.SentPaused = false;

Logger.LogInformation("Playback was resumed. (File={FileId})", fileId);
if (sessionMetadata.ShouldSendEvent(true))
if (sessionMetadata.ShouldSendEvent(true) && userConfig.SyncUserDataUnderPlayback )
success = await APIClient.ScrobbleFile(fileId, episodeId, "resume", sessionMetadata.Ticks, userConfig.Token).ConfigureAwait(false);
}
// Return early if we're not scrobbling.
Expand All @@ -216,10 +216,11 @@ public async void OnUserDataSaved(object sender, UserDataSaveEventArgs e)
++sessionMetadata.ScrobbleTicks < userConfig.SyncUserDataUnderPlaybackAtEveryXTicks)
return;

Logger.LogInformation("Scrobbled during playback. (File={FileId})", fileId);
Logger.LogInformation("Playback is running. (File={FileId})", fileId);
sessionMetadata.ScrobbleTicks = 0;
if (sessionMetadata.ShouldSendEvent())
if (sessionMetadata.ShouldSendEvent() && userConfig.SyncUserDataUnderPlayback ) {
success = await APIClient.ScrobbleFile(fileId, episodeId, "scrobble", sessionMetadata.Ticks, userConfig.Token).ConfigureAwait(false);
}
}
}
break;
Expand Down

0 comments on commit 1be3cf9

Please sign in to comment.