forked from GitHub-Mirror/riotX-android
Sync : add log and continue when read_receipts fail
This commit is contained in:
parent
d110dac0a6
commit
04b4f32e16
@ -18,6 +18,7 @@ package im.vector.matrix.android.internal.session.sync
|
|||||||
|
|
||||||
import im.vector.matrix.android.internal.database.model.ReadReceiptEntity
|
import im.vector.matrix.android.internal.database.model.ReadReceiptEntity
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
|
||||||
// the receipts dictionnaries
|
// the receipts dictionnaries
|
||||||
@ -29,26 +30,32 @@ typealias ReadReceiptContent = Map<String, Map<String, Map<String, Map<String, D
|
|||||||
|
|
||||||
internal class ReadReceiptHandler {
|
internal class ReadReceiptHandler {
|
||||||
|
|
||||||
fun handle(realm: Realm, roomId: String, content: ReadReceiptContent?): List<ReadReceiptEntity> {
|
fun handle(realm: Realm, roomId: String, content: ReadReceiptContent?) {
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
return emptyList()
|
return
|
||||||
}
|
}
|
||||||
val readReceipts = content
|
try {
|
||||||
|
val readReceipts = mapContentToReadReceiptEntities(roomId, content)
|
||||||
|
realm.insertOrUpdate(readReceipts)
|
||||||
|
} catch (exception: Exception) {
|
||||||
|
Timber.e("Fail to handle read receipt for room $roomId")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun mapContentToReadReceiptEntities(roomId: String, content: ReadReceiptContent): List<ReadReceiptEntity> {
|
||||||
|
return content
|
||||||
.flatMap { (eventId, receiptDict) ->
|
.flatMap { (eventId, receiptDict) ->
|
||||||
receiptDict
|
receiptDict
|
||||||
.filterKeys { it == "m.read" }
|
.filterKeys { it == "m.read" }
|
||||||
.flatMap { (_, userIdsDict) ->
|
.flatMap { (_, userIdsDict) ->
|
||||||
userIdsDict.map { (userId, paramsDict) ->
|
userIdsDict.map { (userId, paramsDict) ->
|
||||||
val ts = paramsDict.filterKeys { it == "ts" }
|
val ts = paramsDict.filterKeys { it == "ts" }
|
||||||
.values
|
.values
|
||||||
.firstOrNull() ?: 0.0
|
.firstOrNull() ?: 0.0
|
||||||
val primaryKey = roomId + userId
|
val primaryKey = roomId + userId
|
||||||
ReadReceiptEntity(primaryKey, userId, eventId, roomId, ts)
|
ReadReceiptEntity(primaryKey, userId, eventId, roomId, ts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
realm.insertOrUpdate(readReceipts)
|
|
||||||
return readReceipts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -32,9 +32,14 @@ import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoo
|
|||||||
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.room.RoomSummaryUpdater
|
import im.vector.matrix.android.internal.session.room.RoomSummaryUpdater
|
||||||
import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection
|
import im.vector.matrix.android.internal.session.room.timeline.PaginationDirection
|
||||||
import im.vector.matrix.android.internal.session.sync.model.*
|
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.RoomSyncAccountData
|
||||||
|
import im.vector.matrix.android.internal.session.sync.model.RoomSyncEphemeral
|
||||||
|
import im.vector.matrix.android.internal.session.sync.model.RoomsSyncResponse
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.kotlin.createObject
|
import io.realm.kotlin.createObject
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
internal class RoomSyncHandler(private val monarchy: Monarchy,
|
internal class RoomSyncHandler(private val monarchy: Monarchy,
|
||||||
private val readReceiptHandler: ReadReceiptHandler,
|
private val readReceiptHandler: ReadReceiptHandler,
|
||||||
@ -70,8 +75,10 @@ internal class RoomSyncHandler(private val monarchy: Monarchy,
|
|||||||
roomId: String,
|
roomId: String,
|
||||||
roomSync: RoomSync): RoomEntity {
|
roomSync: RoomSync): RoomEntity {
|
||||||
|
|
||||||
|
Timber.v("Handle join sync for room $roomId")
|
||||||
|
|
||||||
val roomEntity = RoomEntity.where(realm, roomId).findFirst()
|
val roomEntity = RoomEntity.where(realm, roomId).findFirst()
|
||||||
?: realm.createObject(roomId)
|
?: realm.createObject(roomId)
|
||||||
|
|
||||||
if (roomEntity.membership == MyMembership.INVITED) {
|
if (roomEntity.membership == MyMembership.INVITED) {
|
||||||
roomEntity.chunks.deleteAllFromRealm()
|
roomEntity.chunks.deleteAllFromRealm()
|
||||||
@ -119,6 +126,9 @@ internal class RoomSyncHandler(private val monarchy: Monarchy,
|
|||||||
roomId: String,
|
roomId: String,
|
||||||
roomSync:
|
roomSync:
|
||||||
InvitedRoomSync): RoomEntity {
|
InvitedRoomSync): RoomEntity {
|
||||||
|
|
||||||
|
Timber.v("Handle invited sync for room $roomId")
|
||||||
|
|
||||||
val roomEntity = RoomEntity()
|
val roomEntity = RoomEntity()
|
||||||
roomEntity.roomId = roomId
|
roomEntity.roomId = roomId
|
||||||
roomEntity.membership = MyMembership.INVITED
|
roomEntity.membership = MyMembership.INVITED
|
||||||
@ -164,7 +174,7 @@ internal class RoomSyncHandler(private val monarchy: Monarchy,
|
|||||||
ephemeral.events
|
ephemeral.events
|
||||||
.filter { it.type == EventType.RECEIPT }
|
.filter { it.type == EventType.RECEIPT }
|
||||||
.map { it.content.toModel<ReadReceiptContent>() }
|
.map { it.content.toModel<ReadReceiptContent>() }
|
||||||
.flatMap { readReceiptHandler.handle(realm, roomId, it) }
|
.forEach { readReceiptHandler.handle(realm, roomId, it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRoomAccountDataEvents(realm: Realm, roomId: String, accountData: RoomSyncAccountData) {
|
private fun handleRoomAccountDataEvents(realm: Realm, roomId: String, accountData: RoomSyncAccountData) {
|
||||||
|
Loading…
Reference in New Issue
Block a user