[Room] Dynamic name generation
This commit is contained in:
parent
ee883a8e84
commit
48746641ba
|
@ -43,6 +43,9 @@ class Room {
|
||||||
/// The name of the room if set by a participant.
|
/// The name of the room if set by a participant.
|
||||||
String name;
|
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.
|
/// The topic of the room if set by a participant.
|
||||||
String topic;
|
String topic;
|
||||||
|
|
||||||
|
@ -104,6 +107,7 @@ class Room {
|
||||||
this.id,
|
this.id,
|
||||||
this.membership,
|
this.membership,
|
||||||
this.name,
|
this.name,
|
||||||
|
this.hasName,
|
||||||
this.topic,
|
this.topic,
|
||||||
this.avatar,
|
this.avatar,
|
||||||
this.notificationCount,
|
this.notificationCount,
|
||||||
|
@ -375,11 +379,14 @@ class Room {
|
||||||
/// Returns a Room from a json String which comes normally from the store.
|
/// Returns a Room from a json String which comes normally from the store.
|
||||||
static Future<Room> getRoomFromTableRow(
|
static Future<Room> getRoomFromTableRow(
|
||||||
Map<String, dynamic> row, Client matrix) async {
|
Map<String, dynamic> row, Client matrix) async {
|
||||||
|
bool newHasName = false;
|
||||||
String name = row["topic"];
|
String name = row["topic"];
|
||||||
if (name == "" && !row["canonical_alias"].isEmpty)
|
if (name == "" && !row["canonical_alias"].isEmpty)
|
||||||
name = row["canonical_alias"];
|
name = row["canonical_alias"];
|
||||||
else if (name == "")
|
else if (name == "")
|
||||||
name = await matrix.store?.getChatNameFromMemberNames(row["id"]) ?? "";
|
name = await matrix.store?.getChatNameFromMemberNames(row["id"]) ?? "";
|
||||||
|
else
|
||||||
|
newHasName = true;
|
||||||
|
|
||||||
String avatarUrl = row["avatar_url"];
|
String avatarUrl = row["avatar_url"];
|
||||||
if (avatarUrl == "")
|
if (avatarUrl == "")
|
||||||
|
@ -388,6 +395,7 @@ class Room {
|
||||||
return Room(
|
return Room(
|
||||||
id: row["id"],
|
id: row["id"],
|
||||||
name: name,
|
name: name,
|
||||||
|
hasName: newHasName,
|
||||||
membership: Membership.values
|
membership: Membership.values
|
||||||
.firstWhere((e) => e.toString() == 'Membership.' + row["membership"]),
|
.firstWhere((e) => e.toString() == 'Membership.' + row["membership"]),
|
||||||
topic: row["description"],
|
topic: row["description"],
|
||||||
|
|
|
@ -124,19 +124,7 @@ class RoomList {
|
||||||
if (rooms[j].id == eventUpdate.roomID) break;
|
if (rooms[j].id == eventUpdate.roomID) break;
|
||||||
}
|
}
|
||||||
final bool found = (j < rooms.length && rooms[j].id == eventUpdate.roomID);
|
final bool found = (j < rooms.length && rooms[j].id == eventUpdate.roomID);
|
||||||
if (!found) {
|
if (!found) return;
|
||||||
rooms.insert(
|
|
||||||
0,
|
|
||||||
Room(
|
|
||||||
id: eventUpdate.roomID,
|
|
||||||
membership: Membership.join,
|
|
||||||
name: "",
|
|
||||||
prev_batch: "",
|
|
||||||
highlightCount: 0,
|
|
||||||
notificationCount: 0));
|
|
||||||
if (onInsert != null) onInsert(0);
|
|
||||||
j = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is this an old timeline event? Then stop here...
|
// Is this an old timeline event? Then stop here...
|
||||||
/*if (eventUpdate.type == "timeline" &&
|
/*if (eventUpdate.type == "timeline" &&
|
||||||
|
@ -162,6 +150,8 @@ class RoomList {
|
||||||
// Update the room avatar
|
// Update the room avatar
|
||||||
rooms[j].avatar = MxContent(eventUpdate.content["content"]["url"]);
|
rooms[j].avatar = MxContent(eventUpdate.content["content"]["url"]);
|
||||||
}
|
}
|
||||||
|
if (eventUpdate.eventType == "m.room.member" && !rooms[j].hasName)
|
||||||
|
updateMemberName(j);
|
||||||
sortAndUpdate();
|
sortAndUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,6 +160,11 @@ class RoomList {
|
||||||
b.timeCreated.toTimeStamp().compareTo(a.timeCreated.toTimeStamp()));
|
b.timeCreated.toTimeStamp().compareTo(a.timeCreated.toTimeStamp()));
|
||||||
if (onUpdate != null) onUpdate();
|
if (onUpdate != null) onUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateMemberName(int position) async {
|
||||||
|
rooms[position].name =
|
||||||
|
await client.store.getChatNameFromMemberNames(rooms[position].id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef onRoomListUpdateCallback = void Function();
|
typedef onRoomListUpdateCallback = void Function();
|
||||||
|
|
Loading…
Reference in a new issue