waitForRoomInSync method

Future<SyncUpdate> waitForRoomInSync(
  1. String roomId, {
  2. bool join = false,
  3. bool invite = false,
  4. bool leave = false,
})

Wait for the room to appear into the enabled section of the room sync. By default, the function will listen for room in invite, join and leave sections of the sync.

Implementation

Future<SyncUpdate> waitForRoomInSync(String roomId,
    {bool join = false, bool invite = false, bool leave = false}) async {
  if (!join && !invite && !leave) {
    join = true;
    invite = true;
    leave = true;
  }

  return await onSync.stream.firstWhere((sync) =>
      invite && (sync.rooms?.invite?.containsKey(roomId) ?? false) ||
      join && (sync.rooms?.join?.containsKey(roomId) ?? false) ||
      leave && (sync.rooms?.leave?.containsKey(roomId) ?? false));
}