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

Can respond to group membership invitations

This commit is contained in:
Pierre HUBERT 2020-04-15 14:31:45 +02:00
parent cd677deec0
commit 8d49a80e79
3 changed files with 59 additions and 5 deletions

View File

@ -73,7 +73,7 @@ class GroupsHelper {
// Check which groups information to download
final toDownload = Set<int>();
groups.forEach((groupID) {
if (_groupsListCache.containsKey(groupID))
if (!force && _groupsListCache.containsKey(groupID))
list[groupID] = _groupsListCache[groupID];
else
toDownload.add(groupID);
@ -101,8 +101,11 @@ class GroupsHelper {
.toSet();
/// Perform a simple membership request
Future<bool> _simpleMembershipRequest(int groupID, String uri) async =>
(await (APIRequest(uri: uri, needLogin: true)..addInt("id", groupID))
Future<bool> _simpleMembershipRequest(int groupID, String uri,
{Map<String, String> args}) async =>
(await (APIRequest(uri: uri, needLogin: true)
..addInt("id", groupID)
..addArgs(args == null ? Map() : args))
.exec())
.isOK;
@ -118,6 +121,12 @@ class GroupsHelper {
Future<bool> sendRequest(int groupID) async =>
_simpleMembershipRequest(groupID, "groups/send_request");
/// Respond to a group membership invitation
Future<bool> respondInvitation(int groupID, bool accept) async =>
_simpleMembershipRequest(groupID, "groups/respond_invitation", args: {
"accept": accept ? "true" : "false",
});
/// Turn an API entry into a group object
Group _getGroupFromAPI(Map<String, dynamic> map) {
return Group(

View File

@ -31,6 +31,8 @@ class APIRequest {
void addFile(String name, File file) => files[name] = file;
void addArgs(Map<String, String> newArgs) => args.addAll(newArgs);
/// Execute the request
Future<APIResponse> exec() async => APIHelper().exec(this);

View File

@ -43,8 +43,8 @@ class _GroupMembershipWidgetState extends SafeState<GroupMembershipWidget> {
return Text(tr("Member"));
case GroupMembershipLevel.INVITED:
// TODO: Handle this case.
break;
return _buildInvitedState();
case GroupMembershipLevel.PENDING:
return _buildPendingState();
@ -53,6 +53,49 @@ class _GroupMembershipWidgetState extends SafeState<GroupMembershipWidget> {
}
}
/// Build invited state
Widget _buildInvitedState() {
return RichText(
text: TextSpan(children: [
WidgetSpan(
child: Icon(Icons.info_outline, size: 12),
alignment: PlaceholderAlignment.middle),
TextSpan(text: " " + tr("Invited") + " "),
TextSpan(
text: tr("Accept"),
style: TextStyle(color: Colors.green),
recognizer: TapGestureRecognizer()
..onTap = () => _respondInvitation(true)),
TextSpan(text: " "),
TextSpan(
text: tr("Reject"),
style: TextStyle(color: Colors.red),
recognizer: TapGestureRecognizer()
..onTap = () => _respondInvitation(false)),
]),
);
}
/// Respond to an invitation
void _respondInvitation(bool accept) async {
if (!accept &&
!await showConfirmDialog(
context: context,
message: tr("Do you really want to reject this invitation?")))
return;
if (!await GroupsHelper().respondInvitation(_id, accept))
showSimpleSnack(context, tr("Could not respond to your invitation!"));
else {
// Refresh state
group.membershipLevel =
accept ? GroupMembershipLevel.MEMBER : GroupMembershipLevel.VISITOR;
this.setState(() {});
if (this.widget.onUpdated != null) this.widget.onUpdated();
}
}
/// Build pending state
Widget _buildPendingState() {
return RichText(