diff --git a/lib/src/room.dart b/lib/src/room.dart index c0baee6b..ff676f42 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -646,7 +646,7 @@ class Room { threadRootEventId: threadRootEventId, threadLastEventId: threadLastEventId); } - + final eventContent = getEventContentFromMsgText( message: message, parseMarkdown: parseMarkdown, @@ -1030,10 +1030,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; @@ -1046,7 +1048,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) {