fix: User pills

This commit is contained in:
Krille 2023-05-31 15:52:51 +02:00
parent b00111381a
commit 3942de3222
No known key found for this signature in database
3 changed files with 20 additions and 11 deletions

View File

@ -422,6 +422,11 @@ class RoomPillExtension extends HtmlExtension {
return userId != null; return userId != null;
} }
static final _cachedUsers = <String, User?>{};
Future<User?> _fetchUser(String matrixId) async =>
_cachedUsers[room.id + matrixId] ??= await room.requestUser(matrixId);
@override @override
InlineSpan build( InlineSpan build(
ExtensionContext context, ExtensionContext context,
@ -433,14 +438,18 @@ class RoomPillExtension extends HtmlExtension {
return TextSpan(text: context.innerHtml); return TextSpan(text: context.innerHtml);
} }
if (matrixId.sigil == '@') { if (matrixId.sigil == '@') {
final user = room.unsafeGetUserFromMemoryOrFallback(matrixId);
return WidgetSpan( return WidgetSpan(
child: MatrixPill( child: FutureBuilder<User?>(
key: Key('user_pill_$matrixId'), future: _fetchUser(matrixId),
name: user.calcDisplayname(), builder: (context, snapshot) => MatrixPill(
avatar: user.avatarUrl, key: Key('user_pill_$matrixId'),
uri: href, name: _cachedUsers[room.id + matrixId]?.calcDisplayname() ??
outerContext: this.context, matrixId.localpart ??
matrixId,
avatar: _cachedUsers[room.id + matrixId]?.avatarUrl,
uri: href,
outerContext: this.context,
),
), ),
); );
} }

View File

@ -1059,10 +1059,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: matrix name: matrix
sha256: "2b07709bce975d2be4dc4cd3cc1196fcd6c0397d4e250b42a498e35523fc28f3" sha256: a1c336a1f1d8f914cd8ec1adb4cab4f062e36ccabcc1a849389c85031a73f9d2
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.20.1" version: "0.20.4"
matrix_api_lite: matrix_api_lite:
dependency: transitive dependency: transitive
description: description:

View File

@ -62,7 +62,7 @@ dependencies:
keyboard_shortcuts: ^0.1.4 keyboard_shortcuts: ^0.1.4
latlong2: ^0.8.1 latlong2: ^0.8.1
linkify: ^5.0.0 linkify: ^5.0.0
matrix: ^0.20.1 matrix: ^0.20.4
matrix_homeserver_recommendations: ^0.3.0 matrix_homeserver_recommendations: ^0.3.0
native_imaging: ^0.1.0 native_imaging: ^0.1.0
package_info_plus: ^4.0.0 package_info_plus: ^4.0.0
@ -171,4 +171,4 @@ dependency_overrides:
git: git:
url: https://github.com/timsneath/wakelock.git url: https://github.com/timsneath/wakelock.git
ref: 2a9bca63a540771f241d688562351482b2cf234c ref: 2a9bca63a540771f241d688562351482b2cf234c
path: wakelock_windows path: wakelock_windows