Merge branch 'main' into karthi/cache-get-config

This commit is contained in:
Nicolas Werner 2023-12-14 16:33:50 +01:00 committed by GitHub
commit e1b80a1f3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 2 deletions

View File

@ -502,6 +502,7 @@ class KeyManager {
Future<OutboundGroupSession> _createOutboundGroupSession( Future<OutboundGroupSession> _createOutboundGroupSession(
String roomId) async { String roomId) async {
await clearOrUseOutboundGroupSession(roomId, wipe: true); await clearOrUseOutboundGroupSession(roomId, wipe: true);
await client.firstSyncReceived;
final room = client.getRoomById(roomId); final room = client.getRoomById(roomId);
if (room == null) { if (room == null) {
throw Exception( throw Exception(

View File

@ -1595,9 +1595,9 @@ class Client extends MatrixApi {
); );
/// Timeout of 0, so that we don't see a spinner for 30 seconds. /// Timeout of 0, so that we don't see a spinner for 30 seconds.
final syncFuture = _sync(timeout: Duration.zero); firstSyncReceived = _sync(timeout: Duration.zero);
if (waitForFirstSync) { if (waitForFirstSync) {
await syncFuture; await firstSyncReceived;
} }
return; return;
} catch (e, s) { } catch (e, s) {
@ -2350,6 +2350,7 @@ class Client extends MatrixApi {
Future? userDeviceKeysLoading; Future? userDeviceKeysLoading;
Future? roomsLoading; Future? roomsLoading;
Future? _accountDataLoading; Future? _accountDataLoading;
Future? firstSyncReceived;
Future? get accountDataLoading => _accountDataLoading; Future? get accountDataLoading => _accountDataLoading;

View File

@ -223,6 +223,29 @@ class Room {
return pinned is Iterable ? pinned.map((e) => e.toString()).toList() : []; return pinned is Iterable ? pinned.map((e) => e.toString()).toList() : [];
} }
/// Returns the heroes as `User` objects.
/// This is very useful if you want to make sure that all users are loaded
/// from the database, that you need to correctly calculate the displayname
/// and the avatar of the room.
Future<List<User>> loadHeroUsers() async {
var heroes = summary.mHeroes;
if (heroes == null) {
final directChatMatrixID = this.directChatMatrixID;
if (directChatMatrixID != null) {
heroes = [directChatMatrixID];
}
}
if (heroes == null) return [];
return await Future.wait(heroes.map((hero) async =>
(await requestUser(
hero,
ignoreErrors: true,
)) ??
User(hero, room: this)));
}
/// Returns a localized displayname for this server. If the room is a groupchat /// Returns a localized displayname for this server. If the room is a groupchat
/// without a name, then it will return the localized version of 'Group with Alice' instead /// 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. /// of just 'Alice' to make it different to a direct chat.

View File

@ -81,6 +81,9 @@ void main() {
stateKey: '', stateKey: '',
)); ));
final heroUsers = await room.loadHeroUsers();
expect(heroUsers.length, 3);
expect(room.id, id); expect(room.id, id);
expect(room.membership, membership); expect(room.membership, membership);
expect(room.notificationCount, notificationCount); expect(room.notificationCount, notificationCount);