Skip to content

Commit

Permalink
Merge pull request #2375 from acterglobal/ben-minor-fixing
Browse files Browse the repository at this point in the history
Fixing 404 on room join
  • Loading branch information
gnunicorn authored Nov 18, 2024
2 parents 7918dbe + 6d3c5fd commit f522f3a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
33 changes: 30 additions & 3 deletions app/lib/features/room/actions/join_room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ import 'package:logging/logging.dart';

final _log = Logger('a3::room::join');

Future<T> _ensureLoadedWithinTime<T>(
Future<T?> Function() callback, {
int delayMs = 300,
int attempts = 20,
}) async {
int remaining = attempts;
while (remaining > 0) {
remaining -= 1;
final res = await callback();
if (res != null) {
return res;
}
await Future.delayed(Duration(milliseconds: delayMs));
}

throw 'Loading timed out';
}

Future<String?> joinRoom(
BuildContext context,
WidgetRef ref,
Expand All @@ -24,13 +42,22 @@ Future<String?> joinRoom(
try {
final newRoom = await client.joinRoom(roomIdOrAlias, server);
final roomId = newRoom.roomIdStr();
final isSpace = newRoom.isSpace();
// ensure we re-evaluate the room data on our end. This is necessary
// if we knew of the room prior (e.g. we had left it), but hadn’t joined
// this should properly re-evaluate all possible readers
ref.invalidate(maybeRoomProvider(roomId));
ref.invalidate(chatProvider(roomId));
ref.invalidate(spaceProvider(roomId));
await client.waitForRoom(roomId, 5);
if (isSpace) {
ref.invalidate(spaceProvider(roomId));
await _ensureLoadedWithinTime(
() async => await ref.read(maybeSpaceProvider(roomId).future),
);
} else {
ref.invalidate(chatProvider(roomId));
}
await _ensureLoadedWithinTime(
() async => await ref.read(chatProvider(roomId).future),
);
EasyLoading.dismiss();
if (forward != null) forward(roomId);
return roomId;
Expand Down
1 change: 1 addition & 0 deletions packages/acter_notifify/lib/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Future<void> removeNotificationsForRoom(String roomId) async {
}

Future<void> updateBadgeCount(int newCount) async {
if (Platform.isLinux) return; // not supported
if (await AppBadgePlus.isSupported()) {
await AppBadgePlus.updateBadge(0);
// await AppBadgePlus.updateBadge(newCount);
Expand Down

0 comments on commit f522f3a

Please sign in to comment.