mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 12:58:51 +00:00
Can remove a member from a group
This commit is contained in:
parent
2edaedc5f3
commit
eb66ea407b
@ -297,6 +297,15 @@ class GroupsHelper {
|
||||
.addBool("accept", accept)
|
||||
.execWithThrow();
|
||||
|
||||
/// Remove a member from a group
|
||||
///
|
||||
/// Throws an exception in case of failure
|
||||
static Future<void> removeMemberFromGroup(int groupID, int userID) async =>
|
||||
APIRequest.withLogin("groups/delete_member")
|
||||
.addInt("groupID", groupID)
|
||||
.addInt("userID", userID)
|
||||
.execWithThrow();
|
||||
|
||||
/// Turn an API entry into a group object
|
||||
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
||||
return Group(
|
||||
|
@ -146,6 +146,8 @@ class _GroupMembershipTile extends StatefulWidget {
|
||||
__GroupMembershipTileState createState() => __GroupMembershipTileState();
|
||||
}
|
||||
|
||||
enum _MemberMenuOptions { DELETE }
|
||||
|
||||
class __GroupMembershipTileState extends State<_GroupMembershipTile> {
|
||||
int get groupID => widget.membership.groupID;
|
||||
|
||||
@ -168,13 +170,9 @@ class __GroupMembershipTileState extends State<_GroupMembershipTile> {
|
||||
Widget _buildTrailing() {
|
||||
switch (widget.membership.level) {
|
||||
case GroupMembershipLevel.ADMINISTRATOR:
|
||||
// TODO: Handle this case.
|
||||
break;
|
||||
case GroupMembershipLevel.MODERATOR:
|
||||
// TODO: Handle this case.
|
||||
break;
|
||||
case GroupMembershipLevel.MEMBER:
|
||||
// TODO: Handle this case.
|
||||
return _buildMemberCase();
|
||||
break;
|
||||
|
||||
case GroupMembershipLevel.INVITED:
|
||||
@ -193,6 +191,43 @@ class __GroupMembershipTileState extends State<_GroupMembershipTile> {
|
||||
return null;
|
||||
}
|
||||
|
||||
Widget _buildMemberCase() {
|
||||
return PopupMenuButton<_MemberMenuOptions>(
|
||||
itemBuilder: (c) => [
|
||||
// Remove membership
|
||||
PopupMenuItem(
|
||||
child: Text(tr("Remove")),
|
||||
value: _MemberMenuOptions.DELETE,
|
||||
),
|
||||
],
|
||||
onSelected: _handleMenu,
|
||||
);
|
||||
}
|
||||
|
||||
void _handleMenu(_MemberMenuOptions value) {
|
||||
switch (value) {
|
||||
case _MemberMenuOptions.DELETE:
|
||||
_removeMembership();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _removeMembership() async {
|
||||
try {
|
||||
if (!await showConfirmDialog(
|
||||
context: context,
|
||||
message: tr("Do you really want to remove this membership ?")))
|
||||
return;
|
||||
|
||||
await GroupsHelper.removeMemberFromGroup(groupID, userID);
|
||||
} catch (e, s) {
|
||||
print("Could not remove membership! $e\n$s");
|
||||
showSimpleSnack(context, tr("Could not remove this membership!"));
|
||||
}
|
||||
|
||||
widget.onUpdated();
|
||||
}
|
||||
|
||||
Widget _buildInvitedCase() {
|
||||
return MaterialButton(
|
||||
onPressed: _cancelMembership,
|
||||
|
Loading…
Reference in New Issue
Block a user