From 3942de32222bdfc28276c4c3db19a1128da0895d Mon Sep 17 00:00:00 2001 From: Krille Date: Wed, 31 May 2023 15:52:51 +0200 Subject: [PATCH] fix: User pills --- lib/pages/chat/events/html_message.dart | 23 ++++++++++++++++------- pubspec.lock | 4 ++-- pubspec.yaml | 4 ++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/pages/chat/events/html_message.dart b/lib/pages/chat/events/html_message.dart index 328f860a..0718b7cc 100644 --- a/lib/pages/chat/events/html_message.dart +++ b/lib/pages/chat/events/html_message.dart @@ -422,6 +422,11 @@ class RoomPillExtension extends HtmlExtension { return userId != null; } + static final _cachedUsers = {}; + + Future _fetchUser(String matrixId) async => + _cachedUsers[room.id + matrixId] ??= await room.requestUser(matrixId); + @override InlineSpan build( ExtensionContext context, @@ -433,14 +438,18 @@ class RoomPillExtension extends HtmlExtension { return TextSpan(text: context.innerHtml); } if (matrixId.sigil == '@') { - final user = room.unsafeGetUserFromMemoryOrFallback(matrixId); return WidgetSpan( - child: MatrixPill( - key: Key('user_pill_$matrixId'), - name: user.calcDisplayname(), - avatar: user.avatarUrl, - uri: href, - outerContext: this.context, + child: FutureBuilder( + future: _fetchUser(matrixId), + builder: (context, snapshot) => MatrixPill( + key: Key('user_pill_$matrixId'), + name: _cachedUsers[room.id + matrixId]?.calcDisplayname() ?? + matrixId.localpart ?? + matrixId, + avatar: _cachedUsers[room.id + matrixId]?.avatarUrl, + uri: href, + outerContext: this.context, + ), ), ); } diff --git a/pubspec.lock b/pubspec.lock index 8842c99c..702b5614 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1059,10 +1059,10 @@ packages: dependency: "direct main" description: name: matrix - sha256: "2b07709bce975d2be4dc4cd3cc1196fcd6c0397d4e250b42a498e35523fc28f3" + sha256: a1c336a1f1d8f914cd8ec1adb4cab4f062e36ccabcc1a849389c85031a73f9d2 url: "https://pub.dev" source: hosted - version: "0.20.1" + version: "0.20.4" matrix_api_lite: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c7da91a4..ca156f7e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -62,7 +62,7 @@ dependencies: keyboard_shortcuts: ^0.1.4 latlong2: ^0.8.1 linkify: ^5.0.0 - matrix: ^0.20.1 + matrix: ^0.20.4 matrix_homeserver_recommendations: ^0.3.0 native_imaging: ^0.1.0 package_info_plus: ^4.0.0 @@ -171,4 +171,4 @@ dependency_overrides: git: url: https://github.com/timsneath/wakelock.git ref: 2a9bca63a540771f241d688562351482b2cf234c - path: wakelock_windows \ No newline at end of file + path: wakelock_windows