title property
override
Text representing the title of this chat.
Implementation
@override
String get title {
// [RxUser]s taking part in the [title] formation.
//
// Used to subscribe to the [RxUser.updates] to keep these [users]
// up-to-date.
final List<RxUser> users = [];
switch (chat.value.kind) {
case ChatKind.dialog:
final RxUser? rxUser =
members.values.firstWhereOrNull((u) => u.user.id != me)?.user;
if (rxUser != null) {
users.add(rxUser);
}
break;
case ChatKind.group:
if (chat.value.name == null) {
users.addAll(members.values.take(3).map((e) => e.user));
}
break;
case ChatKind.monolog:
case ChatKind.artemisUnknown:
// No-op.
break;
}
_userSubscriptions.removeWhere((k, v) {
if (users.none((u) => u.id == k)) {
v.cancel();
return true;
}
return false;
});
for (final e in users) {
if (_userSubscriptions[e.id] == null) {
_userSubscriptions[e.id] = e.updates.listen((_) {});
}
}
return chat.value.getTitle(users, me);
}