1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09: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 => Future<bool> cancelRequest(int groupID) async =>
_simpleMembershipRequest(groupID, "groups/cancel_request"); _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 /// 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

@ -49,8 +49,7 @@ class _GroupMembershipWidgetState extends SafeState<GroupMembershipWidget> {
return _buildPendingState(); return _buildPendingState();
case GroupMembershipLevel.VISITOR: case GroupMembershipLevel.VISITOR:
// TODO: Handle this case. return _buildVisitorState();
break;
} }
} }
@ -79,4 +78,28 @@ class _GroupMembershipWidgetState extends SafeState<GroupMembershipWidget> {
if (this.widget.onUpdated != null) this.widget.onUpdated(); 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();
}
}
} }