diff --git a/lib/pages/chat_details/chat_details_view.dart b/lib/pages/chat_details/chat_details_view.dart index dc4823aaa..1667a8702 100644 --- a/lib/pages/chat_details/chat_details_view.dart +++ b/lib/pages/chat_details/chat_details_view.dart @@ -8,6 +8,7 @@ import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/class_det import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/class_invitation_buttons.dart'; import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/class_name_button.dart'; import 'package:fluffychat/pangea/pages/class_settings/p_class_widgets/room_rules_editor.dart'; +import 'package:fluffychat/pangea/utils/archive_space.dart'; import 'package:fluffychat/pangea/utils/lock_room.dart'; import 'package:fluffychat/pangea/widgets/class/add_class_and_invite.dart'; import 'package:fluffychat/pangea/widgets/class/add_space_toggles.dart'; @@ -495,12 +496,58 @@ class ChatDetailsView extends StatelessWidget { : AddToClassMode.chat, ), const Divider(height: 1), + if (!room.isSpace || (room.isSpace && room.isRoomAdmin)) + ListTile( + title: Text( + room.isSpace + ? L10n.of(context)!.archiveSpace + : L10n.of(context)!.archive, + style: TextStyle( + color: Theme.of(context).colorScheme.secondary, + fontWeight: FontWeight.bold, + ), + ), + leading: CircleAvatar( + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, + foregroundColor: iconColor, + child: const Icon( + Icons.archive_outlined, + ), + ), + onTap: () => showFutureLoadingDialog( + context: context, + future: () async { + room.isSpace + ? await archiveSpace( + room, + Matrix.of(context).client, + ) + : await room.leave(); + context.go('/rooms'); + }, + ), + ), if (room.isRoomAdmin) SwitchListTile.adaptive( activeColor: AppConfig.activeToggleColor, - title: room.isSpace - ? Text(L10n.of(context)!.lockSpace) - : Text(L10n.of(context)!.lockChat), + title: Text( + room.isSpace + ? L10n.of(context)!.lockSpace + : L10n.of(context)!.lockChat, + style: TextStyle( + color: Theme.of(context).colorScheme.secondary, + fontWeight: FontWeight.bold, + ), + ), + secondary: CircleAvatar( + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, + foregroundColor: iconColor, + child: const Icon( + Icons.lock_outlined, + ), + ), value: room.locked, onChanged: (value) => showFutureLoadingDialog( context: context, diff --git a/lib/pangea/utils/archive_space.dart b/lib/pangea/utils/archive_space.dart index 3cefe54a5..cd9ec3b01 100644 --- a/lib/pangea/utils/archive_space.dart +++ b/lib/pangea/utils/archive_space.dart @@ -1,6 +1,18 @@ import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:matrix/matrix.dart'; +Future> getChildRooms(Room space, Client client) async { + final List children = []; + for (final child in space.spaceChildren) { + if (child.roomId == null) continue; + final Room? room = client.getRoomById(child.roomId!); + if (room != null) { + children.add(room); + } + } + return children; +} + Future archiveSpace(Room? space, Client client) async { if (space == null) { ErrorHandler.logError( @@ -10,12 +22,9 @@ Future archiveSpace(Room? space, Client client) async { return; } - final List children = - space.spaceChildren.map((e) => e.roomId).where((e) => e != null).toList(); - for (final String? child in children) { - final Room? room = client.getRoomById(child!); - if (room == null) continue; - await room.leave(); + final List children = await getChildRooms(space, client); + for (final Room child in children) { + await child.leave(); } await space.leave(); }