mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-29 08:16:28 +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)
|
.addBool("accept", accept)
|
||||||
.execWithThrow();
|
.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
|
/// Turn an API entry into a group object
|
||||||
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
||||||
return Group(
|
return Group(
|
||||||
|
@ -146,6 +146,8 @@ class _GroupMembershipTile extends StatefulWidget {
|
|||||||
__GroupMembershipTileState createState() => __GroupMembershipTileState();
|
__GroupMembershipTileState createState() => __GroupMembershipTileState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum _MemberMenuOptions { DELETE }
|
||||||
|
|
||||||
class __GroupMembershipTileState extends State<_GroupMembershipTile> {
|
class __GroupMembershipTileState extends State<_GroupMembershipTile> {
|
||||||
int get groupID => widget.membership.groupID;
|
int get groupID => widget.membership.groupID;
|
||||||
|
|
||||||
@ -168,13 +170,9 @@ class __GroupMembershipTileState extends State<_GroupMembershipTile> {
|
|||||||
Widget _buildTrailing() {
|
Widget _buildTrailing() {
|
||||||
switch (widget.membership.level) {
|
switch (widget.membership.level) {
|
||||||
case GroupMembershipLevel.ADMINISTRATOR:
|
case GroupMembershipLevel.ADMINISTRATOR:
|
||||||
// TODO: Handle this case.
|
|
||||||
break;
|
|
||||||
case GroupMembershipLevel.MODERATOR:
|
case GroupMembershipLevel.MODERATOR:
|
||||||
// TODO: Handle this case.
|
|
||||||
break;
|
|
||||||
case GroupMembershipLevel.MEMBER:
|
case GroupMembershipLevel.MEMBER:
|
||||||
// TODO: Handle this case.
|
return _buildMemberCase();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GroupMembershipLevel.INVITED:
|
case GroupMembershipLevel.INVITED:
|
||||||
@ -193,6 +191,43 @@ class __GroupMembershipTileState extends State<_GroupMembershipTile> {
|
|||||||
return null;
|
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() {
|
Widget _buildInvitedCase() {
|
||||||
return MaterialButton(
|
return MaterialButton(
|
||||||
onPressed: _cancelMembership,
|
onPressed: _cancelMembership,
|
||||||
|
Loading…
Reference in New Issue
Block a user