From c203071a7db3ba6f9937a06f69621f53d075d608 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Wed, 22 May 2024 16:39:32 -0400 Subject: [PATCH] removed unused delete room files --- .../p_class_widgets/delete_class_tile.dart | 149 ------------------ lib/pangea/utils/delete_room.dart | 92 ----------- 2 files changed, 241 deletions(-) delete mode 100644 lib/pangea/pages/class_settings/p_class_widgets/delete_class_tile.dart delete mode 100644 lib/pangea/utils/delete_room.dart diff --git a/lib/pangea/pages/class_settings/p_class_widgets/delete_class_tile.dart b/lib/pangea/pages/class_settings/p_class_widgets/delete_class_tile.dart deleted file mode 100644 index 7e3fc3af6..000000000 --- a/lib/pangea/pages/class_settings/p_class_widgets/delete_class_tile.dart +++ /dev/null @@ -1,149 +0,0 @@ -import 'package:flutter/material.dart'; - -import 'package:flutter_gen/gen_l10n/l10n.dart'; -import 'package:future_loading_dialog/future_loading_dialog.dart'; -import 'package:go_router/go_router.dart'; -import 'package:matrix/matrix.dart'; - -import 'package:fluffychat/pangea/utils/delete_room.dart'; -import 'package:fluffychat/widgets/matrix.dart'; - -class DeleteSpaceTile extends StatelessWidget { - final Room room; - - const DeleteSpaceTile({ - super.key, - required this.room, - }); - - @override - Widget build(BuildContext context) { - bool classNameMatch = true; - final textController = TextEditingController(); - Future deleteSpace() async { - final Client client = Matrix.of(context).client; - final GetSpaceHierarchyResponse spaceHierarchy = - await client.getSpaceHierarchy(room.id); - - if (spaceHierarchy.rooms.isNotEmpty) { - final List spaceChats = spaceHierarchy.rooms - .where((c) => c.roomId != room.id) - .map((e) => Matrix.of(context).client.getRoomById(e.roomId)) - .where((c) => c != null && !c.isSpace && !c.isDirectChat) - .cast() - .toList(); - - await Future.wait( - spaceChats.map((c) => deleteRoom(c.id, client)), - ); - } - deleteRoom(room.id, client); - context.go('/rooms'); - return; - } - - Future deleteChat() { - context.go('/rooms'); - return deleteRoom(room.id, Matrix.of(context).client); - } - - Future deleteChatAction() async { - showDialog( - context: context, - useRootNavigator: false, - builder: (context) { - return StatefulBuilder( - builder: (context, setState) { - return AlertDialog( - title: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - room.isSpace - ? L10n.of(context)!.areYouSureDeleteClass - : L10n.of(context)!.areYouSureDeleteGroup, - style: const TextStyle( - fontSize: 20, - ), - textAlign: TextAlign.center, - ), - const SizedBox(height: 5), - Text( - L10n.of(context)!.cannotBeReversed, - style: const TextStyle( - fontSize: 16, - ), - textAlign: TextAlign.center, - ), - const SizedBox(height: 10), - if (room.isSpace) - Text( - L10n.of(context)!.enterDeletedClassName, - style: const TextStyle( - fontSize: 14, - ), - textAlign: TextAlign.center, - ), - ], - ), - content: room.isSpace - ? TextField( - autofocus: true, - controller: textController, - decoration: InputDecoration( - hintText: room.name, - errorText: !classNameMatch - ? L10n.of(context)!.incorrectClassName - : null, - ), - ) - : null, - actions: [ - TextButton( - child: Text(L10n.of(context)!.ok), - onPressed: () async { - if (room.isSpace) { - setState(() { - classNameMatch = textController.text == room.name; - }); - if (classNameMatch) { - Navigator.of(context).pop(); - await showFutureLoadingDialog( - context: context, - future: () => deleteSpace(), - ); - } - } else { - await showFutureLoadingDialog( - context: context, - future: () => deleteChat(), - ); - } - }, - ), - TextButton( - child: Text(L10n.of(context)!.cancel), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - ], - ); - }, - ); - }, - ); - } - - return ListTile( - trailing: const Icon(Icons.delete_outlined), - title: Text( - room.isSpace - ? L10n.of(context)!.deleteSpace - : L10n.of(context)!.deleteGroup, - style: const TextStyle(color: Colors.red), - ), - onTap: () => deleteChatAction(), - ); - } -} diff --git a/lib/pangea/utils/delete_room.dart b/lib/pangea/utils/delete_room.dart deleted file mode 100644 index d2a0acae9..000000000 --- a/lib/pangea/utils/delete_room.dart +++ /dev/null @@ -1,92 +0,0 @@ -import 'package:fluffychat/pangea/constants/class_default_values.dart'; -import 'package:matrix/matrix.dart'; - -import 'error_handler.dart'; - -Future deleteRoom(String? roomID, Client client) async { - if (roomID == null) { - ErrorHandler.logError( - m: "in deleteRoomAction with null pangeaClassRoomID", - s: StackTrace.current, - ); - return; - } - - final Room? room = client.getRoomById(roomID); - if (room == null) { - ErrorHandler.logError( - m: "failed to fetch room with roomID $roomID", - s: StackTrace.current, - ); - return; - } - - try { - await room.join(); - } catch (err) { - ErrorHandler.logError( - m: "failed to join room with roomID $roomID", - s: StackTrace.current, - ); - return; - } - - List members; - try { - members = await room.requestParticipants(); - } catch (err) { - ErrorHandler.logError( - m: "failed to fetch members for room with roomID $roomID", - s: StackTrace.current, - ); - return; - } - - final List otherAdmins = []; - for (final User member in members) { - final String memberID = member.id; - final int memberPowerLevel = room.getPowerLevelByUserId(memberID); - if (memberID == client.userID) continue; - if (memberPowerLevel >= ClassDefaultValues.powerLevelOfAdmin) { - otherAdmins.add(member); - continue; - } - try { - await room.kick(memberID); - } catch (err) { - ErrorHandler.logError( - m: "Failed to kick user $memberID from room with id $roomID. Error: $err", - s: StackTrace.current, - ); - continue; - } - } - - if (otherAdmins.isNotEmpty && room.canSendEvent(EventTypes.RoomJoinRules)) { - try { - await client.setRoomStateWithKey( - roomID, - EventTypes.RoomJoinRules, - "", - {"join_rules": "invite"}, - ); - } catch (err) { - ErrorHandler.logError( - m: "Failed to update student create room permissions. error: $err, roomId: $roomID", - s: StackTrace.current, - ); - } - } - - try { - if (room.isUnread) { - await room.markUnread(false); - } - await room.leave(); - } catch (err) { - ErrorHandler.logError( - m: "Failed to leave room with id $roomID. Error: $err", - s: StackTrace.current, - ); - } -}