diff --git a/lib/helpers/groups_helper.dart b/lib/helpers/groups_helper.dart index c1a2550..f289e3a 100644 --- a/lib/helpers/groups_helper.dart +++ b/lib/helpers/groups_helper.dart @@ -238,11 +238,22 @@ class GroupsHelper { .execWithFilesAndThrow(); /// Delete group logo + /// + /// Throws in case of error static Future deleteLogo(int groupID) async => await APIRequest(uri: "groups/delete_logo", needLogin: true) .addInt("id", groupID) .execWithThrow(); + /// Delete a group + /// + /// Throws in case of error + static Future deleteGroup(int groupID, String password) async => + await APIRequest(uri: "groups/delete", needLogin: true) + .addInt("groupID", groupID) + .addString("password", password) + .execWithThrow(); + /// Turn an API entry into a group object Group _getGroupFromAPI(Map map) { return Group( diff --git a/lib/ui/screens/group_settings_screen.dart b/lib/ui/screens/group_settings_screen.dart index 0e99a7a..6c30254 100644 --- a/lib/ui/screens/group_settings_screen.dart +++ b/lib/ui/screens/group_settings_screen.dart @@ -3,8 +3,10 @@ import 'dart:typed_data'; import 'package:comunic/helpers/groups_helper.dart'; import 'package:comunic/models/advanced_group_info.dart'; import 'package:comunic/models/group.dart'; +import 'package:comunic/ui/dialogs/input_user_password_dialog.dart'; import 'package:comunic/ui/dialogs/multi_choices_dialog.dart'; import 'package:comunic/ui/dialogs/virtual_directory_dialog.dart'; +import 'package:comunic/ui/routes/main_route.dart'; import 'package:comunic/ui/widgets/async_screen_widget.dart'; import 'package:comunic/ui/widgets/comunic_back_button_widget.dart'; import 'package:comunic/ui/widgets/group_icon_widget.dart'; @@ -81,7 +83,8 @@ class _GroupSettingsScreenState extends SafeState { sections: [ _buildGeneralSection(), _buildAccessRestrictions(), - _buildGroupLogoArea() + _buildGroupLogoArea(), + _buildDangerZone(), ], ); } @@ -316,4 +319,38 @@ class _GroupSettingsScreenState extends SafeState { showSimpleSnack(context, tr("Could not delete group logo!")); } } + + Widget _buildDangerZone() { + return SettingsSection( + title: tr("Danger zone"), + tiles: [ + SettingsTile( + title: tr("Delete group"), + onTap: _deleteGroup, + ), + ], + ); + } + + /// Delete the group + void _deleteGroup() async { + try { + final password = await showUserPasswordDialog(context); + + if (password == null) return; + + if (!await showConfirmDialog( + context: context, + message: tr( + "Do you really want to delete this group ? All the posts related to it will be permanently deleted!"))) + return; + + await GroupsHelper.deleteGroup(_groupSettings.id, password); + + MainController.of(context).popPage(); + } catch (e, s) { + print("Could not delete the group! $e\n$s"); + showSimpleSnack(context, tr("Could not delete the group")); + } + } }