From 3e8b54d9f05e195c3dea0a4a78657855839627a8 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 23 Jul 2019 14:42:33 +0200 Subject: [PATCH 1/5] [RoomList] Add room on event update --- lib/src/RoomList.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/RoomList.dart b/lib/src/RoomList.dart index f0a10603..f03da4f4 100644 --- a/lib/src/RoomList.dart +++ b/lib/src/RoomList.dart @@ -124,7 +124,11 @@ class RoomList { if (rooms[j].id == eventUpdate.roomID) break; } final bool found = (j < rooms.length && rooms[j].id == eventUpdate.roomID); - if (!found) return; + if (!found) { + rooms.insert(0, Room(id: eventUpdate.roomID)); + if (onInsert != null) onInsert(0); + j = 0; + } // Is this an old timeline event? Then stop here... /*if (eventUpdate.type == "timeline" && From ee883a8e84db476810edec34c07b11b3b449ed00 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 23 Jul 2019 14:50:09 +0200 Subject: [PATCH 2/5] [RoomList] Fix empty room --- lib/src/RoomList.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/src/RoomList.dart b/lib/src/RoomList.dart index f03da4f4..2e766132 100644 --- a/lib/src/RoomList.dart +++ b/lib/src/RoomList.dart @@ -125,7 +125,15 @@ class RoomList { } final bool found = (j < rooms.length && rooms[j].id == eventUpdate.roomID); if (!found) { - rooms.insert(0, Room(id: eventUpdate.roomID)); + rooms.insert( + 0, + Room( + id: eventUpdate.roomID, + membership: Membership.join, + name: "", + prev_batch: "", + highlightCount: 0, + notificationCount: 0)); if (onInsert != null) onInsert(0); j = 0; } From 48746641ba86d7851c0d8d67b974afe34933b3e7 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 23 Jul 2019 15:03:16 +0200 Subject: [PATCH 3/5] [Room] Dynamic name generation --- lib/src/Room.dart | 8 ++++++++ lib/src/RoomList.dart | 21 ++++++++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/src/Room.dart b/lib/src/Room.dart index fc286899..eaa9d012 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -43,6 +43,9 @@ class Room { /// The name of the room if set by a participant. String name; + /// Whether this room has a name or the name is generated by member names. + bool hasName = false; + /// The topic of the room if set by a participant. String topic; @@ -104,6 +107,7 @@ class Room { this.id, this.membership, this.name, + this.hasName, this.topic, this.avatar, this.notificationCount, @@ -375,11 +379,14 @@ class Room { /// Returns a Room from a json String which comes normally from the store. static Future getRoomFromTableRow( Map row, Client matrix) async { + bool newHasName = false; String name = row["topic"]; if (name == "" && !row["canonical_alias"].isEmpty) name = row["canonical_alias"]; else if (name == "") name = await matrix.store?.getChatNameFromMemberNames(row["id"]) ?? ""; + else + newHasName = true; String avatarUrl = row["avatar_url"]; if (avatarUrl == "") @@ -388,6 +395,7 @@ class Room { return Room( id: row["id"], name: name, + hasName: newHasName, membership: Membership.values .firstWhere((e) => e.toString() == 'Membership.' + row["membership"]), topic: row["description"], diff --git a/lib/src/RoomList.dart b/lib/src/RoomList.dart index 2e766132..0fa71468 100644 --- a/lib/src/RoomList.dart +++ b/lib/src/RoomList.dart @@ -124,19 +124,7 @@ class RoomList { if (rooms[j].id == eventUpdate.roomID) break; } final bool found = (j < rooms.length && rooms[j].id == eventUpdate.roomID); - if (!found) { - rooms.insert( - 0, - Room( - id: eventUpdate.roomID, - membership: Membership.join, - name: "", - prev_batch: "", - highlightCount: 0, - notificationCount: 0)); - if (onInsert != null) onInsert(0); - j = 0; - } + if (!found) return; // Is this an old timeline event? Then stop here... /*if (eventUpdate.type == "timeline" && @@ -162,6 +150,8 @@ class RoomList { // Update the room avatar rooms[j].avatar = MxContent(eventUpdate.content["content"]["url"]); } + if (eventUpdate.eventType == "m.room.member" && !rooms[j].hasName) + updateMemberName(j); sortAndUpdate(); } @@ -170,6 +160,11 @@ class RoomList { b.timeCreated.toTimeStamp().compareTo(a.timeCreated.toTimeStamp())); if (onUpdate != null) onUpdate(); } + + void updateMemberName(int position) async { + rooms[position].name = + await client.store.getChatNameFromMemberNames(rooms[position].id); + } } typedef onRoomListUpdateCallback = void Function(); From a38d43b167d0f48aa3151b090c8d0612602e7c14 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 23 Jul 2019 15:07:31 +0200 Subject: [PATCH 4/5] [Room] hasName false by default --- lib/src/Room.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/Room.dart b/lib/src/Room.dart index eaa9d012..fd6a007e 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -107,7 +107,7 @@ class Room { this.id, this.membership, this.name, - this.hasName, + this.hasName = false, this.topic, this.avatar, this.notificationCount, From a43f5048dbccd375f7f5e9ffa3f133ce3bf4ad73 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 23 Jul 2019 15:10:38 +0200 Subject: [PATCH 5/5] [RoomList] Set hasName to false --- lib/src/RoomList.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/src/RoomList.dart b/lib/src/RoomList.dart index 0fa71468..b1544aae 100644 --- a/lib/src/RoomList.dart +++ b/lib/src/RoomList.dart @@ -86,12 +86,14 @@ class RoomList { num position = chatUpdate.membership == Membership.invite ? 0 : j; // Add the new chat to the list Room newRoom = Room( - id: chatUpdate.id, - name: "", - membership: chatUpdate.membership, - prev_batch: chatUpdate.prev_batch, - highlightCount: chatUpdate.highlight_count, - notificationCount: chatUpdate.notification_count); + id: chatUpdate.id, + name: "", + membership: chatUpdate.membership, + prev_batch: chatUpdate.prev_batch, + highlightCount: chatUpdate.highlight_count, + notificationCount: chatUpdate.notification_count, + hasName: false, + ); rooms.insert(position, newRoom); if (onInsert != null) onInsert(position); }