Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use same logic for playback stop events and offline listen log #936

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/services/offline_listen_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class OfflineListenLogHelper {
/// The [timestamp] provided to this function should be in seconds
/// and marks the time the track was stopped.
Future<void> _logOfflineListen(OfflineListen listen) {
_logger.info("Storing offline listen for ${listen.name}");
return Future.wait([
Hive.box<OfflineListen>("OfflineListens").add(listen),
_exportOfflineListenToFile(listen)
Expand Down
14 changes: 8 additions & 6 deletions lib/services/playback_history_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,21 @@ class PlaybackHistoryService {
PlaybackState? previousState,
bool skippingForward,
) async {
final shouldReportPreviousTrack = previousItem != null &&
previousState != null &&
// don't submit stop events for idle tracks (at position 0 and not playing)
(previousState.playing ||
previousState.updatePosition != Duration.zero);

if (FinampSettingsHelper.finampSettings.isOffline) {
if (previousItem != null) {
if (shouldReportPreviousTrack) {
await _offlineListenLogHelper.logOfflineListen(previousItem.item);
}
return;
}

jellyfin_models.PlaybackProgressInfo? previousTrackPlaybackData;
if (previousItem != null &&
previousState != null &&
// don't submit stop events for idle tracks (at position 0 and not playing)
(previousState.playing ||
previousState.updatePosition != Duration.zero)) {
if (shouldReportPreviousTrack) {
previousTrackPlaybackData = generatePlaybackProgressInfoFromState(
previousItem,
previousState,
Expand Down