fix: leaved direct chat name
This commit is contained in:
parent
90e8d5b118
commit
52d6b59cc1
|
|
@ -59,6 +59,7 @@ const String fileSendingStatusKey =
|
||||||
'com.famedly.famedlysdk.file_sending_status';
|
'com.famedly.famedlysdk.file_sending_status';
|
||||||
|
|
||||||
const String sortOrderKey = 'com.famedly.famedlysdk.sort_order';
|
const String sortOrderKey = 'com.famedly.famedlysdk.sort_order';
|
||||||
|
const String emptyRoomName = 'Empty chat';
|
||||||
|
|
||||||
/// Represents a Matrix room.
|
/// Represents a Matrix room.
|
||||||
class Room {
|
class Room {
|
||||||
|
|
@ -240,6 +241,20 @@ class Room {
|
||||||
return i18n.groupWith(displayname);
|
return i18n.groupWith(displayname);
|
||||||
}
|
}
|
||||||
if (displayname.isNotEmpty) {
|
if (displayname.isNotEmpty) {
|
||||||
|
if (directChatMatrixID != null) {
|
||||||
|
final displayName =
|
||||||
|
unsafeGetUserFromMemoryOrFallback(directChatMatrixID!)
|
||||||
|
.calcDisplayname();
|
||||||
|
final dmPartnerMembership =
|
||||||
|
getState(EventTypes.RoomMember, directChatMatrixID!)
|
||||||
|
?.asUser
|
||||||
|
.membership;
|
||||||
|
if (dmPartnerMembership == null ||
|
||||||
|
dmPartnerMembership == Membership.leave) {
|
||||||
|
return i18n.wasDirectChatDisplayName(displayName);
|
||||||
|
}
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
return displayname;
|
return displayname;
|
||||||
}
|
}
|
||||||
return i18n.emptyChat;
|
return i18n.emptyChat;
|
||||||
|
|
@ -406,19 +421,35 @@ class Room {
|
||||||
if (canonicalAlias != null && canonicalAlias.isNotEmpty) {
|
if (canonicalAlias != null && canonicalAlias.isNotEmpty) {
|
||||||
return canonicalAlias;
|
return canonicalAlias;
|
||||||
}
|
}
|
||||||
|
|
||||||
final heroes = summary.mHeroes;
|
final heroes = summary.mHeroes;
|
||||||
if (heroes != null && heroes.isNotEmpty) {
|
if (heroes != null && heroes.isNotEmpty) {
|
||||||
return heroes
|
final result = heroes
|
||||||
.where((hero) => hero.isNotEmpty)
|
.where((hero) => hero.isNotEmpty)
|
||||||
.map((hero) =>
|
.map((hero) =>
|
||||||
unsafeGetUserFromMemoryOrFallback(hero).calcDisplayname())
|
unsafeGetUserFromMemoryOrFallback(hero).calcDisplayname())
|
||||||
.join(', ');
|
.join(', ');
|
||||||
|
if (directChatMatrixID != null) {
|
||||||
|
final dmPartnerMembership = getState(
|
||||||
|
EventTypes.RoomMember,
|
||||||
|
directChatMatrixID!,
|
||||||
|
)?.asUser.membership;
|
||||||
|
if (dmPartnerMembership == null ||
|
||||||
|
dmPartnerMembership == Membership.leave) {
|
||||||
|
return leavedDirectChatName(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isDirectChat) {
|
if (isDirectChat) {
|
||||||
final user = directChatMatrixID;
|
final user = directChatMatrixID;
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
return unsafeGetUserFromMemoryOrFallback(user).calcDisplayname();
|
final displayName =
|
||||||
|
unsafeGetUserFromMemoryOrFallback(user).calcDisplayname();
|
||||||
|
return membership == Membership.leave
|
||||||
|
? leavedDirectChatName(displayName)
|
||||||
|
: displayName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (membership == Membership.invite) {
|
if (membership == Membership.invite) {
|
||||||
|
|
@ -427,7 +458,20 @@ class Room {
|
||||||
.calcDisplayname();
|
.calcDisplayname();
|
||||||
if (sender != null) return sender;
|
if (sender != null) return sender;
|
||||||
}
|
}
|
||||||
return 'Empty chat';
|
if (membership == Membership.leave) {
|
||||||
|
final invitation = getState(EventTypes.RoomMember, client.userID!);
|
||||||
|
if (invitation != null && invitation.unsigned?['prev_sender'] != null) {
|
||||||
|
final name = unsafeGetUserFromMemoryOrFallback(
|
||||||
|
invitation.unsigned?['prev_sender'])
|
||||||
|
.calcDisplayname();
|
||||||
|
return leavedDirectChatName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return emptyRoomName;
|
||||||
|
}
|
||||||
|
|
||||||
|
String leavedDirectChatName(String prevName) {
|
||||||
|
return '$emptyRoomName (was $prevName)';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// When the last message received.
|
/// When the last message received.
|
||||||
|
|
@ -1080,7 +1124,6 @@ class Room {
|
||||||
/// Call the Matrix API to leave this room. If this room is set as a direct
|
/// Call the Matrix API to leave this room. If this room is set as a direct
|
||||||
/// chat, this will be removed too.
|
/// chat, this will be removed too.
|
||||||
Future<void> leave() async {
|
Future<void> leave() async {
|
||||||
if (directChatMatrixID != '') await removeFromDirectChat();
|
|
||||||
try {
|
try {
|
||||||
await client.leaveRoom(id);
|
await client.leaveRoom(id);
|
||||||
} on MatrixException catch (exception) {
|
} on MatrixException catch (exception) {
|
||||||
|
|
|
||||||
|
|
@ -265,4 +265,8 @@ class MatrixDefaultLocalizations extends MatrixLocalizations {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String youUnbannedUser(String targetName) => 'You unbanned $targetName';
|
String youUnbannedUser(String targetName) => 'You unbanned $targetName';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String wasDirectChatDisplayName(String oldDisplayName) =>
|
||||||
|
'Empty chat (was $oldDisplayName)';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,8 @@ abstract class MatrixLocalizations {
|
||||||
String answeredTheCall(String senderName);
|
String answeredTheCall(String senderName);
|
||||||
|
|
||||||
String sentCallInformations(String senderName);
|
String sentCallInformations(String senderName);
|
||||||
|
|
||||||
|
String wasDirectChatDisplayName(String oldDisplayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
extension HistoryVisibilityDisplayString on HistoryVisibility {
|
extension HistoryVisibilityDisplayString on HistoryVisibility {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue