Merge branch 'grieshofer/keeping-a-list-of-left-rooms-in-the-client' into 'main'
feat: Expose a getter for all rooms including archived rooms See merge request famedly/company/frontend/famedlysdk!1251
This commit is contained in:
commit
7c480c8d87
|
|
@ -252,6 +252,12 @@ class Client extends MatrixApi {
|
|||
List<Room> get rooms => _rooms;
|
||||
List<Room> _rooms = [];
|
||||
|
||||
/// Get a list of the archived rooms
|
||||
///
|
||||
/// Attention! Archived rooms are only returned if [loadArchive()] was called
|
||||
/// beforehand! The state refers to the last retrieval via [loadArchive()]!
|
||||
List<ArchivedRoom> get archivedRooms => _archivedRooms;
|
||||
|
||||
bool enableDehydratedDevices = false;
|
||||
|
||||
/// Whether this client supports end-to-end encryption using olm.
|
||||
|
|
@ -264,7 +270,7 @@ class Client extends MatrixApi {
|
|||
|
||||
String get fingerprintKey => encryption?.fingerprintKey ?? '';
|
||||
|
||||
/// Wheather this session is unknown to others
|
||||
/// Whether this session is unknown to others
|
||||
bool get isUnknownSession =>
|
||||
userDeviceKeys[userID]?.deviceKeys[deviceID]?.signed != true;
|
||||
|
||||
|
|
@ -1187,7 +1193,7 @@ class Client extends MatrixApi {
|
|||
/// full Room object with the sender User object in it. Returns null if this
|
||||
/// push notification is not corresponding to an existing event.
|
||||
/// The client does **not** need to be initialized first. If it is not
|
||||
/// initalized, it will only fetch the necessary parts of the database. This
|
||||
/// initialized, it will only fetch the necessary parts of the database. This
|
||||
/// should make it possible to run this parallel to another client with the
|
||||
/// same client name.
|
||||
/// This also checks if the given event has a readmarker and returns null
|
||||
|
|
|
|||
|
|
@ -1393,6 +1393,17 @@ class Room {
|
|||
} else {
|
||||
final archive = client.getArchiveRoomFromCache(id);
|
||||
events = archive?.timeline.events.toList() ?? [];
|
||||
for (var i = 0; i < events.length; i++) {
|
||||
// Try to decrypt encrypted events but don't update the database.
|
||||
if (encrypted && client.encryptionEnabled) {
|
||||
if (events[i].type == EventTypes.Encrypted) {
|
||||
events[i] = await client.encryption!.decryptRoomEvent(
|
||||
id,
|
||||
events[i],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var chunk = TimelineChunk(events: events);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import 'dart:convert';
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:canonical_json/canonical_json.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:olm/olm.dart' as olm;
|
||||
import 'package:test/test.dart';
|
||||
|
||||
|
|
@ -1016,6 +1017,38 @@ void main() {
|
|||
expect(storedEvent2?.eventId, event?.eventId);
|
||||
});
|
||||
|
||||
test('Rooms and archived rooms getter', () async {
|
||||
final client = await getClient();
|
||||
await Future.delayed(Duration(milliseconds: 50));
|
||||
|
||||
expect(client.rooms.length, 2,
|
||||
reason:
|
||||
'Count of invited+joined before loadArchive() rooms does not match');
|
||||
expect(client.archivedRooms.length, 0,
|
||||
reason:
|
||||
'Count of archived rooms before loadArchive() does not match');
|
||||
|
||||
await client.loadArchive();
|
||||
|
||||
expect(client.rooms.length, 2,
|
||||
reason: 'Count of invited+joined rooms does not match');
|
||||
expect(client.archivedRooms.length, 2,
|
||||
reason: 'Count of archived rooms does not match');
|
||||
|
||||
expect(
|
||||
client.archivedRooms.firstWhereOrNull(
|
||||
(r) => r.room.id == '!5345234234:example.com') !=
|
||||
null,
|
||||
true,
|
||||
reason: '!5345234234:example.com not found as archived room');
|
||||
expect(
|
||||
client.archivedRooms.firstWhereOrNull(
|
||||
(r) => r.room.id == '!5345234235:example.com') !=
|
||||
null,
|
||||
true,
|
||||
reason: '!5345234235:example.com not found as archived room');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
matrix.dispose(closeDatabase: true);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue