Prevent dup history broadcasts

This commit is contained in:
Kelvin 2024-11-26 18:47:33 +01:00
parent 14b699485a
commit 192df0a3b8
5 changed files with 18 additions and 15 deletions

View file

@ -59,6 +59,7 @@ class StateHistory {
return getHistoryPosition(url) > duration * 0.7;
}
private var _lastHistoryBroadcast = "";
fun updateHistoryPosition(liveObj: IPlatformVideo, index: DBHistory.Index, updateExisting: Boolean, position: Long = -1L, date: OffsetDateTime? = null, isUserAction: Boolean = false): Long {
val pos = if(position < 0) 0 else position;
val historyVideo = index.obj;
@ -82,19 +83,21 @@ class StateHistory {
historyVideo.date = date ?: OffsetDateTime.now();
_historyDBStore.update(index.id!!, historyVideo);
onHistoricVideoChanged.emit(liveObj, pos);
}
if(isUserAction) {
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
if(StateSync.instance.hasAtLeastOneOnlineDevice()) {
Logger.i(TAG, "SyncHistory playback broadcasted (${liveObj.name}: ${position})");
StateSync.instance.broadcastJsonData(
GJSyncOpcodes.syncHistory,
listOf(historyVideo)
);
}
};
val historyBroadcastSig = "${historyVideo.position}${historyVideo.video.id.value ?: historyVideo.video.url}"
if(isUserAction && _lastHistoryBroadcast != historyBroadcastSig) {
_lastHistoryBroadcast = historyBroadcastSig;
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
if(StateSync.instance.hasAtLeastOneOnlineDevice()) {
Logger.i(TAG, "SyncHistory playback broadcasted (${liveObj.name}: ${position})");
StateSync.instance.broadcastJsonData(
GJSyncOpcodes.syncHistory,
listOf(historyVideo)
);
}
};
}
}
return positionBefore;
}

@ -1 +1 @@
Subproject commit 946bc835e18d62a584de7150a05cebea7c832b51
Subproject commit 62e19e2e61ac55ee0d6d836dc1953c5e2b6751b3

@ -1 +1 @@
Subproject commit e2d896ac45357e85b88a8d1f0a1fc5f4b72bfcfa
Subproject commit f018ca772da6bfc287fa4ef767a4f13c601b52c4

@ -1 +1 @@
Subproject commit 946bc835e18d62a584de7150a05cebea7c832b51
Subproject commit 62e19e2e61ac55ee0d6d836dc1953c5e2b6751b3

@ -1 +1 @@
Subproject commit e2d896ac45357e85b88a8d1f0a1fc5f4b72bfcfa
Subproject commit f018ca772da6bfc287fa4ef767a4f13c601b52c4