From f03a1f6ad7d4a6fa4dc933880731edeb2e5a08ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Tue, 1 Sep 2026 16:08:45 +0200 Subject: [PATCH] chore: make autoRequestProfileForMissingUsers and getDisplayNameAndAvatarFromPrevContent configurable --- lib/src/client.dart | 12 ++++++++++++ lib/src/room.dart | 8 +++++--- lib/src/user.dart | 6 ++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index c5e41a6a2..9d8913903 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -128,6 +128,9 @@ class Client extends MatrixApi { final Duration sendTimelineEventTimeout; + final bool autoRequestProfileForMissingUsers; + final bool getDisplayNameAndAvatarFromPrevContent; + /// The timeout until a typing indicator gets removed automatically. final Duration typingIndicatorTimeout; @@ -243,6 +246,15 @@ class Client extends MatrixApi { this.dehydratedDeviceDisplayName = 'Dehydrated Device', RoomSorter? customRoomSorter, this.contentScannerConfig, + + /// Whether the app automatically requests the profile for users which have + /// no filled out member state in a room. This is e.g. the case for left + /// or banned users. + this.autoRequestProfileForMissingUsers = true, + + /// Whether the app should get DisplayName and Avatar also from the + /// previous content of a member state event. + this.getDisplayNameAndAvatarFromPrevContent = true, }) : _database = database, syncFilter = syncFilter ?? diff --git a/lib/src/room.dart b/lib/src/room.dart index 72dbb09c5..9631c075c 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -2145,7 +2145,7 @@ class Room { String mxID, { bool ignoreErrors = false, bool requestState = true, - bool requestProfile = true, + bool? requestProfile, }) async { assert(mxID.isValidMatrixIdStrict()); @@ -2153,7 +2153,8 @@ class Room { mxID: mxID, ignoreErrors: ignoreErrors, requestState: requestState, - requestProfile: requestProfile, + requestProfile: + requestProfile ?? client.autoRequestProfileForMissingUsers, ); final cache = _inflightUserRequests[parameters] ??= AsyncCache.ephemeral(); @@ -2164,7 +2165,8 @@ class Room { mxID, ignoreErrors: ignoreErrors, requestState: requestState, - requestProfile: requestProfile, + requestProfile: + requestProfile ?? client.autoRequestProfileForMissingUsers, ), ); _inflightUserRequests.remove(parameters); diff --git a/lib/src/user.dart b/lib/src/user.dart index 4e7918bc9..1c19a3864 100644 --- a/lib/src/user.dart +++ b/lib/src/user.dart @@ -57,7 +57,8 @@ class User extends StrippedStateEvent { /// The displayname of the user if the user has set one. String? get displayName => content.tryGet('displayname') ?? - (membership == Membership.join + (membership == Membership.join || + !room.client.getDisplayNameAndAvatarFromPrevContent ? null : prevContent?.tryGet('displayname')); @@ -80,7 +81,8 @@ class User extends StrippedStateEvent { Uri? get avatarUrl { final uri = content.tryGet('avatar_url') ?? - (membership == Membership.join + (membership == Membership.join || + !room.client.getDisplayNameAndAvatarFromPrevContent ? null : prevContent?.tryGet('avatar_url')); return uri == null ? null : Uri.tryParse(uri);