Archive rooms from within chat details

This commit is contained in:
ggurdin 2023-11-09 12:53:50 -05:00
parent d5a94aa823
commit df884fb7e4
2 changed files with 65 additions and 9 deletions

View file

@ -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,

View file

@ -1,6 +1,18 @@
import 'package:fluffychat/pangea/utils/error_handler.dart';
import 'package:matrix/matrix.dart';
Future<List<Room>> getChildRooms(Room space, Client client) async {
final List<Room> 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<void> archiveSpace(Room? space, Client client) async {
if (space == null) {
ErrorHandler.logError(
@ -10,12 +22,9 @@ Future<void> archiveSpace(Room? space, Client client) async {
return;
}
final List<String?> 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<Room> children = await getChildRooms(space, client);
for (final Room child in children) {
await child.leave();
}
await space.leave();
}