diff --git a/lib/src/Client.dart b/lib/src/Client.dart index 9698c46e..38fdc14e 100644 --- a/lib/src/Client.dart +++ b/lib/src/Client.dart @@ -219,6 +219,17 @@ class Client { type: HTTPType.POST, action: "/client/r0/join/$id"); } + /// Loads the contact list for this user excluding the user itself. + /// Currently the contacts are found by discovering the contacts of + /// the famedlyContactDiscovery room, which is + /// defined by the autojoin room feature in Synapse. + Future> loadFamedlyContacts() async { + Room contactDiscoveryRoom = await store + .getRoomByAlias("#famedlyContactDiscovery:${userID.split(":")[1]}"); + List contacts = await contactDiscoveryRoom.requestParticipants(); + return contacts; + } + /// Creates a new group chat and invites the given Users and returns the new /// created room ID. Future createGroup(List users) async { diff --git a/lib/src/Connection.dart b/lib/src/Connection.dart index a6be6bad..479daaa9 100644 --- a/lib/src/Connection.dart +++ b/lib/src/Connection.dart @@ -53,7 +53,7 @@ class Connection { String get _syncFilters => '{"room":{"state":{"lazy_load_members":true}}}'; String get _firstSyncFilters => - '{"room":{"include_leave":true,"state":{"lazy_load_members":false}}}'; + '{"room":{"include_leave":true,"state":{"lazy_load_members":true}}}'; /// Handles the connection to the Matrix Homeserver. You can change this to a /// MockClient for testing. diff --git a/lib/src/Store.dart b/lib/src/Store.dart index df628a68..45b3a28d 100644 --- a/lib/src/Store.dart +++ b/lib/src/Store.dart @@ -458,6 +458,7 @@ class Store { /// Loads all Users in the database to provide a contact list /// except users who are in the Room with the ID [exceptRoomID]. + @deprecated Future> loadContacts({String exceptRoomID = ""}) async { List> res = await db.rawQuery( "SELECT * FROM Users WHERE matrix_id!=? AND chat_id!=? GROUP BY matrix_id ORDER BY displayname", @@ -549,6 +550,14 @@ class Store { return Room.getRoomFromTableRow(res[0], client); } + /// Returns a room without events and participants. + Future getRoomByAlias(String alias) async { + List> res = await db + .rawQuery("SELECT * FROM Rooms WHERE canonical_alias=?", [alias]); + if (res.length != 1) return null; + return Room.getRoomFromTableRow(res[0], client); + } + /// Calculates and returns an avatar for a direct chat by a given [roomID]. Future getAvatarFromSingleChat(String roomID) async { String avatarStr = ""; @@ -592,7 +601,8 @@ class Store { /// the user [userID]. Returns null if there is none. Future getDirectChatRoomID(String userID) async { List> res = await db.rawQuery( - "SELECT id FROM Rooms WHERE direct_chat_matrix_id=?", [userID]); + "SELECT id FROM Rooms WHERE direct_chat_matrix_id=? AND membership!='leave' LIMIT 1", + [userID]); if (res.length != 1) return null; return res[0]["id"]; } diff --git a/pubspec.lock b/pubspec.lock index 609ce879..ef602ebe 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -28,7 +28,7 @@ packages: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.0.4" build: dependency: transitive description: @@ -297,7 +297,7 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.8.0+1" + version: "1.7.0" pool: dependency: transitive description: diff --git a/test/FakeMatrixApi.dart b/test/FakeMatrixApi.dart index 41510a7b..58a93801 100644 --- a/test/FakeMatrixApi.dart +++ b/test/FakeMatrixApi.dart @@ -309,7 +309,7 @@ class FakeMatrixApi extends MockClient { ] } }, - "/client/r0/sync?filter=%7B%22room%22:%7B%22include_leave%22:true,%22state%22:%7B%22lazy_load_members%22:false%7D%7D%7D": + "/client/r0/sync?filter=%7B%22room%22:%7B%22include_leave%22:true,%22state%22:%7B%22lazy_load_members%22:true%7D%7D%7D": (var req) => { "next_batch": Random().nextDouble().toString(), "presence": {