chore: incrementally add left rooms to archive
- store left rooms in archive during sync (as well as they are removed on join already) - refactor room archive code - fix typo Internal reference: SMC-385 Signed-off-by: The one with the braid <info@braid.business>
This commit is contained in:
parent
8c638a7554
commit
053dddb76d
|
|
@ -261,7 +261,7 @@ class Client extends MatrixApi {
|
||||||
|
|
||||||
bool enableDehydratedDevices = false;
|
bool enableDehydratedDevices = false;
|
||||||
|
|
||||||
/// Wether read receipts are sent as public receipts by default or just as private receipts.
|
/// Whether read receipts are sent as public receipts by default or just as private receipts.
|
||||||
bool receiptsPublicByDefault = true;
|
bool receiptsPublicByDefault = true;
|
||||||
|
|
||||||
/// Whether this client supports end-to-end encryption using olm.
|
/// Whether this client supports end-to-end encryption using olm.
|
||||||
|
|
@ -933,8 +933,14 @@ class Client extends MatrixApi {
|
||||||
final leave = syncResp.rooms?.leave;
|
final leave = syncResp.rooms?.leave;
|
||||||
if (leave != null) {
|
if (leave != null) {
|
||||||
for (final entry in leave.entries) {
|
for (final entry in leave.entries) {
|
||||||
final id = entry.key;
|
await _storeArchivedRoom(entry.key, entry.value);
|
||||||
final room = entry.value;
|
}
|
||||||
|
}
|
||||||
|
return _archivedRooms;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _storeArchivedRoom(String id, LeftRoomUpdate update) async {
|
||||||
|
final room = update;
|
||||||
final leftRoom = Room(
|
final leftRoom = Room(
|
||||||
id: id,
|
id: id,
|
||||||
membership: Membership.leave,
|
membership: Membership.leave,
|
||||||
|
|
@ -972,10 +978,13 @@ class Client extends MatrixApi {
|
||||||
// Try to decrypt encrypted events but don't update the database.
|
// Try to decrypt encrypted events but don't update the database.
|
||||||
if (leftRoom.encrypted && leftRoom.client.encryptionEnabled) {
|
if (leftRoom.encrypted && leftRoom.client.encryptionEnabled) {
|
||||||
if (timeline.events[i].type == EventTypes.Encrypted) {
|
if (timeline.events[i].type == EventTypes.Encrypted) {
|
||||||
timeline.events[i] =
|
await leftRoom.client.encryption!
|
||||||
await leftRoom.client.encryption!.decryptRoomEvent(
|
.decryptRoomEvent(
|
||||||
leftRoom.id,
|
leftRoom.id,
|
||||||
timeline.events[i],
|
timeline.events[i],
|
||||||
|
)
|
||||||
|
.then(
|
||||||
|
(decrypted) => timeline.events[i] = decrypted,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -983,9 +992,6 @@ class Client extends MatrixApi {
|
||||||
|
|
||||||
_archivedRooms.add(ArchivedRoom(room: leftRoom, timeline: timeline));
|
_archivedRooms.add(ArchivedRoom(room: leftRoom, timeline: timeline));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return _archivedRooms;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Uploads a file and automatically caches it in the database, if it is small enough
|
/// Uploads a file and automatically caches it in the database, if it is small enough
|
||||||
/// and returns the mxc url.
|
/// and returns the mxc url.
|
||||||
|
|
@ -1885,7 +1891,7 @@ class Client extends MatrixApi {
|
||||||
final syncRoomUpdate = entry.value;
|
final syncRoomUpdate = entry.value;
|
||||||
|
|
||||||
await database?.storeRoomUpdate(id, syncRoomUpdate, this);
|
await database?.storeRoomUpdate(id, syncRoomUpdate, this);
|
||||||
final room = _updateRoomsByRoomUpdate(id, syncRoomUpdate);
|
final room = await _updateRoomsByRoomUpdate(id, syncRoomUpdate);
|
||||||
|
|
||||||
final timelineUpdateType = direction != null
|
final timelineUpdateType = direction != null
|
||||||
? (direction == Direction.b
|
? (direction == Direction.b
|
||||||
|
|
@ -2125,7 +2131,8 @@ class Client extends MatrixApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Room _updateRoomsByRoomUpdate(String roomId, SyncRoomUpdate chatUpdate) {
|
Future<Room> _updateRoomsByRoomUpdate(
|
||||||
|
String roomId, SyncRoomUpdate chatUpdate) async {
|
||||||
// Update the chat list item.
|
// Update the chat list item.
|
||||||
// Search the room in the rooms
|
// Search the room in the rooms
|
||||||
final roomIndex = rooms.indexWhere((r) => r.id == roomId);
|
final roomIndex = rooms.indexWhere((r) => r.id == roomId);
|
||||||
|
|
@ -2169,7 +2176,7 @@ class Client extends MatrixApi {
|
||||||
|
|
||||||
rooms.removeAt(roomIndex);
|
rooms.removeAt(roomIndex);
|
||||||
}
|
}
|
||||||
// Update notification, highlight count and/or additional informations
|
// Update notification, highlight count and/or additional information
|
||||||
else if (found &&
|
else if (found &&
|
||||||
chatUpdate is JoinedRoomUpdate &&
|
chatUpdate is JoinedRoomUpdate &&
|
||||||
(rooms[roomIndex].membership != membership ||
|
(rooms[roomIndex].membership != membership ||
|
||||||
|
|
@ -2202,6 +2209,10 @@ class Client extends MatrixApi {
|
||||||
runInRoot(rooms[roomIndex].requestHistory);
|
runInRoot(rooms[roomIndex].requestHistory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// in order to keep the archive in sync, add left room to archive
|
||||||
|
if (chatUpdate is LeftRoomUpdate) {
|
||||||
|
await _storeArchivedRoom(room.id, chatUpdate);
|
||||||
|
}
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue