1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 06:49:22 +00:00

Can delete group

This commit is contained in:
Pierre HUBERT 2020-05-02 09:45:03 +02:00
parent 9646cb7a70
commit df111e393a
2 changed files with 49 additions and 1 deletions

View File

@ -238,11 +238,22 @@ class GroupsHelper {
.execWithFilesAndThrow();
/// Delete group logo
///
/// Throws in case of error
static Future<void> 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<void> 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<String, dynamic> map) {
return Group(

View File

@ -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<GroupSettingsScreen> {
sections: [
_buildGeneralSection(),
_buildAccessRestrictions(),
_buildGroupLogoArea()
_buildGroupLogoArea(),
_buildDangerZone(),
],
);
}
@ -316,4 +319,38 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
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"));
}
}
}