mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-03 12:37:31 +01:00
Adding related event ids of live in entity
This commit is contained in:
parent
bad4eba153
commit
c404454cd7
@ -16,6 +16,7 @@
|
||||
|
||||
package org.matrix.android.sdk.internal.database.model.livelocation
|
||||
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmObject
|
||||
import io.realm.annotations.PrimaryKey
|
||||
|
||||
@ -29,6 +30,11 @@ internal open class LiveLocationShareAggregatedSummaryEntity(
|
||||
@PrimaryKey
|
||||
var eventId: String = "",
|
||||
|
||||
/**
|
||||
* List of event ids used to compute the aggregated summary data.
|
||||
*/
|
||||
var relatedEventIds: RealmList<String> = RealmList(),
|
||||
|
||||
var roomId: String = "",
|
||||
|
||||
var userId: String = "",
|
||||
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.room.aggregation.livelocation
|
||||
|
||||
import androidx.work.ExistingWorkPolicy
|
||||
import io.realm.Realm
|
||||
import io.realm.RealmList
|
||||
import org.matrix.android.sdk.api.extensions.orTrue
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||
@ -73,6 +74,11 @@ internal class LiveLocationAggregationProcessor @Inject constructor(
|
||||
eventId = targetEventId
|
||||
)
|
||||
|
||||
if (!isLive && !event.eventId.isNullOrEmpty()) {
|
||||
// in this case, the received event is a new state event related to the previous one
|
||||
addRelatedEventId(event.eventId, aggregatedSummary)
|
||||
}
|
||||
|
||||
// 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) }
|
||||
@ -144,6 +150,11 @@ internal class LiveLocationAggregationProcessor @Inject constructor(
|
||||
roomId = roomId,
|
||||
eventId = relatedEventId
|
||||
)
|
||||
|
||||
if (!event.eventId.isNullOrEmpty()) {
|
||||
addRelatedEventId(event.eventId, aggregatedSummary)
|
||||
}
|
||||
|
||||
val updatedLocationTimestamp = content.getBestTimestampMillis() ?: 0
|
||||
val currentLocationTimestamp = ContentMapper
|
||||
.map(aggregatedSummary.lastLocationContent)
|
||||
@ -160,6 +171,17 @@ internal class LiveLocationAggregationProcessor @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun addRelatedEventId(
|
||||
eventId: String,
|
||||
aggregatedSummary: LiveLocationShareAggregatedSummaryEntity
|
||||
) {
|
||||
Timber.d("adding related event id $eventId to summary of id ${aggregatedSummary.eventId}")
|
||||
val updatedEventIds = aggregatedSummary.relatedEventIds.toMutableList().also {
|
||||
it.add(eventId)
|
||||
}
|
||||
aggregatedSummary.relatedEventIds = RealmList(*updatedEventIds.toTypedArray())
|
||||
}
|
||||
|
||||
private fun deactivateAllPreviousBeacons(realm: Realm, roomId: String, userId: String, currentEventId: String) {
|
||||
LiveLocationShareAggregatedSummaryEntity
|
||||
.findActiveLiveInRoomForUser(
|
||||
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.room.aggregation.livelocation
|
||||
|
||||
import androidx.work.ExistingWorkPolicy
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
import org.amshove.kluent.shouldContain
|
||||
import org.junit.Test
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.events.model.UnsignedData
|
||||
@ -199,9 +200,10 @@ internal class LiveLocationAggregationProcessorTest {
|
||||
age = 123,
|
||||
replacesState = AN_EVENT_ID
|
||||
)
|
||||
val stateEventId = "state-event-id"
|
||||
val event = Event(
|
||||
senderId = A_SENDER_ID,
|
||||
eventId = "",
|
||||
eventId = stateEventId,
|
||||
unsignedData = unsignedData
|
||||
)
|
||||
val beaconInfo = MessageBeaconInfoContent(
|
||||
@ -237,6 +239,7 @@ internal class LiveLocationAggregationProcessorTest {
|
||||
aggregatedEntity.roomId shouldBeEqualTo A_ROOM_ID
|
||||
aggregatedEntity.userId shouldBeEqualTo A_SENDER_ID
|
||||
aggregatedEntity.isActive shouldBeEqualTo false
|
||||
aggregatedEntity.relatedEventIds shouldContain stateEventId
|
||||
aggregatedEntity.endOfLiveTimestampMillis shouldBeEqualTo A_TIMESTAMP + A_TIMEOUT_MILLIS
|
||||
aggregatedEntity.lastLocationContent shouldBeEqualTo null
|
||||
previousEntities.forEach { entity ->
|
||||
@ -324,7 +327,7 @@ internal class LiveLocationAggregationProcessorTest {
|
||||
val lastBeaconLocationContent = MessageBeaconLocationDataContent(
|
||||
unstableTimestampMillis = A_TIMESTAMP
|
||||
)
|
||||
givenLastSummaryQueryReturns(
|
||||
val aggregatedEntity = givenLastSummaryQueryReturns(
|
||||
eventId = AN_EVENT_ID,
|
||||
roomId = A_ROOM_ID,
|
||||
beaconLocationContent = lastBeaconLocationContent
|
||||
@ -340,6 +343,7 @@ internal class LiveLocationAggregationProcessorTest {
|
||||
)
|
||||
|
||||
result shouldBeEqualTo false
|
||||
aggregatedEntity.relatedEventIds shouldContain AN_EVENT_ID
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -353,7 +357,7 @@ internal class LiveLocationAggregationProcessorTest {
|
||||
val lastBeaconLocationContent = MessageBeaconLocationDataContent(
|
||||
unstableTimestampMillis = A_TIMESTAMP - 60_000
|
||||
)
|
||||
val entity = givenLastSummaryQueryReturns(
|
||||
val aggregatedEntity = givenLastSummaryQueryReturns(
|
||||
eventId = AN_EVENT_ID,
|
||||
roomId = A_ROOM_ID,
|
||||
beaconLocationContent = lastBeaconLocationContent
|
||||
@ -369,7 +373,8 @@ internal class LiveLocationAggregationProcessorTest {
|
||||
)
|
||||
|
||||
result shouldBeEqualTo true
|
||||
val savedLocationData = ContentMapper.map(entity.lastLocationContent).toModel<MessageBeaconLocationDataContent>()
|
||||
aggregatedEntity.relatedEventIds shouldContain AN_EVENT_ID
|
||||
val savedLocationData = ContentMapper.map(aggregatedEntity.lastLocationContent).toModel<MessageBeaconLocationDataContent>()
|
||||
savedLocationData?.getBestTimestampMillis() shouldBeEqualTo A_TIMESTAMP
|
||||
savedLocationData?.getBestLocationInfo()?.geoUri shouldBeEqualTo A_GEO_URI
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user