Implementing aggregation processor methods
This commit is contained in:
parent
b788a82d0d
commit
f283a95c03
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.matrix.android.sdk.api.session.room.model.livelocation
|
package org.matrix.android.sdk.api.session.room.model.livelocation
|
||||||
|
|
||||||
import org.matrix.android.sdk.api.session.room.model.message.MessageLocationContent
|
import org.matrix.android.sdk.api.session.room.model.message.MessageLiveLocationContent
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aggregation info concerning a live location share.
|
* Aggregation info concerning a live location share.
|
||||||
@ -29,5 +29,5 @@ data class LiveLocationAggregatedSummary(
|
|||||||
val roomId: String,
|
val roomId: String,
|
||||||
val isLive: Boolean,
|
val isLive: Boolean,
|
||||||
val endOfLiveTimestampAsMilliseconds: Long,
|
val endOfLiveTimestampAsMilliseconds: Long,
|
||||||
val lastLocationContent: MessageLocationContent? = null,
|
val lastLocationContent: MessageLiveLocationContent? = null,
|
||||||
)
|
)
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.matrix.android.sdk.internal.database.model.livelocation
|
package org.matrix.android.sdk.internal.database.model.livelocation
|
||||||
|
|
||||||
import io.realm.RealmObject
|
import io.realm.RealmObject
|
||||||
import io.realm.annotations.PrimaryKey
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aggregation info concerning a live location share.
|
* Aggregation info concerning a live location share.
|
||||||
@ -34,7 +33,11 @@ internal open class LiveLocationAggregatedSummaryEntity(
|
|||||||
|
|
||||||
var endOfLiveTimestampAsMilliseconds: Long? = null,
|
var endOfLiveTimestampAsMilliseconds: Long? = null,
|
||||||
|
|
||||||
var lastLocation: String? = null
|
/**
|
||||||
|
* For now we persist this as a JSON for greater flexibility
|
||||||
|
* @see [org.matrix.android.sdk.api.session.room.model.message.MessageLiveLocationContent]
|
||||||
|
*/
|
||||||
|
var lastLocationContent: String? = null,
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
companion object
|
companion object
|
||||||
}
|
}
|
||||||
|
@ -17,35 +17,74 @@
|
|||||||
package org.matrix.android.sdk.internal.session.room.aggregation.livelocation
|
package org.matrix.android.sdk.internal.session.room.aggregation.livelocation
|
||||||
|
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
|
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.toModel
|
||||||
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationBeaconContent
|
import org.matrix.android.sdk.api.session.room.model.livelocation.LiveLocationBeaconContent
|
||||||
import org.matrix.android.sdk.api.session.room.model.message.MessageLiveLocationContent
|
import org.matrix.android.sdk.api.session.room.model.message.MessageLiveLocationContent
|
||||||
|
import org.matrix.android.sdk.internal.database.mapper.ContentMapper
|
||||||
|
import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationAggregatedSummaryEntity
|
||||||
|
import org.matrix.android.sdk.internal.database.query.getOrCreate
|
||||||
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class DefaultLiveLocationAggregationProcessor @Inject constructor() : LiveLocationAggregationProcessor {
|
internal class DefaultLiveLocationAggregationProcessor @Inject constructor() : LiveLocationAggregationProcessor {
|
||||||
|
|
||||||
override fun handleBeaconInfo(realm: Realm, event: Event, content: LiveLocationBeaconContent, roomId: String, isLocalEcho: Boolean) {
|
override fun handleBeaconInfo(realm: Realm, event: Event, content: LiveLocationBeaconContent, roomId: String, isLocalEcho: Boolean) {
|
||||||
//val locationSenderId = event.senderId ?: return
|
if (event.senderId.isNullOrEmpty() || isLocalEcho) {
|
||||||
|
|
||||||
// We shouldn't process local echos
|
|
||||||
if (isLocalEcho) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO if live field is true, get eventId else get get replace eventId
|
val targetEventId = if (content.isLive.orTrue()) {
|
||||||
// TODO getOrCreate existing aggregated summary
|
event.eventId
|
||||||
// TODO update the endOfLiveTimestamp and live fields
|
} else {
|
||||||
|
// when live is set to false, we use the id of the event that should have been replaced
|
||||||
|
event.unsignedData?.replacesState
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetEventId.isNullOrEmpty()) {
|
||||||
|
Timber.w("no target event id found for the beacon content")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val aggregatedSummary = LiveLocationAggregatedSummaryEntity.getOrCreate(
|
||||||
|
realm = realm,
|
||||||
|
roomId = roomId,
|
||||||
|
eventId = targetEventId
|
||||||
|
)
|
||||||
|
|
||||||
|
aggregatedSummary.endOfLiveTimestampAsMilliseconds = content.getBestTimestampAsMilliseconds()?.let { it + (content.timeout ?: 0) }
|
||||||
|
aggregatedSummary.isLive = content.isLive
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleLiveLocation(realm: Realm, event: Event, content: MessageLiveLocationContent, roomId: String, isLocalEcho: Boolean) {
|
override fun handleLiveLocation(realm: Realm, event: Event, content: MessageLiveLocationContent, roomId: String, isLocalEcho: Boolean) {
|
||||||
//val locationSenderId = event.senderId ?: return
|
if (event.senderId.isNullOrEmpty() || isLocalEcho) {
|
||||||
|
|
||||||
// We shouldn't process local echos
|
|
||||||
if (isLocalEcho) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO getOrCreate existing aggregated summary
|
val targetEventId = content.relatesTo?.eventId
|
||||||
// TODO add location content only if more recent than the current one if any
|
|
||||||
|
if (targetEventId.isNullOrEmpty()) {
|
||||||
|
Timber.w("no target event id found for the live location content")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val aggregatedSummary = LiveLocationAggregatedSummaryEntity.getOrCreate(
|
||||||
|
realm = realm,
|
||||||
|
roomId = roomId,
|
||||||
|
eventId = targetEventId
|
||||||
|
)
|
||||||
|
val updatedLocationTimestamp = content.getBestTimestampAsMilliseconds() ?: 0
|
||||||
|
val currentLocationTimestamp = ContentMapper
|
||||||
|
.map(aggregatedSummary.lastLocationContent)
|
||||||
|
.toModel<MessageLiveLocationContent>()
|
||||||
|
?.getBestTimestampAsMilliseconds()
|
||||||
|
?: 0
|
||||||
|
|
||||||
|
if (updatedLocationTimestamp > currentLocationTimestamp) {
|
||||||
|
// only take location if it is more recent
|
||||||
|
aggregatedSummary.lastLocationContent = ContentMapper.map(content.toContent())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user