refactor: Use handleRoomEvents method instead of handleEvent

This makes it easier to update
the state by a whole timeline.
This commit is contained in:
Christian Pauly 2022-06-28 09:24:32 +02:00
parent fc229c5715
commit c591c1d4b5
1 changed files with 69 additions and 77 deletions

View File

@ -1749,7 +1749,7 @@ class Client extends MatrixApi {
Future<void> _handleEphemerals(Room room, List<BasicRoomEvent> events) async { Future<void> _handleEphemerals(Room room, List<BasicRoomEvent> events) async {
for (final event in events) { for (final event in events) {
await _handleEvent(event, room, EventUpdateType.ephemeral); await _handleRoomEvents(room, [event], EventUpdateType.ephemeral);
// Receipt events are deltas between two states. We will create a // Receipt events are deltas between two states. We will create a
// fake room account data event for this and store the difference // fake room account data event for this and store the difference
@ -1783,7 +1783,7 @@ class Client extends MatrixApi {
} }
} }
event.content = receiptStateContent; event.content = receiptStateContent;
await _handleEvent(event, room, EventUpdateType.accountData); await _handleRoomEvents(room, [event], EventUpdateType.accountData);
} }
} }
} }
@ -1794,15 +1794,6 @@ class Client extends MatrixApi {
EventUpdateType type, EventUpdateType type,
) async { ) async {
for (final event in events) { for (final event in events) {
await _handleEvent(event, room, type);
}
}
Future<void> _handleEvent(
BasicEvent event,
Room room,
EventUpdateType type,
) async {
// The client must ignore any new m.room.encryption event to prevent // The client must ignore any new m.room.encryption event to prevent
// man-in-the-middle attacks! // man-in-the-middle attacks!
if ((event.type == EventTypes.Encryption && if ((event.type == EventTypes.Encryption &&
@ -1875,6 +1866,7 @@ class Client extends MatrixApi {
} }
} }
} }
}
Room _updateRoomsByRoomUpdate(String roomId, SyncRoomUpdate chatUpdate) { Room _updateRoomsByRoomUpdate(String roomId, SyncRoomUpdate chatUpdate) {
// Update the chat list item. // Update the chat list item.