Skip to content

Commit

Permalink
Merge pull request #373 from pangeachat/archive-subspaces-properly
Browse files Browse the repository at this point in the history
Archive subspaces properly
  • Loading branch information
ggurdin authored Jun 21, 2024
2 parents 24131b6 + 5a16314 commit a82cadc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
60 changes: 53 additions & 7 deletions lib/pangea/extensions/pangea_room_extension/events_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ extension EventsRoomExtension on Room {
future: () async {
final List<Room> 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();
Expand All @@ -77,6 +81,23 @@ extension EventsRoomExtension on Room {
return success.error == null;
}

Future<void> _archiveSubspace() async {
final List<Room> 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<bool> _leaveSpace(BuildContext context, Client client) async {
final confirmed = await showOkCancelAlertDialog(
useRootNavigator: false,
Expand All @@ -94,12 +115,18 @@ extension EventsRoomExtension on Room {
try {
final List<Room> 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) {
Expand All @@ -116,6 +143,25 @@ extension EventsRoomExtension on Room {
return success.error == null;
}

Future<void> _leaveSubspace() async {
final List<Room> 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<Event?> _sendPangeaEvent({
required Map<String, dynamic> content,
required String parentEventId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,13 @@ extension PangeaRoom on Room {
}) async =>
await _archiveSpace(context, client, onlyAdmin: onlyAdmin);

Future<void> archiveSubspace() async => await _archiveSubspace();

Future<bool> leaveSpace(BuildContext context, Client client) async =>
await _leaveSpace(context, client);

Future<void> leaveSubspace() async => await _leaveSubspace();

Future<Event?> sendPangeaEvent({
required Map<String, dynamic> content,
required String parentEventId,
Expand Down

0 comments on commit a82cadc

Please sign in to comment.