mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-03 20:47:32 +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
|
package org.matrix.android.sdk.internal.database.model.livelocation
|
||||||
|
|
||||||
|
import io.realm.RealmList
|
||||||
import io.realm.RealmObject
|
import io.realm.RealmObject
|
||||||
import io.realm.annotations.PrimaryKey
|
import io.realm.annotations.PrimaryKey
|
||||||
|
|
||||||
@ -29,6 +30,11 @@ internal open class LiveLocationShareAggregatedSummaryEntity(
|
|||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
var eventId: String = "",
|
var eventId: String = "",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of event ids used to compute the aggregated summary data.
|
||||||
|
*/
|
||||||
|
var relatedEventIds: RealmList<String> = RealmList(),
|
||||||
|
|
||||||
var roomId: String = "",
|
var roomId: String = "",
|
||||||
|
|
||||||
var userId: String = "",
|
var userId: String = "",
|
||||||
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.room.aggregation.livelocation
|
|||||||
|
|
||||||
import androidx.work.ExistingWorkPolicy
|
import androidx.work.ExistingWorkPolicy
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
|
import io.realm.RealmList
|
||||||
import org.matrix.android.sdk.api.extensions.orTrue
|
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.Event
|
||||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||||
@ -73,6 +74,11 @@ internal class LiveLocationAggregationProcessor @Inject constructor(
|
|||||||
eventId = targetEventId
|
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
|
// remote event can stay with isLive == true while the local summary is no more active
|
||||||
val isActive = aggregatedSummary.isActive.orTrue() && isLive
|
val isActive = aggregatedSummary.isActive.orTrue() && isLive
|
||||||
val endOfLiveTimestampMillis = content.getBestTimestampMillis()?.let { it + (content.timeout ?: 0) }
|
val endOfLiveTimestampMillis = content.getBestTimestampMillis()?.let { it + (content.timeout ?: 0) }
|
||||||
@ -144,6 +150,11 @@ internal class LiveLocationAggregationProcessor @Inject constructor(
|
|||||||
roomId = roomId,
|
roomId = roomId,
|
||||||
eventId = relatedEventId
|
eventId = relatedEventId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!event.eventId.isNullOrEmpty()) {
|
||||||
|
addRelatedEventId(event.eventId, aggregatedSummary)
|
||||||
|
}
|
||||||
|
|
||||||
val updatedLocationTimestamp = content.getBestTimestampMillis() ?: 0
|
val updatedLocationTimestamp = content.getBestTimestampMillis() ?: 0
|
||||||
val currentLocationTimestamp = ContentMapper
|
val currentLocationTimestamp = ContentMapper
|
||||||
.map(aggregatedSummary.lastLocationContent)
|
.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) {
|
private fun deactivateAllPreviousBeacons(realm: Realm, roomId: String, userId: String, currentEventId: String) {
|
||||||
LiveLocationShareAggregatedSummaryEntity
|
LiveLocationShareAggregatedSummaryEntity
|
||||||
.findActiveLiveInRoomForUser(
|
.findActiveLiveInRoomForUser(
|
||||||
|
@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.room.aggregation.livelocation
|
|||||||
|
|
||||||
import androidx.work.ExistingWorkPolicy
|
import androidx.work.ExistingWorkPolicy
|
||||||
import org.amshove.kluent.shouldBeEqualTo
|
import org.amshove.kluent.shouldBeEqualTo
|
||||||
|
import org.amshove.kluent.shouldContain
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.matrix.android.sdk.api.session.events.model.Event
|
import org.matrix.android.sdk.api.session.events.model.Event
|
||||||
import org.matrix.android.sdk.api.session.events.model.UnsignedData
|
import org.matrix.android.sdk.api.session.events.model.UnsignedData
|
||||||
@ -199,9 +200,10 @@ internal class LiveLocationAggregationProcessorTest {
|
|||||||
age = 123,
|
age = 123,
|
||||||
replacesState = AN_EVENT_ID
|
replacesState = AN_EVENT_ID
|
||||||
)
|
)
|
||||||
|
val stateEventId = "state-event-id"
|
||||||
val event = Event(
|
val event = Event(
|
||||||
senderId = A_SENDER_ID,
|
senderId = A_SENDER_ID,
|
||||||
eventId = "",
|
eventId = stateEventId,
|
||||||
unsignedData = unsignedData
|
unsignedData = unsignedData
|
||||||
)
|
)
|
||||||
val beaconInfo = MessageBeaconInfoContent(
|
val beaconInfo = MessageBeaconInfoContent(
|
||||||
@ -237,6 +239,7 @@ internal class LiveLocationAggregationProcessorTest {
|
|||||||
aggregatedEntity.roomId shouldBeEqualTo A_ROOM_ID
|
aggregatedEntity.roomId shouldBeEqualTo A_ROOM_ID
|
||||||
aggregatedEntity.userId shouldBeEqualTo A_SENDER_ID
|
aggregatedEntity.userId shouldBeEqualTo A_SENDER_ID
|
||||||
aggregatedEntity.isActive shouldBeEqualTo false
|
aggregatedEntity.isActive shouldBeEqualTo false
|
||||||
|
aggregatedEntity.relatedEventIds shouldContain stateEventId
|
||||||
aggregatedEntity.endOfLiveTimestampMillis shouldBeEqualTo A_TIMESTAMP + A_TIMEOUT_MILLIS
|
aggregatedEntity.endOfLiveTimestampMillis shouldBeEqualTo A_TIMESTAMP + A_TIMEOUT_MILLIS
|
||||||
aggregatedEntity.lastLocationContent shouldBeEqualTo null
|
aggregatedEntity.lastLocationContent shouldBeEqualTo null
|
||||||
previousEntities.forEach { entity ->
|
previousEntities.forEach { entity ->
|
||||||
@ -324,7 +327,7 @@ internal class LiveLocationAggregationProcessorTest {
|
|||||||
val lastBeaconLocationContent = MessageBeaconLocationDataContent(
|
val lastBeaconLocationContent = MessageBeaconLocationDataContent(
|
||||||
unstableTimestampMillis = A_TIMESTAMP
|
unstableTimestampMillis = A_TIMESTAMP
|
||||||
)
|
)
|
||||||
givenLastSummaryQueryReturns(
|
val aggregatedEntity = givenLastSummaryQueryReturns(
|
||||||
eventId = AN_EVENT_ID,
|
eventId = AN_EVENT_ID,
|
||||||
roomId = A_ROOM_ID,
|
roomId = A_ROOM_ID,
|
||||||
beaconLocationContent = lastBeaconLocationContent
|
beaconLocationContent = lastBeaconLocationContent
|
||||||
@ -340,6 +343,7 @@ internal class LiveLocationAggregationProcessorTest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
result shouldBeEqualTo false
|
result shouldBeEqualTo false
|
||||||
|
aggregatedEntity.relatedEventIds shouldContain AN_EVENT_ID
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -353,7 +357,7 @@ internal class LiveLocationAggregationProcessorTest {
|
|||||||
val lastBeaconLocationContent = MessageBeaconLocationDataContent(
|
val lastBeaconLocationContent = MessageBeaconLocationDataContent(
|
||||||
unstableTimestampMillis = A_TIMESTAMP - 60_000
|
unstableTimestampMillis = A_TIMESTAMP - 60_000
|
||||||
)
|
)
|
||||||
val entity = givenLastSummaryQueryReturns(
|
val aggregatedEntity = givenLastSummaryQueryReturns(
|
||||||
eventId = AN_EVENT_ID,
|
eventId = AN_EVENT_ID,
|
||||||
roomId = A_ROOM_ID,
|
roomId = A_ROOM_ID,
|
||||||
beaconLocationContent = lastBeaconLocationContent
|
beaconLocationContent = lastBeaconLocationContent
|
||||||
@ -369,7 +373,8 @@ internal class LiveLocationAggregationProcessorTest {
|
|||||||
)
|
)
|
||||||
|
|
||||||
result shouldBeEqualTo true
|
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?.getBestTimestampMillis() shouldBeEqualTo A_TIMESTAMP
|
||||||
savedLocationData?.getBestLocationInfo()?.geoUri shouldBeEqualTo A_GEO_URI
|
savedLocationData?.getBestLocationInfo()?.geoUri shouldBeEqualTo A_GEO_URI
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user