Merge pull request #4960 from vector-im/feature/aris/improve_local_echo_stuck_fix

Avoid deleting sent messages on non room events
This commit is contained in:
Benoit Marty 2022-01-17 15:26:46 +01:00 committed by GitHub
commit eafb76b9b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

1
changelog.d/4960.misc Normal file
View File

@ -0,0 +1 @@
Improves local echo blinking when non room events received

View File

@ -129,8 +129,6 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
} else {
handlingStrategy.data.mapWithProgress(reporter, InitSyncStep.ImportingAccountJoinedRooms, 0.6f) {
handleJoinedRoom(realm, it.key, it.value, insertType, syncLocalTimeStampMillis, aggregator)
}.also {
fixStuckLocalEcho(it)
}
}
}
@ -428,6 +426,10 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
}
}
}
// Handle deletion of [stuck] local echos if needed
deleteLocalEchosIfNeeded(insertType, roomEntity, eventList)
// posting new events to timeline if any is registered
timelineInput.onNewTimelineEvents(roomId = roomId, eventIds = eventIds)
return chunkEntity
@ -513,8 +515,11 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
* While we cannot know when a specific event arrived from the pagination (no transactionId included), after each room /sync
* we clear all SENT events, and we are sure that we will receive it from /sync or pagination
*/
private fun fixStuckLocalEcho(rooms: List<RoomEntity>) {
rooms.forEach { roomEntity ->
private fun deleteLocalEchosIfNeeded(insertType: EventInsertType, roomEntity: RoomEntity, eventList: List<Event>) {
// Skip deletion if we are on initial sync
if (insertType == EventInsertType.INITIAL_SYNC) return
// Skip deletion if there are no timeline events or there is no event received from the current user
if (eventList.firstOrNull { it.senderId == userId } == null) return
roomEntity.sendingTimelineEvents.filter { timelineEvent ->
timelineEvent.root?.sendState == SendState.SENT
}.forEach {
@ -523,4 +528,3 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
}
}
}
}