mirror of
https://github.com/element-hq/element-android
synced 2024-11-25 02:45:37 +03:00
Merge pull request #264 from vector-im/feature/fix_double_reaction
Fix / sometime sent reaction is count twice
This commit is contained in:
commit
cbe8236036
2 changed files with 12 additions and 17 deletions
|
@ -20,13 +20,12 @@ import com.zhuinden.monarchy.Monarchy
|
||||||
import im.vector.matrix.android.api.session.events.model.*
|
import im.vector.matrix.android.api.session.events.model.*
|
||||||
import im.vector.matrix.android.api.session.room.model.message.MessageContent
|
import im.vector.matrix.android.api.session.room.model.message.MessageContent
|
||||||
import im.vector.matrix.android.api.session.room.model.relation.ReactionContent
|
import im.vector.matrix.android.api.session.room.model.relation.ReactionContent
|
||||||
import im.vector.matrix.android.api.session.room.send.SendState
|
|
||||||
import im.vector.matrix.android.internal.database.mapper.ContentMapper
|
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.mapper.EventMapper
|
||||||
import im.vector.matrix.android.internal.database.model.*
|
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.create
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
import im.vector.matrix.android.internal.session.SessionScope
|
import im.vector.matrix.android.internal.session.room.send.LocalEchoEventFactory
|
||||||
import im.vector.matrix.android.internal.task.Task
|
import im.vector.matrix.android.internal.task.Task
|
||||||
import im.vector.matrix.android.internal.util.tryTransactionSync
|
import im.vector.matrix.android.internal.util.tryTransactionSync
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
|
@ -36,7 +35,7 @@ import javax.inject.Inject
|
||||||
internal interface EventRelationsAggregationTask : Task<EventRelationsAggregationTask.Params, Unit> {
|
internal interface EventRelationsAggregationTask : Task<EventRelationsAggregationTask.Params, Unit> {
|
||||||
|
|
||||||
data class Params(
|
data class Params(
|
||||||
val events: List<Pair<Event, SendState>>,
|
val events: List<Event>,
|
||||||
val userId: String
|
val userId: String
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -59,17 +58,15 @@ internal class DefaultEventRelationsAggregationTask @Inject constructor(private
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun update(realm: Realm, events: List<Pair<Event, SendState>>, userId: String) {
|
private fun update(realm: Realm, events: List<Event>, userId: String) {
|
||||||
events.forEach { pair ->
|
events.forEach { event ->
|
||||||
try { //Temporary catch, should be removed
|
try { //Temporary catch, should be removed
|
||||||
val roomId = pair.first.roomId
|
val roomId = event.roomId
|
||||||
if (roomId == null) {
|
if (roomId == null) {
|
||||||
Timber.w("Event has no room id ${pair.first.eventId}")
|
Timber.w("Event has no room id ${event.eventId}")
|
||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
val event = pair.first
|
val isLocalEcho = LocalEchoEventFactory.isLocalEchoId(event.eventId ?: "")
|
||||||
val sendState = pair.second
|
|
||||||
val isLocalEcho = sendState == SendState.UNSENT
|
|
||||||
when (event.type) {
|
when (event.type) {
|
||||||
EventType.REACTION -> {
|
EventType.REACTION -> {
|
||||||
//we got a reaction!!
|
//we got a reaction!!
|
||||||
|
@ -96,8 +93,8 @@ internal class DefaultEventRelationsAggregationTask @Inject constructor(private
|
||||||
when (eventToPrune.type) {
|
when (eventToPrune.type) {
|
||||||
EventType.MESSAGE -> {
|
EventType.MESSAGE -> {
|
||||||
Timber.d("REDACTION for message ${eventToPrune.eventId}")
|
Timber.d("REDACTION for message ${eventToPrune.eventId}")
|
||||||
val unsignedData = EventMapper.map(eventToPrune).unsignedData
|
// val unsignedData = EventMapper.map(eventToPrune).unsignedData
|
||||||
?: UnsignedData(null, null)
|
// ?: UnsignedData(null, null)
|
||||||
|
|
||||||
//was this event a m.replace
|
//was this event a m.replace
|
||||||
val contentModel = ContentMapper.map(eventToPrune.content)?.toModel<MessageContent>()
|
val contentModel = ContentMapper.map(eventToPrune.content)?.toModel<MessageContent>()
|
||||||
|
@ -128,7 +125,7 @@ internal class DefaultEventRelationsAggregationTask @Inject constructor(private
|
||||||
//ok, this is a replace
|
//ok, this is a replace
|
||||||
var existing = EventAnnotationsSummaryEntity.where(realm, targetEventId).findFirst()
|
var existing = EventAnnotationsSummaryEntity.where(realm, targetEventId).findFirst()
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
Timber.v("###REPLACE creating new relation summary for ${targetEventId}")
|
Timber.v("###REPLACE creating new relation summary for $targetEventId")
|
||||||
existing = EventAnnotationsSummaryEntity.create(realm, targetEventId)
|
existing = EventAnnotationsSummaryEntity.create(realm, targetEventId)
|
||||||
existing.roomId = roomId
|
existing.roomId = roomId
|
||||||
}
|
}
|
||||||
|
@ -168,7 +165,7 @@ internal class DefaultEventRelationsAggregationTask @Inject constructor(private
|
||||||
existingSummary.sourceEvents.add(eventId)
|
existingSummary.sourceEvents.add(eventId)
|
||||||
} else {
|
} else {
|
||||||
//ignore this event for the summary
|
//ignore this event for the summary
|
||||||
Timber.v("###REPLACE ignoring event for summary, it's to old ${eventId}")
|
Timber.v("###REPLACE ignoring event for summary, it's to old $eventId")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@ import im.vector.matrix.android.internal.database.RealmLiveEntityObserver
|
||||||
import im.vector.matrix.android.internal.database.mapper.asDomain
|
import im.vector.matrix.android.internal.database.mapper.asDomain
|
||||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||||
import im.vector.matrix.android.internal.database.query.types
|
import im.vector.matrix.android.internal.database.query.types
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
|
||||||
import im.vector.matrix.android.internal.session.SessionScope
|
|
||||||
import im.vector.matrix.android.internal.task.TaskExecutor
|
import im.vector.matrix.android.internal.task.TaskExecutor
|
||||||
import im.vector.matrix.android.internal.task.configureWith
|
import im.vector.matrix.android.internal.task.configureWith
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
@ -53,7 +51,7 @@ internal class EventRelationsAggregationUpdater @Inject constructor(monarchy: Mo
|
||||||
override fun processChanges(inserted: List<EventEntity>, updated: List<EventEntity>, deleted: List<EventEntity>) {
|
override fun processChanges(inserted: List<EventEntity>, updated: List<EventEntity>, deleted: List<EventEntity>) {
|
||||||
Timber.v("EventRelationsAggregationUpdater called with ${inserted.size} insertions")
|
Timber.v("EventRelationsAggregationUpdater called with ${inserted.size} insertions")
|
||||||
val domainInserted = inserted
|
val domainInserted = inserted
|
||||||
.map { it.asDomain() to it.sendState }
|
.map { it.asDomain() }
|
||||||
|
|
||||||
val params = EventRelationsAggregationTask.Params(
|
val params = EventRelationsAggregationTask.Params(
|
||||||
domainInserted,
|
domainInserted,
|
||||||
|
|
Loading…
Reference in a new issue