Skip to content

Commit

Permalink
Merge branch 'main' into karthi/cache-get-config
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-famedly authored Dec 14, 2023
2 parents db0762a + d8deaf8 commit e1b80a1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/encryption/key_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ class KeyManager {
Future<OutboundGroupSession> _createOutboundGroupSession(
String roomId) async {
await clearOrUseOutboundGroupSession(roomId, wipe: true);
await client.firstSyncReceived;
final room = client.getRoomById(roomId);
if (room == null) {
throw Exception(
Expand Down
5 changes: 3 additions & 2 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1595,9 +1595,9 @@ class Client extends MatrixApi {
);

/// 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) {
await syncFuture;
await firstSyncReceived;
}
return;
} catch (e, s) {
Expand Down Expand Up @@ -2350,6 +2350,7 @@ class Client extends MatrixApi {
Future? userDeviceKeysLoading;
Future? roomsLoading;
Future? _accountDataLoading;
Future? firstSyncReceived;

Future? get accountDataLoading => _accountDataLoading;

Expand Down
23 changes: 23 additions & 0 deletions lib/src/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,29 @@ class Room {
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
/// 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.
Expand Down
3 changes: 3 additions & 0 deletions test/room_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ void main() {
stateKey: '',
));

final heroUsers = await room.loadHeroUsers();
expect(heroUsers.length, 3);

expect(room.id, id);
expect(room.membership, membership);
expect(room.notificationCount, notificationCount);
Expand Down

0 comments on commit e1b80a1

Please sign in to comment.