mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Can respond to group membership invitations
This commit is contained in:
parent
cd677deec0
commit
8d49a80e79
@ -73,7 +73,7 @@ class GroupsHelper {
|
|||||||
// Check which groups information to download
|
// Check which groups information to download
|
||||||
final toDownload = Set<int>();
|
final toDownload = Set<int>();
|
||||||
groups.forEach((groupID) {
|
groups.forEach((groupID) {
|
||||||
if (_groupsListCache.containsKey(groupID))
|
if (!force && _groupsListCache.containsKey(groupID))
|
||||||
list[groupID] = _groupsListCache[groupID];
|
list[groupID] = _groupsListCache[groupID];
|
||||||
else
|
else
|
||||||
toDownload.add(groupID);
|
toDownload.add(groupID);
|
||||||
@ -101,8 +101,11 @@ class GroupsHelper {
|
|||||||
.toSet();
|
.toSet();
|
||||||
|
|
||||||
/// Perform a simple membership request
|
/// Perform a simple membership request
|
||||||
Future<bool> _simpleMembershipRequest(int groupID, String uri) async =>
|
Future<bool> _simpleMembershipRequest(int groupID, String uri,
|
||||||
(await (APIRequest(uri: uri, needLogin: true)..addInt("id", groupID))
|
{Map<String, String> args}) async =>
|
||||||
|
(await (APIRequest(uri: uri, needLogin: true)
|
||||||
|
..addInt("id", groupID)
|
||||||
|
..addArgs(args == null ? Map() : args))
|
||||||
.exec())
|
.exec())
|
||||||
.isOK;
|
.isOK;
|
||||||
|
|
||||||
@ -118,6 +121,12 @@ class GroupsHelper {
|
|||||||
Future<bool> sendRequest(int groupID) async =>
|
Future<bool> sendRequest(int groupID) async =>
|
||||||
_simpleMembershipRequest(groupID, "groups/send_request");
|
_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
|
/// Turn an API entry into a group object
|
||||||
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
Group _getGroupFromAPI(Map<String, dynamic> map) {
|
||||||
return Group(
|
return Group(
|
||||||
|
@ -31,6 +31,8 @@ class APIRequest {
|
|||||||
|
|
||||||
void addFile(String name, File file) => files[name] = file;
|
void addFile(String name, File file) => files[name] = file;
|
||||||
|
|
||||||
|
void addArgs(Map<String, String> newArgs) => args.addAll(newArgs);
|
||||||
|
|
||||||
/// Execute the request
|
/// Execute the request
|
||||||
Future<APIResponse> exec() async => APIHelper().exec(this);
|
Future<APIResponse> exec() async => APIHelper().exec(this);
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ class _GroupMembershipWidgetState extends SafeState<GroupMembershipWidget> {
|
|||||||
return Text(tr("Member"));
|
return Text(tr("Member"));
|
||||||
|
|
||||||
case GroupMembershipLevel.INVITED:
|
case GroupMembershipLevel.INVITED:
|
||||||
// TODO: Handle this case.
|
return _buildInvitedState();
|
||||||
break;
|
|
||||||
case GroupMembershipLevel.PENDING:
|
case GroupMembershipLevel.PENDING:
|
||||||
return _buildPendingState();
|
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
|
/// Build pending state
|
||||||
Widget _buildPendingState() {
|
Widget _buildPendingState() {
|
||||||
return RichText(
|
return RichText(
|
||||||
|
Loading…
Reference in New Issue
Block a user