From 2edaedc5f373cd34b498575031c3c59f8b8d1754 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 2 May 2020 15:57:49 +0200 Subject: [PATCH] Can respond to a group membership request --- lib/helpers/groups_helper.dart | 11 +++++++++ lib/ui/screens/group_members_screen.dart | 31 +++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/helpers/groups_helper.dart b/lib/helpers/groups_helper.dart index fa111aa..932e305 100644 --- a/lib/helpers/groups_helper.dart +++ b/lib/helpers/groups_helper.dart @@ -286,6 +286,17 @@ class GroupsHelper { .addInt("userID", userID) .execWithThrow(); + /// Respond to a group membership request + /// + /// Throws an exception in case of failure + static Future respondRequest( + int groupID, int userID, bool accept) async => + await APIRequest.withLogin("groups/respond_request") + .addInt("groupID", groupID) + .addInt("userID", userID) + .addBool("accept", accept) + .execWithThrow(); + /// Turn an API entry into a group object Group _getGroupFromAPI(Map map) { return Group( diff --git a/lib/ui/screens/group_members_screen.dart b/lib/ui/screens/group_members_screen.dart index a0da717..0b5a017 100644 --- a/lib/ui/screens/group_members_screen.dart +++ b/lib/ui/screens/group_members_screen.dart @@ -182,7 +182,7 @@ class __GroupMembershipTileState extends State<_GroupMembershipTile> { break; case GroupMembershipLevel.PENDING: - // TODO: Handle this case. + return _buildRequestedCase(); break; case GroupMembershipLevel.VISITOR: @@ -211,4 +211,33 @@ class __GroupMembershipTileState extends State<_GroupMembershipTile> { widget.onUpdated(); } + + Widget _buildRequestedCase() { + return IntrinsicWidth( + child: Row( + children: [ + MaterialButton( + onPressed: () => _respondRequest(false), + child: Text(tr("Reject").toUpperCase()), + textColor: Colors.red, + ), + MaterialButton( + onPressed: () => _respondRequest(true), + child: Text(tr("Accept").toUpperCase()), + textColor: Colors.green, + ) + ], + )); + } + + void _respondRequest(bool accept) async { + try { + await GroupsHelper.respondRequest(groupID, userID, accept); + } catch (e, s) { + print("Could not respond to membership request! $e\n$s"); + showSimpleSnack(context, tr("Could not respond to membership request!")); + } + + widget.onUpdated(); + } }