diff --git a/doc/adr/0004-support-filter-for-request-history.md b/doc/adr/0004-support-filter-for-request-history.md new file mode 100644 index 00000000..41031445 --- /dev/null +++ b/doc/adr/0004-support-filter-for-request-history.md @@ -0,0 +1,24 @@ +# 4. Support filter for request history + +Date: 2024-12-09 + +## Status + +Accepted + +- Issue: [#1862](https://github.com/linagora/twake-on-matrix/issues/1862) + +## Context + +- The date of the last message in chat list display is not correct. +- The message in chat screen is not displayed correctly so block user by empty screen. + +## Decision + +- Add `StateFilter` to request history to request specific data from the server. + +## Consequences + +- The `timeLine` and `event` can be filtered by the user to get specific data from the server. +- Display the correct message in chat screen. Prevent block user by empty screen. +- In the chat list, we improve the display date time of the last message soon. diff --git a/lib/src/room.dart b/lib/src/room.dart index 6dd8afb2..9aefeb70 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1037,10 +1037,12 @@ class Room { /// be received maximum. When the request is answered, [onHistoryReceived] will be triggered **before** /// the historical events will be published in the onEvent stream. /// Returns the actual count of received timeline events. - Future requestHistory( - {int historyCount = defaultHistoryCount, - void Function()? onHistoryReceived, - direction = Direction.b}) async { + Future requestHistory({ + int historyCount = defaultHistoryCount, + void Function()? onHistoryReceived, + direction = Direction.b, + StateFilter? filter, + }) async { final prev_batch = this.prev_batch; final storeInDatabase = !isArchived; @@ -1053,7 +1055,7 @@ class Room { direction, from: prev_batch, limit: historyCount, - filter: jsonEncode(StateFilter(lazyLoadMembers: true).toJson()), + filter: jsonEncode((filter ?? StateFilter(lazyLoadMembers: true)).toJson()), ); if (onHistoryReceived != null) onHistoryReceived(); diff --git a/lib/src/timeline.dart b/lib/src/timeline.dart index cc1cd76a..66481fef 100644 --- a/lib/src/timeline.dart +++ b/lib/src/timeline.dart @@ -30,6 +30,7 @@ import 'package:matrix/src/models/timeline_chunk.dart'; class Timeline { final Room room; + List get events => chunk.events; /// Map of event ID to map of type to set of aggregated events @@ -79,14 +80,20 @@ class Timeline { return room.prev_batch != null && events.last.type != EventTypes.RoomCreate; } - Future requestHistory( - {int historyCount = Room.defaultHistoryCount}) async { + Future requestHistory({ + int historyCount = Room.defaultHistoryCount, + StateFilter? filter, + }) async { if (isRequestingHistory) { return; } isRequestingHistory = true; - await _requestEvents(direction: Direction.b, historyCount: historyCount); + await _requestEvents( + direction: Direction.b, + historyCount: historyCount, + filter: filter, + ); isRequestingHistory = false; } @@ -104,9 +111,11 @@ class Timeline { isRequestingFuture = false; } - Future _requestEvents( - {int historyCount = Room.defaultHistoryCount, - required Direction direction}) async { + Future _requestEvents({ + int historyCount = Room.defaultHistoryCount, + required Direction direction, + StateFilter? filter, + }) async { onUpdate?.call(); try { @@ -151,11 +160,13 @@ class Timeline { await getRoomEvents( historyCount: historyCount, direction: direction, + filter: filter, ); } else { await room.requestHistory( historyCount: historyCount, direction: direction, + filter: filter, onHistoryReceived: () { _collectHistoryUpdates = true; }, @@ -173,15 +184,19 @@ class Timeline { /// be received maximum. When the request is answered, [onHistoryReceived] will be triggered **before** /// the historical events will be published in the onEvent stream. /// Returns the actual count of received timeline events. - Future getRoomEvents( - {int historyCount = Room.defaultHistoryCount, - direction = Direction.b}) async { + Future getRoomEvents({ + int historyCount = Room.defaultHistoryCount, + direction = Direction.b, + StateFilter? filter, + }) async { final resp = await room.client.getRoomEvents( room.id, direction, from: direction == Direction.b ? chunk.prevBatch : chunk.nextBatch, limit: historyCount, - filter: jsonEncode(StateFilter(lazyLoadMembers: true).toJson()), + filter: jsonEncode( + (filter ?? StateFilter(lazyLoadMembers: true)).toJson(), + ), ); if (resp.end == null) {