From 43628427c1e0fae1aab58663a974c126657d5fbc Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Thu, 26 Feb 2026 13:24:34 -0500 Subject: [PATCH] fix: auto-accept invite resulting from knocks on app launch (#5824) --- lib/pages/chat_list/chat_list.dart | 62 ++++++++++++++++++------------ 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/lib/pages/chat_list/chat_list.dart b/lib/pages/chat_list/chat_list.dart index e91ac526a..5fe3319fa 100644 --- a/lib/pages/chat_list/chat_list.dart +++ b/lib/pages/chat_list/chat_list.dart @@ -557,26 +557,9 @@ class ChatListController extends State inviteEntry.key, ); - if (isSpace) { - final spaceId = inviteEntry.key; - final space = Matrix.of(context).client.getRoomById(spaceId); - - if (space?.classCode?.toLowerCase() == - SpaceCodeRepo.recentCode?.toLowerCase()) { - return; - } - - if (space != null) { - chatListHandleSpaceTap(context, space); - } - } - + final room = Matrix.of(context).client.getRoomById(inviteEntry.key); + if (room == null) continue; if (isAnalytics || hasKnocked) { - final room = Matrix.of( - context, - ).client.getRoomById(inviteEntry.key); - if (room == null) return; - try { await room.joinKnockedRoom(); } catch (err, s) { @@ -587,7 +570,12 @@ class ChatListController extends State data: {"roomId": room.id}, ); } - return; + } else if (isSpace) { + if (room.classCode?.toLowerCase() == + SpaceCodeRepo.recentCode?.toLowerCase()) { + continue; + } + chatListHandleSpaceTap(context, room); } } }); @@ -639,7 +627,7 @@ class ChatListController extends State }); WidgetsBinding.instance.addPostFrameCallback((_) { - _joinInvitedSpaces(); + _joinInvitedRooms(); }); // Pangea# @@ -651,12 +639,36 @@ class ChatListController extends State if (mounted) showSubscribedSnackbar(context); } - Future _joinInvitedSpaces() async { - final invitedSpaces = Matrix.of( + Future _joinInvitedRooms() async { + final invitedRooms = Matrix.of( context, - ).client.rooms.where((r) => r.isSpace && r.membership == Membership.invite); + ).client.rooms.where((r) => r.membership == Membership.invite); - for (final space in invitedSpaces) { + final spaces = []; + for (final room in invitedRooms) { + final hasKnocked = KnockTracker.hasKnocked( + Matrix.of(context).client, + room.id, + ); + + if (hasKnocked || room.isAnalyticsRoom) { + try { + await room.joinKnockedRoom(); + } catch (err, s) { + ErrorHandler.logError( + m: "Failed to join knocked room", + e: err, + s: s, + data: {"roomId": room.id}, + ); + } + return; + } + + if (room.isSpace) spaces.add(room); + } + + for (final space in spaces) { await showInviteDialog(space, context); } }