Code review
This commit is contained in:
parent
975de1dbed
commit
289c03e724
|
@ -21,7 +21,7 @@ import im.vector.matrix.android.api.session.events.model.Content
|
|||
* Events can relates to other events, this object keeps a summary
|
||||
* of all events that are referencing the 'eventId' event via the RelationType.REFERENCE
|
||||
*/
|
||||
class ReferencesAggregatedSummary(
|
||||
data class ReferencesAggregatedSummary(
|
||||
val eventId: String,
|
||||
val content: Content?,
|
||||
val sourceEvents: List<String>,
|
||||
|
|
|
@ -40,7 +40,8 @@ internal open class EventEntity(@Index var eventId: String = "",
|
|||
@Index var displayIndex: Int = 0,
|
||||
@Index var isUnlinked: Boolean = false,
|
||||
var decryptionResultJson: String? = null,
|
||||
var decryptionErrorCode: String? = null
|
||||
var decryptionErrorCode: String? = null,
|
||||
var ageLocalTs: Long? = null
|
||||
) : RealmObject() {
|
||||
|
||||
enum class LinkFilterMode {
|
||||
|
@ -59,8 +60,6 @@ internal open class EventEntity(@Index var eventId: String = "",
|
|||
sendStateStr = value.name
|
||||
}
|
||||
|
||||
var ageLocalTs: Long? = null
|
||||
|
||||
companion object
|
||||
|
||||
@LinkingObjects("untimelinedStateEvents")
|
||||
|
|
|
@ -47,3 +47,7 @@ internal fun EventAnnotationsSummaryEntity.Companion.create(realm: Realm, roomId
|
|||
}
|
||||
return obj
|
||||
}
|
||||
internal fun EventAnnotationsSummaryEntity.Companion.getOrCreate(realm: Realm, roomId: String, eventId: String): EventAnnotationsSummaryEntity {
|
||||
return EventAnnotationsSummaryEntity.where(realm, eventId).findFirst()
|
||||
?: EventAnnotationsSummaryEntity.create(realm, roomId, eventId).apply { this.roomId = roomId }
|
||||
}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2019 New Vector Ltd
|
||||
*
|
||||
* 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 im.vector.matrix.android.internal.database.query
|
||||
|
||||
import im.vector.matrix.android.internal.database.model.ReferencesAggregatedSummaryEntity
|
||||
|
|
|
@ -29,6 +29,7 @@ import im.vector.matrix.android.internal.database.mapper.ContentMapper
|
|||
import im.vector.matrix.android.internal.database.mapper.EventMapper
|
||||
import im.vector.matrix.android.internal.database.model.*
|
||||
import im.vector.matrix.android.internal.database.query.create
|
||||
import im.vector.matrix.android.internal.database.query.getOrCreate
|
||||
import im.vector.matrix.android.internal.database.query.where
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import im.vector.matrix.android.internal.util.awaitTransaction
|
||||
|
@ -201,11 +202,7 @@ internal class DefaultEventRelationsAggregationTask @Inject constructor(
|
|||
val targetEventId = relatedEventId ?: content.relatesTo?.eventId ?: return
|
||||
val newContent = content.newContent ?: return
|
||||
// ok, this is a replace
|
||||
var existing = EventAnnotationsSummaryEntity.where(realm, targetEventId).findFirst()
|
||||
if (existing == null) {
|
||||
Timber.v("###REPLACE creating new relation summary for $targetEventId")
|
||||
existing = EventAnnotationsSummaryEntity.create(realm, roomId, targetEventId)
|
||||
}
|
||||
val existing = EventAnnotationsSummaryEntity.getOrCreate(realm, roomId, targetEventId)
|
||||
|
||||
// we have it
|
||||
val existingSummary = existing.editSummary
|
||||
|
@ -295,8 +292,7 @@ internal class DefaultEventRelationsAggregationTask @Inject constructor(
|
|||
val relatedEventID = content.relatesTo.eventId
|
||||
val reactionEventId = event.eventId
|
||||
Timber.v("Reaction $reactionEventId relates to $relatedEventID")
|
||||
val eventSummary = EventAnnotationsSummaryEntity.where(realm, relatedEventID).findFirst()
|
||||
?: EventAnnotationsSummaryEntity.create(realm, roomId, relatedEventID).apply { this.roomId = roomId }
|
||||
val eventSummary = EventAnnotationsSummaryEntity.getOrCreate(realm, roomId, relatedEventID)
|
||||
|
||||
var sum = eventSummary.reactionsSummary.find { it.key == reaction }
|
||||
val txId = event.unsignedData?.transactionId
|
||||
|
@ -420,8 +416,7 @@ internal class DefaultEventRelationsAggregationTask @Inject constructor(
|
|||
}
|
||||
|
||||
private fun handleVerification(realm: Realm, event: Event, roomId: String, isLocalEcho: Boolean, relatedEventId: String, userId: String) {
|
||||
val eventSummary = EventAnnotationsSummaryEntity.where(realm, relatedEventId).findFirst()
|
||||
?: EventAnnotationsSummaryEntity.create(realm, roomId, relatedEventId).apply { this.roomId = roomId }
|
||||
val eventSummary = EventAnnotationsSummaryEntity.getOrCreate(realm, roomId, relatedEventId)
|
||||
|
||||
val verifSummary = eventSummary.referencesSummaryEntity
|
||||
?: ReferencesAggregatedSummaryEntity.create(realm, relatedEventId).also {
|
||||
|
@ -469,9 +464,7 @@ internal class DefaultEventRelationsAggregationTask @Inject constructor(
|
|||
if (isLocalEcho) {
|
||||
verifSummary.sourceLocalEcho.add(event.eventId)
|
||||
} else {
|
||||
if (verifSummary.sourceLocalEcho.contains(txId)) {
|
||||
verifSummary.sourceLocalEcho.remove(txId)
|
||||
}
|
||||
verifSummary.sourceLocalEcho.remove(txId)
|
||||
verifSummary.sourceEvents.add(event.eventId)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue