fix: Fetching history sometimes re-sorting events in the timeline

This commit is contained in:
Sorunome 2020-11-08 14:54:19 +01:00
parent 66572bd032
commit c509144987
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 8 additions and 2 deletions

View File

@ -421,6 +421,8 @@ class Database extends _$Database {
if (roomUpdate.limitedTimeline) { if (roomUpdate.limitedTimeline) {
await removeSuccessfulRoomEvents(clientId, roomUpdate.id); await removeSuccessfulRoomEvents(clientId, roomUpdate.id);
await updateRoomSortOrder(0.0, 0.0, clientId, roomUpdate.id); await updateRoomSortOrder(0.0, 0.0, clientId, roomUpdate.id);
}
if (roomUpdate.prev_batch != null) {
await setRoomPrevBatch(roomUpdate.prev_batch, clientId, roomUpdate.id); await setRoomPrevBatch(roomUpdate.prev_batch, clientId, roomUpdate.id);
} }
} }

View File

@ -287,8 +287,12 @@ class Timeline {
if (i < events.length) { if (i < events.length) {
// if the old status is larger than the new one, we also want to preserve the old status // if the old status is larger than the new one, we also want to preserve the old status
final oldStatus = events[i].status; final oldStatus = events[i].status;
events[i] = events[i] = Event.fromJson(
Event.fromJson(eventUpdate.content, room, eventUpdate.sortOrder); eventUpdate.content,
room,
eventUpdate.type == EventUpdateType.history
? events[i].sortOrder
: eventUpdate.sortOrder);
// do we preserve the status? we should allow 0 -> -1 updates and status increases // do we preserve the status? we should allow 0 -> -1 updates and status increases
if (status < oldStatus && !(status == -1 && oldStatus == 0)) { if (status < oldStatus && !(status == -1 && oldStatus == 0)) {
events[i].status = oldStatus; events[i].status = oldStatus;