Removing non necessary LiveLocationAggregationProcessor interface
This commit is contained in:
parent
b2099b6b31
commit
4a2310954a
|
@ -88,8 +88,6 @@ import org.matrix.android.sdk.internal.session.integrationmanager.IntegrationMan
|
|||
import org.matrix.android.sdk.internal.session.openid.DefaultOpenIdService
|
||||
import org.matrix.android.sdk.internal.session.permalinks.DefaultPermalinkService
|
||||
import org.matrix.android.sdk.internal.session.room.EventRelationsAggregationProcessor
|
||||
import org.matrix.android.sdk.internal.session.room.aggregation.livelocation.DefaultLiveLocationAggregationProcessor
|
||||
import org.matrix.android.sdk.internal.session.room.aggregation.livelocation.LiveLocationAggregationProcessor
|
||||
import org.matrix.android.sdk.internal.session.room.create.RoomCreateEventProcessor
|
||||
import org.matrix.android.sdk.internal.session.room.prune.RedactionEventProcessor
|
||||
import org.matrix.android.sdk.internal.session.room.send.queue.EventSenderProcessor
|
||||
|
@ -392,7 +390,4 @@ internal abstract class SessionModule {
|
|||
|
||||
@Binds
|
||||
abstract fun bindEventSenderProcessor(processor: EventSenderProcessorCoroutine): EventSenderProcessor
|
||||
|
||||
@Binds
|
||||
abstract fun bindLiveLocationAggregationProcessor(processor: DefaultLiveLocationAggregationProcessor): LiveLocationAggregationProcessor
|
||||
}
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.room.aggregation.livelocation
|
||||
|
||||
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.toContent
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconInfoContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconLocationDataContent
|
||||
import org.matrix.android.sdk.internal.database.mapper.ContentMapper
|
||||
import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationShareAggregatedSummaryEntity
|
||||
import org.matrix.android.sdk.internal.database.query.getOrCreate
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class DefaultLiveLocationAggregationProcessor @Inject constructor() : LiveLocationAggregationProcessor {
|
||||
|
||||
override fun handleBeaconInfo(realm: Realm, event: Event, content: MessageBeaconInfoContent, roomId: String, isLocalEcho: Boolean) {
|
||||
if (event.senderId.isNullOrEmpty() || isLocalEcho) {
|
||||
return
|
||||
}
|
||||
|
||||
val targetEventId = if (content.isLive.orTrue()) {
|
||||
event.eventId
|
||||
} 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 = LiveLocationShareAggregatedSummaryEntity.getOrCreate(
|
||||
realm = realm,
|
||||
roomId = roomId,
|
||||
eventId = targetEventId
|
||||
)
|
||||
|
||||
Timber.d("updating summary of id=$targetEventId with isLive=${content.isLive}")
|
||||
|
||||
aggregatedSummary.endOfLiveTimestampMillis = content.getBestTimestampMillis()?.let { it + (content.timeout ?: 0) }
|
||||
aggregatedSummary.isActive = content.isLive
|
||||
}
|
||||
|
||||
override fun handleBeaconLocationData(
|
||||
realm: Realm,
|
||||
event: Event,
|
||||
content: MessageBeaconLocationDataContent,
|
||||
roomId: String,
|
||||
relatedEventId: String?,
|
||||
isLocalEcho: Boolean
|
||||
) {
|
||||
if (event.senderId.isNullOrEmpty() || isLocalEcho) {
|
||||
return
|
||||
}
|
||||
|
||||
if (relatedEventId.isNullOrEmpty()) {
|
||||
Timber.w("no related event id found for the live location content")
|
||||
return
|
||||
}
|
||||
|
||||
val aggregatedSummary = LiveLocationShareAggregatedSummaryEntity.getOrCreate(
|
||||
realm = realm,
|
||||
roomId = roomId,
|
||||
eventId = relatedEventId
|
||||
)
|
||||
val updatedLocationTimestamp = content.getBestTimestampMillis() ?: 0
|
||||
val currentLocationTimestamp = ContentMapper
|
||||
.map(aggregatedSummary.lastLocationContent)
|
||||
.toModel<MessageBeaconLocationDataContent>()
|
||||
?.getBestTimestampMillis()
|
||||
?: 0
|
||||
|
||||
if (updatedLocationTimestamp.isMoreRecentThan(currentLocationTimestamp)) {
|
||||
Timber.d("updating last location of the summary of id=$relatedEventId")
|
||||
aggregatedSummary.lastLocationContent = ContentMapper.map(content.toContent())
|
||||
}
|
||||
}
|
||||
|
||||
private fun Long.isMoreRecentThan(timestamp: Long) = this > timestamp
|
||||
}
|
|
@ -17,18 +17,48 @@
|
|||
package org.matrix.android.sdk.internal.session.room.aggregation.livelocation
|
||||
|
||||
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.toContent
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconInfoContent
|
||||
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconLocationDataContent
|
||||
import org.matrix.android.sdk.internal.database.mapper.ContentMapper
|
||||
import org.matrix.android.sdk.internal.database.model.livelocation.LiveLocationShareAggregatedSummaryEntity
|
||||
import org.matrix.android.sdk.internal.database.query.getOrCreate
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface LiveLocationAggregationProcessor {
|
||||
fun handleBeaconInfo(
|
||||
realm: Realm,
|
||||
event: Event,
|
||||
content: MessageBeaconInfoContent,
|
||||
roomId: String,
|
||||
isLocalEcho: Boolean,
|
||||
)
|
||||
internal class LiveLocationAggregationProcessor @Inject constructor() {
|
||||
|
||||
fun handleBeaconInfo(realm: Realm, event: Event, content: MessageBeaconInfoContent, roomId: String, isLocalEcho: Boolean) {
|
||||
if (event.senderId.isNullOrEmpty() || isLocalEcho) {
|
||||
return
|
||||
}
|
||||
|
||||
val targetEventId = if (content.isLive.orTrue()) {
|
||||
event.eventId
|
||||
} 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 = LiveLocationShareAggregatedSummaryEntity.getOrCreate(
|
||||
realm = realm,
|
||||
roomId = roomId,
|
||||
eventId = targetEventId
|
||||
)
|
||||
|
||||
Timber.d("updating summary of id=$targetEventId with isLive=${content.isLive}")
|
||||
|
||||
aggregatedSummary.endOfLiveTimestampMillis = content.getBestTimestampMillis()?.let { it + (content.timeout ?: 0) }
|
||||
aggregatedSummary.isActive = content.isLive
|
||||
}
|
||||
|
||||
fun handleBeaconLocationData(
|
||||
realm: Realm,
|
||||
|
@ -36,6 +66,34 @@ internal interface LiveLocationAggregationProcessor {
|
|||
content: MessageBeaconLocationDataContent,
|
||||
roomId: String,
|
||||
relatedEventId: String?,
|
||||
isLocalEcho: Boolean,
|
||||
)
|
||||
isLocalEcho: Boolean
|
||||
) {
|
||||
if (event.senderId.isNullOrEmpty() || isLocalEcho) {
|
||||
return
|
||||
}
|
||||
|
||||
if (relatedEventId.isNullOrEmpty()) {
|
||||
Timber.w("no related event id found for the live location content")
|
||||
return
|
||||
}
|
||||
|
||||
val aggregatedSummary = LiveLocationShareAggregatedSummaryEntity.getOrCreate(
|
||||
realm = realm,
|
||||
roomId = roomId,
|
||||
eventId = relatedEventId
|
||||
)
|
||||
val updatedLocationTimestamp = content.getBestTimestampMillis() ?: 0
|
||||
val currentLocationTimestamp = ContentMapper
|
||||
.map(aggregatedSummary.lastLocationContent)
|
||||
.toModel<MessageBeaconLocationDataContent>()
|
||||
?.getBestTimestampMillis()
|
||||
?: 0
|
||||
|
||||
if (updatedLocationTimestamp.isMoreRecentThan(currentLocationTimestamp)) {
|
||||
Timber.d("updating last location of the summary of id=$relatedEventId")
|
||||
aggregatedSummary.lastLocationContent = ContentMapper.map(content.toContent())
|
||||
}
|
||||
}
|
||||
|
||||
private fun Long.isMoreRecentThan(timestamp: Long) = this > timestamp
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue