Merge pull request #8168 from SpiritCroc/chunk-roomids
matrix-sdk: Ensure correct room for events loaded by chunks
This commit is contained in:
commit
c7928c2228
1
changelog.d/8168.bugfix
Normal file
1
changelog.d/8168.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix timeline loading a wrong room on permalink if a matching event id is found in a different room
|
@ -297,7 +297,7 @@ internal fun updateThreadNotifications(roomId: String, realm: Realm, currentUser
|
|||||||
val readReceipt = findMyReadReceipt(realm, roomId, currentUserId, threadId = rootThreadEventId) ?: return
|
val readReceipt = findMyReadReceipt(realm, roomId, currentUserId, threadId = rootThreadEventId) ?: return
|
||||||
|
|
||||||
val readReceiptChunk = ChunkEntity
|
val readReceiptChunk = ChunkEntity
|
||||||
.findIncludingEvent(realm, readReceipt) ?: return
|
.findIncludingEvent(realm, roomId, readReceipt) ?: return
|
||||||
|
|
||||||
val readReceiptChunkThreadEvents = readReceiptChunk
|
val readReceiptChunkThreadEvents = readReceiptChunk
|
||||||
.timelineEvents
|
.timelineEvents
|
||||||
|
@ -72,15 +72,16 @@ internal fun ChunkEntity.Companion.findEventInThreadChunk(realm: Realm, roomId:
|
|||||||
.findFirst()
|
.findFirst()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ChunkEntity.Companion.findAllIncludingEvents(realm: Realm, eventIds: List<String>): RealmResults<ChunkEntity> {
|
internal fun ChunkEntity.Companion.findAllIncludingEvents(realm: Realm, roomId: String, eventIds: List<String>): RealmResults<ChunkEntity> {
|
||||||
return realm.where<ChunkEntity>()
|
return realm.where<ChunkEntity>()
|
||||||
|
.equalTo(ChunkEntityFields.ROOM.ROOM_ID, roomId)
|
||||||
.`in`(ChunkEntityFields.TIMELINE_EVENTS.EVENT_ID, eventIds.toTypedArray())
|
.`in`(ChunkEntityFields.TIMELINE_EVENTS.EVENT_ID, eventIds.toTypedArray())
|
||||||
.isNull(ChunkEntityFields.ROOT_THREAD_EVENT_ID)
|
.isNull(ChunkEntityFields.ROOT_THREAD_EVENT_ID)
|
||||||
.findAll()
|
.findAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ChunkEntity.Companion.findIncludingEvent(realm: Realm, eventId: String): ChunkEntity? {
|
internal fun ChunkEntity.Companion.findIncludingEvent(realm: Realm, roomId: String, eventId: String): ChunkEntity? {
|
||||||
return findAllIncludingEvents(realm, listOf(eventId)).firstOrNull()
|
return findAllIncludingEvents(realm, roomId, listOf(eventId)).firstOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ChunkEntity.Companion.create(
|
internal fun ChunkEntity.Companion.create(
|
||||||
|
@ -76,11 +76,11 @@ private fun hasReadMissingEvent(realm: Realm,
|
|||||||
userId: String,
|
userId: String,
|
||||||
eventId: String,
|
eventId: String,
|
||||||
threadId: String? = ReadService.THREAD_ID_MAIN): Boolean {
|
threadId: String? = ReadService.THREAD_ID_MAIN): Boolean {
|
||||||
return realm.doesEventExistInChunkHistory(eventId) && realm.hasReadReceiptInLatestChunk(latestChunkEntity, roomId, userId, threadId)
|
return realm.doesEventExistInChunkHistory(roomId, eventId) && realm.hasReadReceiptInLatestChunk(latestChunkEntity, roomId, userId, threadId)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Realm.doesEventExistInChunkHistory(eventId: String): Boolean {
|
private fun Realm.doesEventExistInChunkHistory(roomId: String, eventId: String): Boolean {
|
||||||
return ChunkEntity.findIncludingEvent(this, eventId) != null
|
return ChunkEntity.findIncludingEvent(this, roomId, eventId) != null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Realm.hasReadReceiptInLatestChunk(latestChunkEntity: ChunkEntity, roomId: String, userId: String, threadId: String?): Boolean {
|
private fun Realm.hasReadReceiptInLatestChunk(latestChunkEntity: ChunkEntity, roomId: String, userId: String, threadId: String?): Boolean {
|
||||||
|
@ -59,7 +59,7 @@ internal class DefaultFetchTokenAndPaginateTask @Inject constructor(
|
|||||||
?: throw IllegalStateException("No token found")
|
?: throw IllegalStateException("No token found")
|
||||||
|
|
||||||
monarchy.awaitTransaction { realm ->
|
monarchy.awaitTransaction { realm ->
|
||||||
val chunkToUpdate = ChunkEntity.findIncludingEvent(realm, params.lastKnownEventId)
|
val chunkToUpdate = ChunkEntity.findIncludingEvent(realm, params.roomId, params.lastKnownEventId)
|
||||||
if (params.direction == PaginationDirection.FORWARDS) {
|
if (params.direction == PaginationDirection.FORWARDS) {
|
||||||
chunkToUpdate?.nextToken = fromToken
|
chunkToUpdate?.nextToken = fromToken
|
||||||
} else {
|
} else {
|
||||||
|
@ -278,7 +278,7 @@ internal class LoadTimelineStrategy constructor(
|
|||||||
.findAll()
|
.findAll()
|
||||||
}
|
}
|
||||||
is Mode.Permalink -> {
|
is Mode.Permalink -> {
|
||||||
ChunkEntity.findAllIncludingEvents(realm, listOf(mode.originEventId))
|
ChunkEntity.findAllIncludingEvents(realm, roomId, listOf(mode.originEventId))
|
||||||
}
|
}
|
||||||
is Mode.Thread -> {
|
is Mode.Thread -> {
|
||||||
recreateThreadChunkEntity(realm, mode.rootThreadEventId)
|
recreateThreadChunkEntity(realm, mode.rootThreadEventId)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user