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;
}
static final _cachedUsers = <String, User?>{};
Future<User?> _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<User?>(
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,
),
),
);
}

View File

@ -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:

View File

@ -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
path: wakelock_windows