mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +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))
|
.map((f) => cast<int>(f))
|
||||||
.toSet();
|
.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
|
/// Turn an API entry into a group object
|
||||||
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
||||||
return Group(
|
return Group(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:comunic/helpers/groups_helper.dart';
|
import 'package:comunic/helpers/groups_helper.dart';
|
||||||
import 'package:comunic/lists/groups_list.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/group_icon_widget.dart';
|
||||||
import 'package:comunic/ui/widgets/safe_state.dart';
|
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
@ -16,11 +17,11 @@ class GroupsListScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _GroupsListScreenState extends SafeState<GroupsListScreen> {
|
class _GroupsListScreenState extends SafeState<GroupsListScreen> {
|
||||||
/// The list of groups
|
|
||||||
GroupsList _groups;
|
GroupsList _groups;
|
||||||
|
|
||||||
bool _error = false;
|
bool _error = false;
|
||||||
|
|
||||||
|
final _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@ -47,6 +48,7 @@ class _GroupsListScreenState extends SafeState<GroupsListScreen> {
|
|||||||
// List of groups
|
// List of groups
|
||||||
Expanded(
|
Expanded(
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
|
key: _refreshIndicatorKey,
|
||||||
onRefresh: () => this._refreshList(),
|
onRefresh: () => this._refreshList(),
|
||||||
child: _groups == null
|
child: _groups == null
|
||||||
? Container()
|
? Container()
|
||||||
@ -55,6 +57,9 @@ class _GroupsListScreenState extends SafeState<GroupsListScreen> {
|
|||||||
.map((g) => ListTile(
|
.map((g) => ListTile(
|
||||||
leading: GroupIcon(group: g),
|
leading: GroupIcon(group: g),
|
||||||
title: Text(g.displayName),
|
title: Text(g.displayName),
|
||||||
|
trailing: IconButton(
|
||||||
|
icon: Icon(Icons.delete),
|
||||||
|
onPressed: () => _deleteGroup(g)),
|
||||||
))
|
))
|
||||||
.toList(),
|
.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