mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-21 05:38:49 +03:00
Improve logic
This commit is contained in:
parent
01ade64f3b
commit
879c4ffef6
1 changed files with 14 additions and 13 deletions
|
@ -129,8 +129,6 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
|
||||||
} else {
|
} else {
|
||||||
handlingStrategy.data.mapWithProgress(reporter, InitSyncStep.ImportingAccountJoinedRooms, 0.6f) {
|
handlingStrategy.data.mapWithProgress(reporter, InitSyncStep.ImportingAccountJoinedRooms, 0.6f) {
|
||||||
handleJoinedRoom(realm, it.key, it.value, insertType, syncLocalTimeStampMillis, aggregator)
|
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
|
// posting new events to timeline if any is registered
|
||||||
timelineInput.onNewTimelineEvents(roomId = roomId, eventIds = eventIds)
|
timelineInput.onNewTimelineEvents(roomId = roomId, eventIds = eventIds)
|
||||||
return chunkEntity
|
return chunkEntity
|
||||||
|
@ -513,17 +515,16 @@ 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
|
* 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
|
* we clear all SENT events, and we are sure that we will receive it from /sync or pagination
|
||||||
*/
|
*/
|
||||||
private fun fixStuckLocalEcho(rooms: List<RoomEntity>) {
|
private fun deleteLocalEchosIfNeeded(insertType: EventInsertType, roomEntity: RoomEntity, eventList: List<Event>) {
|
||||||
// when there are not room events, there is no need to delete SENT messages
|
// Skip deletion if we are on initial sync
|
||||||
// this might be useful for events like typing etc
|
if(insertType == EventInsertType.INITIAL_SYNC) return
|
||||||
if (rooms.isNullOrEmpty()) return
|
// Skip deletion if there are no timeline events or there is no event received from the current user
|
||||||
rooms.forEach { roomEntity ->
|
if(eventList.firstOrNull { it.senderId == userId } == null) return
|
||||||
roomEntity.sendingTimelineEvents.filter { timelineEvent ->
|
roomEntity.sendingTimelineEvents.filter { timelineEvent ->
|
||||||
timelineEvent.root?.sendState == SendState.SENT
|
timelineEvent.root?.sendState == SendState.SENT
|
||||||
}.forEach {
|
}.forEach {
|
||||||
roomEntity.sendingTimelineEvents.remove(it)
|
roomEntity.sendingTimelineEvents.remove(it)
|
||||||
it.deleteOnCascade(true)
|
it.deleteOnCascade(true)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue