Adding start of live timestamp threshold when deactivating previous beacons

This commit is contained in:
Maxime NATUREL 2022-07-19 14:51:44 +02:00
parent 448b6e1c74
commit 3ad754e732
3 changed files with 15 additions and 3 deletions

View File

@ -44,6 +44,8 @@ internal open class LiveLocationShareAggregatedSummaryEntity(
*/ */
var isActive: Boolean? = null, var isActive: Boolean? = null,
var startOfLiveTimestampMillis: Long? = null,
var endOfLiveTimestampMillis: Long? = null, var endOfLiveTimestampMillis: Long? = null,
/** /**

View File

@ -92,12 +92,14 @@ internal fun LiveLocationShareAggregatedSummaryEntity.Companion.findActiveLiveIn
roomId: String, roomId: String,
userId: String, userId: String,
ignoredEventId: String, ignoredEventId: String,
startOfLiveTimestampThreshold: Long,
): List<LiveLocationShareAggregatedSummaryEntity> { ): List<LiveLocationShareAggregatedSummaryEntity> {
return LiveLocationShareAggregatedSummaryEntity return LiveLocationShareAggregatedSummaryEntity
.whereRoomId(realm, roomId = roomId) .whereRoomId(realm, roomId = roomId)
.equalTo(LiveLocationShareAggregatedSummaryEntityFields.USER_ID, userId) .equalTo(LiveLocationShareAggregatedSummaryEntityFields.USER_ID, userId)
.equalTo(LiveLocationShareAggregatedSummaryEntityFields.IS_ACTIVE, true) .equalTo(LiveLocationShareAggregatedSummaryEntityFields.IS_ACTIVE, true)
.notEqualTo(LiveLocationShareAggregatedSummaryEntityFields.EVENT_ID, ignoredEventId) .notEqualTo(LiveLocationShareAggregatedSummaryEntityFields.EVENT_ID, ignoredEventId)
.lessThan(LiveLocationShareAggregatedSummaryEntityFields.START_OF_LIVE_TIMESTAMP_MILLIS, startOfLiveTimestampThreshold)
.findAll() .findAll()
.toList() .toList()
} }

View File

@ -84,11 +84,12 @@ internal class LiveLocationAggregationProcessor @Inject constructor(
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") Timber.d("updating summary of id=$targetEventId with isActive=$isActive and endTimestamp=$endOfLiveTimestampMillis")
aggregatedSummary.startOfLiveTimestampMillis = content.getBestTimestampMillis()
aggregatedSummary.endOfLiveTimestampMillis = endOfLiveTimestampMillis aggregatedSummary.endOfLiveTimestampMillis = endOfLiveTimestampMillis
aggregatedSummary.isActive = isActive aggregatedSummary.isActive = isActive
aggregatedSummary.userId = event.senderId aggregatedSummary.userId = event.senderId
deactivateAllPreviousBeacons(realm, roomId, event.senderId, targetEventId) deactivateAllPreviousBeacons(realm, roomId, event.senderId, targetEventId, content.getBestTimestampMillis() ?: 0)
if (isActive) { if (isActive) {
scheduleDeactivationAfterTimeout(targetEventId, roomId, endOfLiveTimestampMillis) scheduleDeactivationAfterTimeout(targetEventId, roomId, endOfLiveTimestampMillis)
@ -182,13 +183,20 @@ internal class LiveLocationAggregationProcessor @Inject constructor(
aggregatedSummary.relatedEventIds = RealmList(*updatedEventIds.toTypedArray()) aggregatedSummary.relatedEventIds = RealmList(*updatedEventIds.toTypedArray())
} }
private fun deactivateAllPreviousBeacons(realm: Realm, roomId: String, userId: String, currentEventId: String) { private fun deactivateAllPreviousBeacons(
realm: Realm,
roomId: String,
userId: String,
currentEventId: String,
currentEventTimestamp: Long
) {
LiveLocationShareAggregatedSummaryEntity LiveLocationShareAggregatedSummaryEntity
.findActiveLiveInRoomForUser( .findActiveLiveInRoomForUser(
realm = realm, realm = realm,
roomId = roomId, roomId = roomId,
userId = userId, userId = userId,
ignoredEventId = currentEventId ignoredEventId = currentEventId,
startOfLiveTimestampThreshold = currentEventTimestamp
) )
.forEach { it.isActive = false } .forEach { it.isActive = false }
} }