Merge branch 'roomlist-fix-add-onevent' into 'master'
[RoomList] Add room on event update See merge request famedly/famedlysdk!46
This commit is contained in:
commit
a3079977bb
|
@ -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 = false,
|
||||
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<Room> getRoomFromTableRow(
|
||||
Map<String, dynamic> 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"],
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -150,6 +152,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();
|
||||
}
|
||||
|
||||
|
@ -158,6 +162,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();
|
||||
|
|
Loading…
Reference in a new issue