Fixing aggregation process

This commit is contained in:
Maxime NATUREL 2022-05-31 15:56:23 +02:00
parent 9874bdeeab
commit 102684ed88
1 changed files with 7 additions and 4 deletions

View File

@ -67,16 +67,18 @@ internal class LiveLocationAggregationProcessor @Inject constructor(
eventId = targetEventId eventId = targetEventId
) )
Timber.d("updating summary of id=$targetEventId with isLive=${content.isLive}") // remote event can stay with isLive == true while the local summary is no more active
val isActive = aggregatedSummary.isActive.orTrue() && isLive
val endOfLiveTimestampMillis = content.getBestTimestampMillis()?.let { it + (content.timeout ?: 0) } val endOfLiveTimestampMillis = content.getBestTimestampMillis()?.let { it + (content.timeout ?: 0) }
Timber.d("updating summary of id=$targetEventId with isActive=$isActive and endTimestamp=$endOfLiveTimestampMillis")
aggregatedSummary.endOfLiveTimestampMillis = endOfLiveTimestampMillis aggregatedSummary.endOfLiveTimestampMillis = endOfLiveTimestampMillis
aggregatedSummary.isActive = isLive aggregatedSummary.isActive = isActive
aggregatedSummary.userId = event.senderId aggregatedSummary.userId = event.senderId
deactivateAllPreviousBeacons(realm, roomId, event.senderId, targetEventId) deactivateAllPreviousBeacons(realm, roomId, event.senderId, targetEventId)
if (isLive) { if (isActive) {
scheduleDeactivationAfterTimeout(targetEventId, roomId, endOfLiveTimestampMillis) scheduleDeactivationAfterTimeout(targetEventId, roomId, endOfLiveTimestampMillis)
} else { } else {
cancelDeactivationAfterTimeout(targetEventId, roomId) cancelDeactivationAfterTimeout(targetEventId, roomId)
@ -90,6 +92,7 @@ internal class LiveLocationAggregationProcessor @Inject constructor(
val workData = WorkerParamsFactory.toData(workParams) val workData = WorkerParamsFactory.toData(workParams)
val workName = DeactivateLiveLocationShareWorker.getWorkName(eventId = eventId, roomId = roomId) val workName = DeactivateLiveLocationShareWorker.getWorkName(eventId = eventId, roomId = roomId)
val workDelayMillis = (endOfLiveTimestampMillis - clock.epochMillis()).coerceAtLeast(0) val workDelayMillis = (endOfLiveTimestampMillis - clock.epochMillis()).coerceAtLeast(0)
Timber.d("scheduling deactivation of $eventId after $workDelayMillis millis")
val workRequest = workManagerProvider.matrixOneTimeWorkRequestBuilder<DeactivateLiveLocationShareWorker>() val workRequest = workManagerProvider.matrixOneTimeWorkRequestBuilder<DeactivateLiveLocationShareWorker>()
.setInitialDelay(workDelayMillis, TimeUnit.MILLISECONDS) .setInitialDelay(workDelayMillis, TimeUnit.MILLISECONDS)
.setInputData(workData) .setInputData(workData)