feat: cache archived rooms to access them with `getRoomById`
getRoomById searches now in the local cache for the given room and returns null if not found. If you have loaded the [archive] before, it can also return archived rooms. This should make it much easier to display archived rooms in the client.
This commit is contained in:
parent
9087f08775
commit
cec08b3775
|
|
@ -275,10 +275,14 @@ class Client extends MatrixApi {
|
|||
return null;
|
||||
}
|
||||
|
||||
/// Searches in the local cache for the given room and returns null if not
|
||||
/// found. If you have loaded the [archive] before, it can also return
|
||||
/// archived rooms.
|
||||
Room getRoomById(String id) {
|
||||
for (final room in rooms) {
|
||||
for (final room in <Room>[...rooms, ..._archivedRooms]) {
|
||||
if (room.id == id) return room;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -645,8 +649,10 @@ class Client extends MatrixApi {
|
|||
avatarUrl: profile.avatarUrl);
|
||||
}
|
||||
|
||||
final List<Room> _archivedRooms = [];
|
||||
|
||||
Future<List<Room>> get archive async {
|
||||
final archiveList = <Room>[];
|
||||
_archivedRooms.clear();
|
||||
final syncResp = await sync(
|
||||
filter: '{"room":{"include_leave":true,"timeline":{"limit":10}}}',
|
||||
timeout: 0,
|
||||
|
|
@ -681,10 +687,10 @@ class Client extends MatrixApi {
|
|||
));
|
||||
}
|
||||
}
|
||||
archiveList.add(leftRoom);
|
||||
_archivedRooms.add(leftRoom);
|
||||
}
|
||||
}
|
||||
return archiveList;
|
||||
return _archivedRooms;
|
||||
}
|
||||
|
||||
/// Uploads a file and automatically caches it in the database, if it is small enough
|
||||
|
|
|
|||
Loading…
Reference in New Issue