1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 04:49:21 +00:00

Can cancel membership request

This commit is contained in:
Pierre HUBERT 2020-04-15 14:04:47 +02:00
parent eaeb07db69
commit 2c9dc5199c
2 changed files with 29 additions and 2 deletions

View File

@ -114,6 +114,10 @@ class GroupsHelper {
Future<bool> cancelRequest(int groupID) async =>
_simpleMembershipRequest(groupID, "groups/cancel_request");
/// Send a new membership request
Future<bool> sendRequest(int groupID) async =>
_simpleMembershipRequest(groupID, "groups/send_request");
/// Turn an API entry into a group object
Group _getGroupFromAPI(Map<String, dynamic> map) {
return Group(

View File

@ -49,8 +49,7 @@ class _GroupMembershipWidgetState extends SafeState<GroupMembershipWidget> {
return _buildPendingState();
case GroupMembershipLevel.VISITOR:
// TODO: Handle this case.
break;
return _buildVisitorState();
}
}
@ -79,4 +78,28 @@ class _GroupMembershipWidgetState extends SafeState<GroupMembershipWidget> {
if (this.widget.onUpdated != null) this.widget.onUpdated();
}
}
/// Build visitor state
Widget _buildVisitorState() {
return RichText(
text: TextSpan(
text: tr("Request membership"),
style: TextStyle(color: Colors.blue),
recognizer: TapGestureRecognizer()
..onTap = () => _requestMembership()),
);
}
/// Create new membership request
void _requestMembership() async {
if (!await GroupsHelper().sendRequest(_id))
showSimpleSnack(context, tr("Could not send your membership request!"));
else {
// Refresh state
group.membershipLevel = GroupMembershipLevel.PENDING;
this.setState(() {});
if (this.widget.onUpdated != null) this.widget.onUpdated();
}
}
}