Fix / Reaction stays highlighted when undone

When undoing my reaction, the reactji stays selected as if i have done the reaction
This commit is contained in:
Valere 2019-05-19 12:07:27 +02:00
parent e3b9031e71
commit 054d339b48
3 changed files with 14 additions and 6 deletions

View File

@ -154,7 +154,7 @@ internal class SessionModule(private val sessionParams: SessionParams) {


scope(DefaultSession.SCOPE) { scope(DefaultSession.SCOPE) {
val groupSummaryUpdater = GroupSummaryUpdater(get()) val groupSummaryUpdater = GroupSummaryUpdater(get())
val eventsPruner = EventsPruner(get()) val eventsPruner = EventsPruner(get(), get())
val userEntityUpdater = UserEntityUpdater(get(), get(), get()) val userEntityUpdater = UserEntityUpdater(get(), get(), get())
listOf<LiveEntityObserver>(groupSummaryUpdater, eventsPruner, userEntityUpdater) listOf<LiveEntityObserver>(groupSummaryUpdater, eventsPruner, userEntityUpdater)
} }

View File

@ -20,6 +20,7 @@ import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequestBuilder import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager import androidx.work.WorkManager
import com.zhuinden.monarchy.Monarchy import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.api.auth.data.Credentials
import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.internal.database.RealmLiveEntityObserver 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
@ -29,7 +30,7 @@ import im.vector.matrix.android.internal.util.WorkerParamsFactory


private const val PRUNE_EVENT_WORKER = "PRUNE_EVENT_WORKER" private const val PRUNE_EVENT_WORKER = "PRUNE_EVENT_WORKER"


internal class EventsPruner(monarchy: Monarchy) : internal class EventsPruner(monarchy: Monarchy, private val credentials: Credentials) :
RealmLiveEntityObserver<EventEntity>(monarchy) { RealmLiveEntityObserver<EventEntity>(monarchy) {


override val query = Monarchy.Query<EventEntity> { EventEntity.where(it, type = EventType.REDACTION) } override val query = Monarchy.Query<EventEntity> { EventEntity.where(it, type = EventType.REDACTION) }
@ -38,7 +39,7 @@ internal class EventsPruner(monarchy: Monarchy) :
val redactionEvents = inserted val redactionEvents = inserted
.mapNotNull { it.asDomain() } .mapNotNull { it.asDomain() }


val pruneEventWorkerParams = PruneEventWorker.Params(redactionEvents) val pruneEventWorkerParams = PruneEventWorker.Params(redactionEvents, credentials.userId)
val workData = WorkerParamsFactory.toData(pruneEventWorkerParams) val workData = WorkerParamsFactory.toData(pruneEventWorkerParams)


val sendWork = OneTimeWorkRequestBuilder<PruneEventWorker>() val sendWork = OneTimeWorkRequestBuilder<PruneEventWorker>()

View File

@ -40,13 +40,15 @@ import io.realm.Realm
import org.koin.standalone.inject import org.koin.standalone.inject
import timber.log.Timber import timber.log.Timber


//TODO should be a task instead of worker
internal class PruneEventWorker(context: Context, internal class PruneEventWorker(context: Context,
workerParameters: WorkerParameters workerParameters: WorkerParameters
) : Worker(context, workerParameters), MatrixKoinComponent { ) : Worker(context, workerParameters), MatrixKoinComponent {


@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
internal class Params( internal class Params(
val redactionEvents: List<Event> val redactionEvents: List<Event>,
val userId: String
) )


private val monarchy by inject<Monarchy>() private val monarchy by inject<Monarchy>()
@ -57,7 +59,7 @@ internal class PruneEventWorker(context: Context,


val result = monarchy.tryTransactionSync { realm -> val result = monarchy.tryTransactionSync { realm ->
params.redactionEvents.forEach { event -> params.redactionEvents.forEach { event ->
pruneEvent(realm, event) pruneEvent(realm, event, params.userId)
} }
} }
return result.fold({ return result.fold({
@ -67,7 +69,7 @@ internal class PruneEventWorker(context: Context,
}) })
} }


private fun pruneEvent(realm: Realm, redactionEvent: Event) { private fun pruneEvent(realm: Realm, redactionEvent: Event, userId: String) {
if (redactionEvent.redacts.isNullOrBlank()) { if (redactionEvent.redacts.isNullOrBlank()) {
return return
} }
@ -88,6 +90,7 @@ internal class PruneEventWorker(context: Context,
val modified = unsignedData.copy(redactedEvent = redactionEvent) val modified = unsignedData.copy(redactedEvent = redactionEvent)
eventToPrune.content = ContentMapper.map(emptyMap()) eventToPrune.content = ContentMapper.map(emptyMap())
eventToPrune.unsignedData = MoshiProvider.providesMoshi().adapter(UnsignedData::class.java).toJson(modified) eventToPrune.unsignedData = MoshiProvider.providesMoshi().adapter(UnsignedData::class.java).toJson(modified)

} }
EventType.REACTION -> { EventType.REACTION -> {
Timber.d("REDACTION of reaction ${eventToPrune.eventId}") Timber.d("REDACTION of reaction ${eventToPrune.eventId}")
@ -110,6 +113,10 @@ internal class PruneEventWorker(context: Context,
summary.sourceEvents.remove(eventToPrune.eventId) summary.sourceEvents.remove(eventToPrune.eventId)
Timber.d("Known reactions after ${summary.sourceEvents.joinToString(",")}") Timber.d("Known reactions after ${summary.sourceEvents.joinToString(",")}")
summary.count = summary.count - 1 summary.count = summary.count - 1
if (eventToPrune.sender == userId) {
//Was it a redact on my reaction?
summary.addedByMe = false
}
if (summary.count == 0) { if (summary.count == 0) {
//delete! //delete!
summary.deleteFromRealm() summary.deleteFromRealm()