1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-29 16:26:27 +00:00

Can respond to a group membership request

This commit is contained in:
Pierre HUBERT 2020-05-02 15:57:49 +02:00
parent 3c7795837c
commit 2edaedc5f3
2 changed files with 41 additions and 1 deletions

View File

@ -286,6 +286,17 @@ class GroupsHelper {
.addInt("userID", userID) .addInt("userID", userID)
.execWithThrow(); .execWithThrow();
/// Respond to a group membership request
///
/// Throws an exception in case of failure
static Future<void> 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 /// Turn an API entry into a group object
Group _getGroupFromAPI(Map<String, dynamic> map) { Group _getGroupFromAPI(Map<String, dynamic> map) {
return Group( return Group(

View File

@ -182,7 +182,7 @@ class __GroupMembershipTileState extends State<_GroupMembershipTile> {
break; break;
case GroupMembershipLevel.PENDING: case GroupMembershipLevel.PENDING:
// TODO: Handle this case. return _buildRequestedCase();
break; break;
case GroupMembershipLevel.VISITOR: case GroupMembershipLevel.VISITOR:
@ -211,4 +211,33 @@ class __GroupMembershipTileState extends State<_GroupMembershipTile> {
widget.onUpdated(); widget.onUpdated();
} }
Widget _buildRequestedCase() {
return IntrinsicWidth(
child: Row(
children: <Widget>[
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();
}
} }