mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Can remove membership
This commit is contained in:
parent
4bedbc4b25
commit
d0bafd5bd9
@ -100,6 +100,13 @@ class GroupsHelper {
|
||||
.map((f) => cast<int>(f))
|
||||
.toSet();
|
||||
|
||||
/// Remove group membership
|
||||
Future<bool> removeMembership(int groupID) async =>
|
||||
(await (APIRequest(uri: "groups/remove_membership", needLogin: true)
|
||||
..addInt("id", groupID))
|
||||
.exec())
|
||||
.isOK;
|
||||
|
||||
/// Turn an API entry into a group object
|
||||
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
||||
return Group(
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:comunic/helpers/groups_helper.dart';
|
||||
import 'package:comunic/lists/groups_list.dart';
|
||||
import 'package:comunic/models/group.dart';
|
||||
import 'package:comunic/ui/widgets/group_icon_widget.dart';
|
||||
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
@ -16,11 +17,11 @@ class GroupsListScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _GroupsListScreenState extends SafeState<GroupsListScreen> {
|
||||
/// The list of groups
|
||||
GroupsList _groups;
|
||||
|
||||
bool _error = false;
|
||||
|
||||
final _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -47,6 +48,7 @@ class _GroupsListScreenState extends SafeState<GroupsListScreen> {
|
||||
// List of groups
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
key: _refreshIndicatorKey,
|
||||
onRefresh: () => this._refreshList(),
|
||||
child: _groups == null
|
||||
? Container()
|
||||
@ -55,6 +57,9 @@ class _GroupsListScreenState extends SafeState<GroupsListScreen> {
|
||||
.map((g) => ListTile(
|
||||
leading: GroupIcon(group: g),
|
||||
title: Text(g.displayName),
|
||||
trailing: IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: () => _deleteGroup(g)),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
@ -81,4 +86,19 @@ class _GroupsListScreenState extends SafeState<GroupsListScreen> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove a group from the list
|
||||
void _deleteGroup(Group g) async {
|
||||
if (!await showConfirmDialog(
|
||||
context: context,
|
||||
message: tr("Do you really want to delete this group membership ?")))
|
||||
return;
|
||||
|
||||
if (!await GroupsHelper().removeMembership(g.id))
|
||||
showSimpleSnack(
|
||||
context, tr("Could not remove your membership to this group!"));
|
||||
|
||||
// Refresh the list of groups
|
||||
_refreshIndicatorKey.currentState.show();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user