From c95f4acecd2b4064bd194e601efaf82fed190930 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 26 Jul 2019 14:00:12 +0200 Subject: [PATCH 1/7] [ContactList] Add functions --- lib/src/Client.dart | 12 ++++++++++++ lib/src/Store.dart | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/src/Client.dart b/lib/src/Client.dart index 9698c46e..d505f1a1 100644 --- a/lib/src/Client.dart +++ b/lib/src/Client.dart @@ -219,6 +219,18 @@ class Client { type: HTTPType.POST, action: "/client/r0/join/$id"); } + /// Loads the contact list for this user excluding the users in + /// the given room of id [exceptRoomID] and 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({String exceptRoomID = ""}) 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/Store.dart b/lib/src/Store.dart index df628a68..1ddbd868 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 = ""; From 8664954f274726897638773d92b1d231fc0767d8 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 26 Jul 2019 14:46:23 +0200 Subject: [PATCH 2/7] [ContactList] Define contact list by discoveryRoom --- lib/src/Client.dart | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/src/Client.dart b/lib/src/Client.dart index d505f1a1..38fdc14e 100644 --- a/lib/src/Client.dart +++ b/lib/src/Client.dart @@ -219,15 +219,14 @@ class Client { type: HTTPType.POST, action: "/client/r0/join/$id"); } - /// Loads the contact list for this user excluding the users in - /// the given room of id [exceptRoomID] and the user itself. Currently the contacts are - /// found by discovering the contacts of the famedlyContactDiscovery room, which is + /// 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({String exceptRoomID = ""}) async { + Future> loadFamedlyContacts() async { Room contactDiscoveryRoom = await store .getRoomByAlias("#famedlyContactDiscovery:${userID.split(":")[1]}"); List contacts = await contactDiscoveryRoom.requestParticipants(); - return contacts; } From d3349682199622272d9068bbf4bedceea4308aab Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 26 Jul 2019 14:46:50 +0200 Subject: [PATCH 3/7] [Connection] Reenable lazy loading --- lib/src/Connection.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From fa88a5b2d4daa8d76956db1263b18907acac6352 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 26 Jul 2019 14:55:17 +0200 Subject: [PATCH 4/7] [Store] Better directchat query --- lib/src/Store.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/Store.dart b/lib/src/Store.dart index 1ddbd868..a307e712 100644 --- a/lib/src/Store.dart +++ b/lib/src/Store.dart @@ -601,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=? WHERE membership='join' LIMIT 1", + [userID]); if (res.length != 1) return null; return res[0]["id"]; } From ffd4eb508ee25f11b697548bc4b1f757932bb456 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 26 Jul 2019 14:57:12 +0200 Subject: [PATCH 5/7] [Store] Fix query --- lib/src/Store.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/Store.dart b/lib/src/Store.dart index a307e712..8d00b25e 100644 --- a/lib/src/Store.dart +++ b/lib/src/Store.dart @@ -601,7 +601,7 @@ 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=? WHERE membership='join' LIMIT 1", + "SELECT id FROM Rooms WHERE direct_chat_matrix_id=? AND membership='join' LIMIT 1", [userID]); if (res.length != 1) return null; return res[0]["id"]; From a97e96bf7244ff6319134ed27bddf62aa2b12028 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 26 Jul 2019 14:57:56 +0200 Subject: [PATCH 6/7] [Store] Include invite --- lib/src/Store.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/Store.dart b/lib/src/Store.dart index 8d00b25e..45b3a28d 100644 --- a/lib/src/Store.dart +++ b/lib/src/Store.dart @@ -601,7 +601,7 @@ 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=? AND membership='join' LIMIT 1", + "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"]; From 01d6b511ca2d92c339e2b3bd9eab216aba12ff0b Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 26 Jul 2019 15:05:46 +0200 Subject: [PATCH 7/7] [Tests] Fix tests --- pubspec.lock | 4 ++-- test/FakeMatrixApi.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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": {