Skip to content

Commit

Permalink
Merge pull request #1770 from famedly/krille/fix-display-invite-state…
Browse files Browse the repository at this point in the history
…-after-restart

fix: Fetch invite state after restart app
  • Loading branch information
td-famedly authored Apr 29, 2024
2 parents 83e6b2a + a821483 commit 4f60e1d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/src/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ class Room {
/// from the database, that you need to correctly calculate the displayname
/// and the avatar of the room.
Future<List<User>> loadHeroUsers() async {
// For invite rooms request own user and invitor.
if (membership == Membership.invite) {
final ownUser = await requestUser(client.userID!, requestProfile: false);
if (ownUser != null) await requestUser(ownUser.senderId);
}

var heroes = summary.mHeroes;
if (heroes == null) {
final directChatMatrixID = this.directChatMatrixID;
Expand All @@ -235,6 +241,9 @@ class Room {
/// without a name, then it will return the localized version of 'Group with Alice' instead
/// of just 'Alice' to make it different to a direct chat.
/// Empty chats will become the localized version of 'Empty Chat'.
/// Please note, that necessary room members are lazy loaded. To be sure
/// that you have the room members, call and await `Room.loadHeroUsers()`
/// before.
/// This method requires a localization class which implements [MatrixLocalizations]
String getLocalizedDisplayname([
MatrixLocalizations i18n = const MatrixDefaultLocalizations(),
Expand Down Expand Up @@ -265,10 +274,12 @@ class Room {
return isDirectChat ? result : i18n.groupWith(result);
}
if (membership == Membership.invite) {
final sender = getState(EventTypes.RoomMember, client.userID!)
?.senderFromMemoryOrFallback
.calcDisplayname(i18n: i18n);
if (sender != null) return sender;
final ownMember = unsafeGetUserFromMemoryOrFallback(client.userID!);

ownMember.senderFromMemoryOrFallback.calcDisplayname(i18n: i18n);
if (ownMember.senderId != ownMember.stateKey) {
return ownMember.senderFromMemoryOrFallback.calcDisplayname(i18n: i18n);
}
}
if (membership == Membership.leave) {
if (directChatMatrixID != null) {
Expand All @@ -287,6 +298,9 @@ class Room {
}

/// The avatar of the room if set by a participant.
/// Please note, that necessary room members are lazy loaded. To be sure
/// that you have the room members, call and await `Room.loadHeroUsers()`
/// before.
Uri? get avatar {
final avatarUrl =
getState(EventTypes.RoomAvatar)?.content.tryGet<String>('url');
Expand Down

0 comments on commit 4f60e1d

Please sign in to comment.