mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-26 06:49:22 +00:00
Can respond to a group membership request
This commit is contained in:
parent
3c7795837c
commit
2edaedc5f3
@ -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<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
|
||||
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
||||
return Group(
|
||||
|
@ -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: <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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user