From be8b1287c7aac738588ebd7d342a3abbe9cc3fa3 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 7 Nov 2018 20:36:19 +0100 Subject: [PATCH] Start handling prune events. WIP --- .../detail/timeline/MessageItemFactory.kt | 2 +- .../timeline/TimelineEventController.kt | 2 +- app/src/main/res/drawable/fg_group_item.xml | 2 +- .../android/api/session/events/model/Event.kt | 4 +- .../database/RealmLiveEntityObserver.kt | 48 +++++++++++++ .../internal/database/mapper/EventMapper.kt | 22 +++--- .../internal/database/model/EventEntity.kt | 7 +- .../database/query/EventEntityQueries.kt | 8 ++- .../internal/session/DefaultSession.kt | 12 ++-- .../android/internal/session/SessionModule.kt | 17 +++-- .../session/events/prune/EventsPruner.kt | 68 +++++++++++++++++++ .../session/group/GroupSummaryUpdater.kt | 56 ++++----------- .../session/room/RoomSummaryUpdater.kt | 49 +++---------- .../internal/session/sync/RoomSyncHandler.kt | 16 ++--- 14 files changed, 184 insertions(+), 129 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/RealmLiveEntityObserver.kt create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/events/prune/EventsPruner.kt diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt index ca5f2d9e2b..b15db3bdb9 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt @@ -26,7 +26,7 @@ class MessageItemFactory(private val timelineDateFormatter: TimelineDateFormatte avatarUrl = roomMember.avatarUrl, showInformation = showInformation, time = timelineDateFormatter.formatMessageHour(date), - memberName = roomMember.displayName + memberName = roomMember.displayName ?: event.root.sender ) } diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt index 0a0e021115..514e139df8 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineEventController.kt @@ -31,7 +31,7 @@ class TimelineEventController(private val roomId: String, } } - var snapshotList: List? = emptyList() + private var snapshotList: List? = emptyList() var timeline: PagedList? = null set(value) { field?.removeWeakCallback(pagedListCallback) diff --git a/app/src/main/res/drawable/fg_group_item.xml b/app/src/main/res/drawable/fg_group_item.xml index a9e09faa52..c6272163e8 100644 --- a/app/src/main/res/drawable/fg_group_item.xml +++ b/app/src/main/res/drawable/fg_group_item.xml @@ -4,7 +4,7 @@ - + diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/Event.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/Event.kt index 6282d9c9e4..2763506b14 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/Event.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/events/model/Event.kt @@ -16,7 +16,9 @@ data class Event( @Json(name = "sender") val sender: String? = null, @Json(name = "state_key") val stateKey: String? = null, @Json(name = "room_id") var roomId: String? = null, - @Json(name = "unsigned") val unsignedData: UnsignedData? = null + @Json(name = "unsigned") val unsignedData: UnsignedData? = null, + @Json(name = "redacts") val redacts: String? = null + ) { val contentAsJsonObject: JsonObject? by lazy { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/RealmLiveEntityObserver.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/RealmLiveEntityObserver.kt new file mode 100644 index 0000000000..6d3458995a --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/RealmLiveEntityObserver.kt @@ -0,0 +1,48 @@ +package im.vector.matrix.android.internal.database + +import android.arch.lifecycle.LiveData +import android.arch.lifecycle.Observer +import com.zhuinden.monarchy.Monarchy +import io.realm.RealmObject +import io.realm.RealmResults +import java.util.concurrent.atomic.AtomicBoolean + +internal interface LiveEntityObserver { + fun start() + fun dispose() +} + +internal abstract class RealmLiveEntityObserver(protected val monarchy: Monarchy) + : Observer>, LiveEntityObserver { + + protected abstract val query: Monarchy.Query + private val isStarted = AtomicBoolean(false) + private val liveResults: LiveData> by lazy { + monarchy.findAllManagedWithChanges(query) + } + + override fun start() { + if (isStarted.compareAndSet(false, true)) { + liveResults.observeForever(this) + } + } + + override fun dispose() { + if (isStarted.compareAndSet(true, false)) { + liveResults.removeObserver(this) + } + } + + // PRIVATE + + override fun onChanged(changeSet: Monarchy.ManagedChangeSet?) { + if (changeSet == null) { + return + } + val indexes = changeSet.orderedCollectionChangeSet.changes + changeSet.orderedCollectionChangeSet.insertions + process(changeSet.realmResults, indexes) + } + + abstract fun process(results: RealmResults, indexes: IntArray) + +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/EventMapper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/EventMapper.kt index 767cada7bf..d52eb5ef33 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/EventMapper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/EventMapper.kt @@ -1,10 +1,10 @@ package im.vector.matrix.android.internal.database.mapper import com.squareup.moshi.Types +import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.UnsignedData import im.vector.matrix.android.internal.database.model.EventEntity import im.vector.matrix.android.internal.di.MoshiProvider -import im.vector.matrix.android.api.session.events.model.Event object EventMapper { @@ -22,21 +22,23 @@ object EventMapper { eventEntity.type = event.type eventEntity.sender = event.sender eventEntity.originServerTs = event.originServerTs + eventEntity.redacts = event.redacts eventEntity.age = event.unsignedData?.age ?: event.originServerTs return eventEntity } internal fun map(eventEntity: EventEntity): Event { return Event( - eventEntity.type, - eventEntity.eventId, - adapter.fromJson(eventEntity.content), - adapter.fromJson(eventEntity.prevContent ?: ""), - eventEntity.originServerTs, - eventEntity.sender, - eventEntity.stateKey, - null, - UnsignedData(eventEntity.age) + type = eventEntity.type, + eventId = eventEntity.eventId, + content = adapter.fromJson(eventEntity.content), + prevContent = adapter.fromJson(eventEntity.prevContent ?: ""), + originServerTs = eventEntity.originServerTs, + sender = eventEntity.sender, + stateKey = eventEntity.stateKey, + roomId = null, + unsignedData = UnsignedData(eventEntity.age), + redacts = eventEntity.redacts ) } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/EventEntity.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/EventEntity.kt index fe4c60264f..370b9c5ffd 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/EventEntity.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/EventEntity.kt @@ -2,17 +2,18 @@ package im.vector.matrix.android.internal.database.model import io.realm.RealmObject import io.realm.RealmResults -import io.realm.annotations.Index import io.realm.annotations.LinkingObjects +import io.realm.annotations.PrimaryKey -open class EventEntity(@Index var eventId: String = "", +open class EventEntity(@PrimaryKey var eventId: String = "", var type: String = "", var content: String = "", var prevContent: String? = null, var stateKey: String? = null, var originServerTs: Long? = null, var sender: String? = null, - var age: Long? = 0 + var age: Long? = 0, + var redacts: String? = null ) : RealmObject() { companion object diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt index 4c249ad024..eda69db422 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/EventEntityQueries.kt @@ -15,9 +15,11 @@ fun EventEntity.Companion.where(realm: Realm, eventId: String): RealmQuery { +fun EventEntity.Companion.where(realm: Realm, roomId: String? = null, type: String? = null): RealmQuery { val query = realm.where() - .equalTo("${EventEntityFields.CHUNK}.${ChunkEntityFields.ROOM}.${RoomEntityFields.ROOM_ID}", roomId) + if (roomId != null) { + query.equalTo("${EventEntityFields.CHUNK}.${ChunkEntityFields.ROOM}.${RoomEntityFields.ROOM_ID}", roomId) + } if (type != null) { query.equalTo(EventEntityFields.TYPE, type) } @@ -32,7 +34,7 @@ fun EventEntity.Companion.stateEvents(realm: Realm, roomId: String): RealmQuery< fun RealmQuery.last(from: Long? = null): EventEntity? { if (from != null) { - this.lessThanOrEqualTo(EventEntityFields.ORIGIN_SERVER_TS, from) + this.lessThan(EventEntityFields.ORIGIN_SERVER_TS, from) } return this .sort(EventEntityFields.ORIGIN_SERVER_TS, Sort.DESCENDING) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt index 9a894a3b7b..d9c917a130 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt @@ -11,10 +11,9 @@ import im.vector.matrix.android.api.session.room.Room import im.vector.matrix.android.api.session.room.RoomService import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.matrix.android.internal.auth.data.SessionParams +import im.vector.matrix.android.internal.database.LiveEntityObserver import im.vector.matrix.android.internal.session.group.GroupModule -import im.vector.matrix.android.internal.session.group.GroupSummaryUpdater import im.vector.matrix.android.internal.session.room.RoomModule -import im.vector.matrix.android.internal.session.room.RoomSummaryUpdater import im.vector.matrix.android.internal.session.sync.SyncModule import im.vector.matrix.android.internal.session.sync.job.SyncThread import org.koin.core.scope.Scope @@ -32,8 +31,7 @@ class DefaultSession(override val sessionParams: SessionParams) : Session, KoinC private lateinit var scope: Scope - private val roomSummaryObserver by inject() - private val groupSummaryUpdater by inject() + private val liveEntityUpdaters by inject>() private val roomService by inject() private val groupService by inject() private val syncThread by inject() @@ -50,8 +48,7 @@ class DefaultSession(override val sessionParams: SessionParams) : Session, KoinC val groupModule = GroupModule() StandAloneContext.loadKoinModules(listOf(sessionModule, syncModule, roomModule, groupModule)) scope = getKoin().getOrCreateScope(SCOPE) - roomSummaryObserver.start() - groupSummaryUpdater.start() + liveEntityUpdaters.forEach { it.start() } syncThread.start() } @@ -61,8 +58,7 @@ class DefaultSession(override val sessionParams: SessionParams) : Session, KoinC checkIsMainThread() assert(isOpen) syncThread.kill() - groupSummaryUpdater.dispose() - roomSummaryObserver.dispose() + liveEntityUpdaters.forEach { it.dispose() } scope.close() isOpen = false } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt index c5c0dec20d..c4de7b2173 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt @@ -4,6 +4,8 @@ import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.session.group.GroupService import im.vector.matrix.android.api.session.room.RoomService import im.vector.matrix.android.internal.auth.data.SessionParams +import im.vector.matrix.android.internal.database.LiveEntityObserver +import im.vector.matrix.android.internal.session.events.prune.EventsPruner import im.vector.matrix.android.internal.session.group.DefaultGroupService import im.vector.matrix.android.internal.session.group.GroupSummaryUpdater import im.vector.matrix.android.internal.session.room.DefaultRoomService @@ -53,22 +55,23 @@ class SessionModule(private val sessionParams: SessionParams) : Module { RoomAvatarResolver(get(), sessionParams.credentials) } - scope(DefaultSession.SCOPE) { - RoomSummaryUpdater(get(), get(), get(), get(), sessionParams.credentials) - } - scope(DefaultSession.SCOPE) { DefaultRoomService(get()) as RoomService } - scope(DefaultSession.SCOPE) { - GroupSummaryUpdater(get(), get()) - } scope(DefaultSession.SCOPE) { DefaultGroupService(get()) as GroupService } + scope(DefaultSession.SCOPE) { + val roomSummaryUpdater = RoomSummaryUpdater(get(), get(), get(), get(), sessionParams.credentials) + val groupSummaryUpdater = GroupSummaryUpdater(get(), get()) + val eventsPruner = EventsPruner(get()) + listOf(roomSummaryUpdater, groupSummaryUpdater, eventsPruner) + } + + }.invoke() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/events/prune/EventsPruner.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/events/prune/EventsPruner.kt new file mode 100644 index 0000000000..bd98ea1395 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/events/prune/EventsPruner.kt @@ -0,0 +1,68 @@ +package im.vector.matrix.android.internal.session.events.prune + +import arrow.core.Option +import com.zhuinden.monarchy.Monarchy +import im.vector.matrix.android.api.session.events.model.Event +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.mapper.asDomain +import im.vector.matrix.android.internal.database.mapper.asEntity +import im.vector.matrix.android.internal.database.model.EventEntity +import im.vector.matrix.android.internal.database.query.where +import io.realm.Realm +import io.realm.RealmResults + +internal class EventsPruner(monarchy: Monarchy) : + RealmLiveEntityObserver(monarchy) { + + override val query = Monarchy.Query { EventEntity.where(it, type = EventType.REDACTION) } + + override fun process(results: RealmResults, indexes: IntArray) { + val redactionEvents = results.map { it.asDomain() } + monarchy.writeAsync { realm -> + indexes.forEach { index -> + val data = redactionEvents[index] + pruneEvent(realm, data) + } + } + } + + private fun pruneEvent(realm: Realm, redactionEvent: Event?) { + if (redactionEvent == null || redactionEvent.redacts.isNullOrEmpty()) { + return + } + val eventToPrune = EventEntity.where(realm, eventId = redactionEvent.redacts).findFirst()?.asDomain() + ?: return + + val allowedKeys = computeAllowedKeys(eventToPrune.type) + val prunedContent = allowedKeys.fold( + { eventToPrune.content }, + { eventToPrune.content?.filterKeys { key -> it.contains(key) } } + ) + val eventToPruneEntity = eventToPrune.copy(content = prunedContent).asEntity() + realm.insertOrUpdate(eventToPruneEntity) + } + + private fun computeAllowedKeys(type: String): Option> { + // Add filtered content, allowed keys in content depends on the event type + val result = when (type) { + EventType.STATE_ROOM_MEMBER -> listOf("membership") + EventType.STATE_ROOM_CREATE -> listOf("creator") + EventType.STATE_ROOM_JOIN_RULES -> listOf("join_rule") + EventType.STATE_ROOM_POWER_LEVELS -> listOf("users", + "users_default", + "events", + "events_default", + "state_default", + "ban", + "kick", + "redact", + "invite") + EventType.STATE_ROOM_ALIASES -> listOf("aliases") + EventType.STATE_CANONICAL_ALIAS -> listOf("alias") + EventType.FEEDBACK -> listOf("type", "target_event_id") + else -> null + } + return Option.fromNullable(result) + } +} \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt index 8f256be4a7..1fb1b7700c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/group/GroupSummaryUpdater.kt @@ -1,62 +1,30 @@ package im.vector.matrix.android.internal.session.group -import android.arch.lifecycle.Observer import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.MatrixCallback -import im.vector.matrix.android.api.session.group.Group -import im.vector.matrix.android.internal.database.mapper.asDomain +import im.vector.matrix.android.internal.database.RealmLiveEntityObserver import im.vector.matrix.android.internal.database.model.GroupEntity import im.vector.matrix.android.internal.database.query.where -import timber.log.Timber -import java.util.concurrent.atomic.AtomicBoolean +import io.realm.RealmResults -internal class GroupSummaryUpdater(private val monarchy: Monarchy, +internal class GroupSummaryUpdater(monarchy: Monarchy, private val getGroupDataRequest: GetGroupDataRequest -) : Observer> { +) : RealmLiveEntityObserver(monarchy) { - private var isStarted = AtomicBoolean(false) - private val liveResults = monarchy.findAllManagedWithChanges { GroupEntity.where(it) } + override val query = Monarchy.Query { GroupEntity.where(it) } - fun start() { - if (isStarted.compareAndSet(false, true)) { - liveResults.observeForever(this) + override fun process(results: RealmResults, indexes: IntArray) { + indexes.forEach { index -> + val data = results[index] + fetchGroupData(data) } } - fun dispose() { - if (isStarted.compareAndSet(true, false)) { - liveResults.removeObserver(this) - } - } - - // PRIVATE - - override fun onChanged(changeSet: Monarchy.ManagedChangeSet?) { - if (changeSet == null) { + private fun fetchGroupData(data: GroupEntity?) { + if (data == null) { return } - val groups = changeSet.realmResults.map { it.asDomain() } - val indexesToUpdate = changeSet.orderedCollectionChangeSet.changes + changeSet.orderedCollectionChangeSet.insertions - updateGroupList(groups, indexesToUpdate) - } - - - private fun updateGroupList(groups: List, indexes: IntArray) { - indexes.forEach { - val group = groups[it] - try { - updateGroup(group) - } catch (e: Exception) { - Timber.e(e, "An error occured when updating room summaries") - } - } - } - - private fun updateGroup(group: Group?) { - if (group == null) { - return - } - getGroupDataRequest.execute(group.groupId, object : MatrixCallback {}) + getGroupDataRequest.execute(data.groupId, object : MatrixCallback {}) } } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomSummaryUpdater.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomSummaryUpdater.kt index 4fdbe7236f..91ff50db29 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/RoomSummaryUpdater.kt @@ -1,12 +1,12 @@ package im.vector.matrix.android.internal.session.room -import android.arch.lifecycle.Observer import android.content.Context import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.room.Room import im.vector.matrix.android.api.session.room.model.RoomTopicContent import im.vector.matrix.android.internal.auth.data.Credentials +import im.vector.matrix.android.internal.database.RealmLiveEntityObserver 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.RoomEntity @@ -16,53 +16,24 @@ import im.vector.matrix.android.internal.database.query.where import im.vector.matrix.android.internal.session.room.members.RoomDisplayNameResolver import im.vector.matrix.android.internal.session.room.members.RoomMembers import io.realm.Realm +import io.realm.RealmResults import io.realm.kotlin.createObject -import timber.log.Timber -import java.util.concurrent.atomic.AtomicBoolean -internal class RoomSummaryUpdater(private val monarchy: Monarchy, +internal class RoomSummaryUpdater(monarchy: Monarchy, private val roomDisplayNameResolver: RoomDisplayNameResolver, private val roomAvatarResolver: RoomAvatarResolver, private val context: Context, private val credentials: Credentials -) : Observer> { +) : RealmLiveEntityObserver(monarchy) { - private var isStarted = AtomicBoolean(false) - private val liveResults = monarchy.findAllManagedWithChanges { RoomEntity.where(it) } + override val query = Monarchy.Query { RoomEntity.where(it) } - fun start() { - if (isStarted.compareAndSet(false, true)) { - liveResults.observeForever(this) - } - } - - fun dispose() { - if (isStarted.compareAndSet(true, false)) { - liveResults.removeObserver(this) - } - } - - // PRIVATE - - override fun onChanged(changeSet: Monarchy.ManagedChangeSet?) { - if (changeSet == null) { - return - } - val rooms = changeSet.realmResults.map { it.asDomain() } - val indexesToUpdate = changeSet.orderedCollectionChangeSet.changes + changeSet.orderedCollectionChangeSet.insertions + override fun process(results: RealmResults, indexes: IntArray) { + val rooms = results.map { it.asDomain() } monarchy.writeAsync { realm -> - updateRoomList(realm, rooms, indexesToUpdate) - } - } - - - private fun updateRoomList(realm: Realm, rooms: List, indexes: IntArray) { - indexes.forEach { - val room = rooms[it] - try { - updateRoom(realm, room) - } catch (e: Exception) { - Timber.e(e, "An error occured when updating room summaries") + indexes.forEach { index -> + val data = rooms[index] + updateRoom(realm, data) } } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt index b502aa871e..bd287f9e89 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/RoomSyncHandler.kt @@ -11,11 +11,7 @@ import im.vector.matrix.android.internal.database.model.RoomSummaryEntity import im.vector.matrix.android.internal.database.query.findAllIncludingEvents import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom import im.vector.matrix.android.internal.database.query.where -import im.vector.matrix.android.internal.session.sync.model.InvitedRoomSync -import im.vector.matrix.android.internal.session.sync.model.RoomSync -import im.vector.matrix.android.internal.session.sync.model.RoomSyncEphemeral -import im.vector.matrix.android.internal.session.sync.model.RoomSyncSummary -import im.vector.matrix.android.internal.session.sync.model.RoomsSyncResponse +import im.vector.matrix.android.internal.session.sync.model.* import io.realm.Realm import io.realm.kotlin.createObject @@ -42,9 +38,9 @@ internal class RoomSyncHandler(private val monarchy: Monarchy, private fun handleRoomSync(realm: Realm, handlingStrategy: HandlingStrategy) { val rooms = when (handlingStrategy) { - is HandlingStrategy.JOINED -> handlingStrategy.data.map { handleJoinedRoom(realm, it.key, it.value) } + is HandlingStrategy.JOINED -> handlingStrategy.data.map { handleJoinedRoom(realm, it.key, it.value) } is HandlingStrategy.INVITED -> handlingStrategy.data.map { handleInvitedRoom(realm, it.key, it.value) } - is HandlingStrategy.LEFT -> handlingStrategy.data.map { handleLeftRoom(it.key, it.value) } + is HandlingStrategy.LEFT -> handlingStrategy.data.map { handleLeftRoom(it.key, it.value) } } realm.insertOrUpdate(rooms) } @@ -54,7 +50,7 @@ internal class RoomSyncHandler(private val monarchy: Monarchy, roomSync: RoomSync): RoomEntity { val roomEntity = RoomEntity.where(realm, roomId).findFirst() - ?: RoomEntity(roomId) + ?: RoomEntity(roomId) if (roomEntity.membership == MyMembership.INVITED) { roomEntity.chunks.deleteAllFromRealm() @@ -115,7 +111,7 @@ internal class RoomSyncHandler(private val monarchy: Monarchy, roomSummary: RoomSyncSummary) { val roomSummaryEntity = RoomSummaryEntity.where(realm, roomId).findFirst() - ?: RoomSummaryEntity(roomId) + ?: RoomSummaryEntity(roomId) if (roomSummary.heroes.isNotEmpty()) { roomSummaryEntity.heroes.clear() @@ -136,7 +132,6 @@ internal class RoomSyncHandler(private val monarchy: Monarchy, prevToken: String? = null, nextToken: String? = null, isLimited: Boolean = true): ChunkEntity { - val chunkEntity = if (!isLimited) { ChunkEntity.findLastLiveChunkFromRoom(realm, roomId) } else { @@ -157,5 +152,4 @@ internal class RoomSyncHandler(private val monarchy: Monarchy, .map { it.content() } .flatMap { readReceiptHandler.handle(realm, roomId, it) } } - } \ No newline at end of file