diff --git a/lib/pangea/extensions/pangea_room_extension/events_extension.dart b/lib/pangea/extensions/pangea_room_extension/events_extension.dart index f878bc3cbf..2d67db5b29 100644 --- a/lib/pangea/extensions/pangea_room_extension/events_extension.dart +++ b/lib/pangea/extensions/pangea_room_extension/events_extension.dart @@ -60,11 +60,15 @@ extension EventsRoomExtension on Room { future: () async { final List children = await getChildRooms(); for (final Room child in children) { - if (!child.isAnalyticsRoom) { + if (!child.isAnalyticsRoom && !child.isArchived) { if (child.membership != Membership.join) { child.join; } - await child.archive(); + if (child.isSpace) { + await child.archiveSubspace(); + } else { + await child.archive(); + } } } await _archive(); @@ -77,6 +81,23 @@ extension EventsRoomExtension on Room { return success.error == null; } + Future _archiveSubspace() async { + final List children = await getChildRooms(); + for (final Room child in children) { + if (!child.isAnalyticsRoom && !child.isArchived) { + if (child.membership != Membership.join) { + child.join; + } + if (child.isSpace) { + await child.archiveSubspace(); + } else { + await child.archive(); + } + } + } + await _archive(); + } + Future _leaveSpace(BuildContext context, Client client) async { final confirmed = await showOkCancelAlertDialog( useRootNavigator: false, @@ -94,12 +115,18 @@ extension EventsRoomExtension on Room { try { final List children = await getChildRooms(); for (final Room child in children) { - if (!child.isSpace && - child.membership == Membership.join && - child.isUnread) { - await child.markUnread(false); + if (!child.isAnalyticsRoom && !child.isArchived) { + if (!child.isSpace && + child.membership == Membership.join && + child.isUnread) { + await child.markUnread(false); + } + if (child.isSpace) { + await child.leaveSubspace(); + } else { + await child.leave(); + } } - await child.leave(); } await leave(); } catch (err, stack) { @@ -116,6 +143,25 @@ extension EventsRoomExtension on Room { return success.error == null; } + Future _leaveSubspace() async { + final List children = await getChildRooms(); + for (final Room child in children) { + if (!child.isAnalyticsRoom && !child.isArchived) { + if (!child.isSpace && + child.membership == Membership.join && + child.isUnread) { + await child.markUnread(false); + } + if (child.isSpace) { + await child.leaveSubspace(); + } else { + await child.leave(); + } + } + } + await leave(); + } + Future _sendPangeaEvent({ required Map content, required String parentEventId, diff --git a/lib/pangea/extensions/pangea_room_extension/pangea_room_extension.dart b/lib/pangea/extensions/pangea_room_extension/pangea_room_extension.dart index 25694901c8..570cbebbae 100644 --- a/lib/pangea/extensions/pangea_room_extension/pangea_room_extension.dart +++ b/lib/pangea/extensions/pangea_room_extension/pangea_room_extension.dart @@ -152,9 +152,13 @@ extension PangeaRoom on Room { }) async => await _archiveSpace(context, client, onlyAdmin: onlyAdmin); + Future archiveSubspace() async => await _archiveSubspace(); + Future leaveSpace(BuildContext context, Client client) async => await _leaveSpace(context, client); + Future leaveSubspace() async => await _leaveSubspace(); + Future sendPangeaEvent({ required Map content, required String parentEventId,