refactor: Better avatar and names for invites
Group chats with no user avatar should return null for the room.avatar getter and not a random hero avatar. This could otherwise lead to confusion as it looks like this is a DM which is not the case. For the name we should also not just display the name of the invitor like in a DM even for group chats, but some more additional information. I found a String for invites quite useful here as this would name rooms without a m.room.name like this: "Invited by $senderName" which should be short enough. The alternative "You have been invited by $senderName" could be too long IMO.
This commit is contained in:
parent
0ac0ef63ed
commit
2e51b450bf
|
|
@ -263,11 +263,11 @@ class Room {
|
|||
if (membership == Membership.invite) {
|
||||
final ownMember = unsafeGetUserFromMemoryOrFallback(client.userID!);
|
||||
|
||||
unsafeGetUserFromMemoryOrFallback(ownMember.senderId)
|
||||
.calcDisplayname(i18n: i18n);
|
||||
if (ownMember.senderId != ownMember.stateKey) {
|
||||
return unsafeGetUserFromMemoryOrFallback(ownMember.senderId)
|
||||
.calcDisplayname(i18n: i18n);
|
||||
return i18n.invitedBy(
|
||||
unsafeGetUserFromMemoryOrFallback(ownMember.senderId)
|
||||
.calcDisplayname(i18n: i18n),
|
||||
);
|
||||
}
|
||||
}
|
||||
if (membership == Membership.leave) {
|
||||
|
|
@ -291,25 +291,19 @@ class Room {
|
|||
/// that you have the room members, call and await `Room.loadHeroUsers()`
|
||||
/// before.
|
||||
Uri? get avatar {
|
||||
// Check content of `m.room.avatar`
|
||||
final avatarUrl =
|
||||
getState(EventTypes.RoomAvatar)?.content.tryGet<String>('url');
|
||||
if (avatarUrl != null) {
|
||||
return Uri.tryParse(avatarUrl);
|
||||
}
|
||||
|
||||
final heroes = summary.mHeroes;
|
||||
if (heroes != null && heroes.length == 1) {
|
||||
final hero = getState(EventTypes.RoomMember, heroes.first);
|
||||
if (hero != null) {
|
||||
return hero.asUser(this).avatarUrl;
|
||||
}
|
||||
}
|
||||
if (isDirectChat) {
|
||||
final user = directChatMatrixID;
|
||||
if (user != null) {
|
||||
return unsafeGetUserFromMemoryOrFallback(user).avatarUrl;
|
||||
}
|
||||
// Room has no avatar and is not a direct chat
|
||||
final directChatMatrixID = this.directChatMatrixID;
|
||||
if (directChatMatrixID != null) {
|
||||
return unsafeGetUserFromMemoryOrFallback(directChatMatrixID).avatarUrl;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -248,6 +248,9 @@ class MatrixDefaultLocalizations extends MatrixLocalizations {
|
|||
String youInvitedBy(String senderName) =>
|
||||
'You have been invited by $senderName';
|
||||
|
||||
@override
|
||||
String invitedBy(String senderName) => 'Invited by $senderName';
|
||||
|
||||
@override
|
||||
String youInvitedUser(String targetName) => 'You invited $targetName';
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ abstract class MatrixLocalizations {
|
|||
|
||||
String youInvitedBy(String senderName);
|
||||
|
||||
String invitedBy(String senderName);
|
||||
|
||||
String youInvitedUser(String targetName);
|
||||
|
||||
String youUnbannedUser(String targetName);
|
||||
|
|
|
|||
Loading…
Reference in New Issue