Skip to content

Commit 79f9d48

Browse files
fix: history are not correctly updated under certain conditions
1 parent 7ae45ad commit 79f9d48

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

android/src/main/kotlin/project/pipepipe/app/mediasource/CustomMediaSourceFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class CustomMediaSourceFactory() : MediaSource.Factory {
9191
mediaSourceFactory = this,
9292
)
9393
}
94+
GlobalScope.launch{ DatabaseOperations.directUpdateStreamHistoryByUrl(item.mediaId) }
9495
return createActualMediaSource(item, dashManifestString, dashUrl, hlsUrl, headers, sponsorblockUrl, relatedItemUrl)
9596
}
9697

library/src/commonMain/kotlin/project/pipepipe/app/database/DatabaseOperations.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,15 @@ object DatabaseOperations {
506506
SharedContext.notifyHistoryChanged()
507507
}
508508

509+
suspend fun directUpdateStreamHistoryByUrl(url: String) = withContext(Dispatchers.IO) {
510+
val watchHistoryMode = SharedContext.settingsManager.getString("watch_history_mode", "on_play")
511+
if (watchHistoryMode == "disabled") return@withContext
512+
513+
val currentTime = System.currentTimeMillis()
514+
updateStreamHistory(url, currentTime)
515+
SharedContext.notifyHistoryChanged()
516+
}
517+
509518
suspend fun isSubscribed(url: String): Boolean = withContext(Dispatchers.IO) {
510519
database.appDatabaseQueries
511520
.selectAllSubscriptions()

library/src/commonMain/kotlin/project/pipepipe/app/viewmodel/VideoDetailViewModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class VideoDetailViewModel()
9090
val watchHistoryMode = SharedContext.settingsManager.getString("watch_history_mode", "on_play")
9191
if (watchHistoryMode == "on_click") {
9292
DatabaseOperations.updateOrInsertStreamHistory(newStreamInfo)
93+
} else {
94+
DatabaseOperations.insertOrUpdateStream(newStreamInfo)
9395
}
9496

9597
if (newStreamInfo.commentUrl != null) {

0 commit comments

Comments
 (0)