mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Can cancel a group membership invitation
This commit is contained in:
parent
f179e7e1d5
commit
1227ef283c
@ -268,6 +268,15 @@ class GroupsHelper {
|
|||||||
.map((f) => _apiToGroupMembership(f))
|
.map((f) => _apiToGroupMembership(f))
|
||||||
.toList());
|
.toList());
|
||||||
|
|
||||||
|
/// Cancel a group membership invitation
|
||||||
|
///
|
||||||
|
/// Throws an exception in case of failure
|
||||||
|
static Future<void> cancelInvitation(int groupID, int userID) async =>
|
||||||
|
await APIRequest.withLogin("groups/cancel_invitation")
|
||||||
|
.addInt("groupID", groupID)
|
||||||
|
.addInt("userID", userID)
|
||||||
|
.execWithThrow();
|
||||||
|
|
||||||
/// 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(
|
||||||
|
@ -36,6 +36,12 @@ class APIRequest {
|
|||||||
if (this.args == null) this.args = Map();
|
if (this.args == null) this.args = Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
APIRequest.withLogin(this.uri, {this.args})
|
||||||
|
: needLogin = true,
|
||||||
|
assert(uri != null) {
|
||||||
|
if (args == null) this.args = Map();
|
||||||
|
}
|
||||||
|
|
||||||
APIRequest addString(String name, String value) {
|
APIRequest addString(String name, String value) {
|
||||||
args[name] = value;
|
args[name] = value;
|
||||||
return this;
|
return this;
|
||||||
|
@ -4,11 +4,13 @@ import 'package:comunic/lists/group_members_list.dart';
|
|||||||
import 'package:comunic/lists/users_list.dart';
|
import 'package:comunic/lists/users_list.dart';
|
||||||
import 'package:comunic/models/group.dart';
|
import 'package:comunic/models/group.dart';
|
||||||
import 'package:comunic/models/group_membership.dart';
|
import 'package:comunic/models/group_membership.dart';
|
||||||
|
import 'package:comunic/models/user.dart';
|
||||||
import 'package:comunic/ui/dialogs/multi_choices_dialog.dart';
|
import 'package:comunic/ui/dialogs/multi_choices_dialog.dart';
|
||||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||||
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
||||||
import 'package:comunic/ui/widgets/comunic_back_button_widget.dart';
|
import 'package:comunic/ui/widgets/comunic_back_button_widget.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
|
import 'package:comunic/utils/ui_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// Group members screen
|
/// Group members screen
|
||||||
@ -27,6 +29,7 @@ class GroupMembersScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _GroupMembersScreenState extends State<GroupMembersScreen> {
|
class _GroupMembersScreenState extends State<GroupMembersScreen> {
|
||||||
|
final _key = GlobalKey<AsyncScreenWidgetState>();
|
||||||
GroupMembersList _members;
|
GroupMembersList _members;
|
||||||
UsersList _users;
|
UsersList _users;
|
||||||
|
|
||||||
@ -50,6 +53,7 @@ class _GroupMembersScreenState extends State<GroupMembersScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildBody() => AsyncScreenWidget(
|
Widget _buildBody() => AsyncScreenWidget(
|
||||||
|
key: _key,
|
||||||
onReload: _refresh,
|
onReload: _refresh,
|
||||||
onBuild: _buildBodyContent,
|
onBuild: _buildBodyContent,
|
||||||
errorMessage: tr("Could not load the list of members of this group!"),
|
errorMessage: tr("Could not load the list of members of this group!"),
|
||||||
@ -62,6 +66,17 @@ class _GroupMembersScreenState extends State<GroupMembersScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildGroupMemberTile(GroupMembership membership) {
|
||||||
|
final user = _users.getUser(membership.userID);
|
||||||
|
|
||||||
|
return _GroupMembershipTile(
|
||||||
|
membership: membership,
|
||||||
|
user: user,
|
||||||
|
onUpdated: () => _key.currentState.refresh(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<MultiChoiceEntry<GroupMembershipLevel>> get _membershipLevels => [
|
List<MultiChoiceEntry<GroupMembershipLevel>> get _membershipLevels => [
|
||||||
MultiChoiceEntry(
|
MultiChoiceEntry(
|
||||||
id: GroupMembershipLevel.ADMINISTRATOR,
|
id: GroupMembershipLevel.ADMINISTRATOR,
|
||||||
@ -79,22 +94,92 @@ class _GroupMembersScreenState extends State<GroupMembersScreen> {
|
|||||||
subtitle: tr("Can access to all group posts")),
|
subtitle: tr("Can access to all group posts")),
|
||||||
MultiChoiceEntry(
|
MultiChoiceEntry(
|
||||||
id: GroupMembershipLevel.PENDING, title: tr("Requested")),
|
id: GroupMembershipLevel.PENDING, title: tr("Requested")),
|
||||||
MultiChoiceEntry(
|
MultiChoiceEntry(id: GroupMembershipLevel.INVITED, title: tr("Invited")),
|
||||||
id: GroupMembershipLevel.INVITED, title: tr("Invited")),
|
MultiChoiceEntry(id: GroupMembershipLevel.VISITOR, title: tr("Visitor")),
|
||||||
MultiChoiceEntry(
|
|
||||||
id: GroupMembershipLevel.VISITOR, title: tr("Visitor")),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
ListTile _buildGroupMemberTile(GroupMembership membership) {
|
class _GroupMembershipTile extends StatefulWidget {
|
||||||
final user = _users.getUser(membership.userID);
|
final GroupMembership membership;
|
||||||
|
final User user;
|
||||||
|
final void Function() onUpdated;
|
||||||
|
|
||||||
|
const _GroupMembershipTile({
|
||||||
|
Key key,
|
||||||
|
@required this.membership,
|
||||||
|
@required this.user,
|
||||||
|
@required this.onUpdated,
|
||||||
|
}) : assert(membership != null),
|
||||||
|
assert(user != null),
|
||||||
|
assert(onUpdated != null),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
__GroupMembershipTileState createState() => __GroupMembershipTileState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class __GroupMembershipTileState extends State<_GroupMembershipTile> {
|
||||||
|
int get groupID => widget.membership.groupID;
|
||||||
|
|
||||||
|
int get userID => widget.membership.userID;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
leading: AccountImageWidget(
|
leading: AccountImageWidget(
|
||||||
user: user,
|
user: widget.user,
|
||||||
),
|
),
|
||||||
title: Text(user.displayName),
|
title: Text(widget.user.displayName),
|
||||||
subtitle: Text(
|
subtitle: Text(_membershipLevels
|
||||||
_membershipLevels.firstWhere((f) => f.id == membership.level).title),
|
.firstWhere((f) => f.id == widget.membership.level)
|
||||||
|
.title),
|
||||||
|
trailing: _buildTrailing(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildTrailing() {
|
||||||
|
switch (widget.membership.level) {
|
||||||
|
case GroupMembershipLevel.ADMINISTRATOR:
|
||||||
|
// TODO: Handle this case.
|
||||||
|
break;
|
||||||
|
case GroupMembershipLevel.MODERATOR:
|
||||||
|
// TODO: Handle this case.
|
||||||
|
break;
|
||||||
|
case GroupMembershipLevel.MEMBER:
|
||||||
|
// TODO: Handle this case.
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GroupMembershipLevel.INVITED:
|
||||||
|
return _buildInvitedCase();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GroupMembershipLevel.PENDING:
|
||||||
|
// TODO: Handle this case.
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GroupMembershipLevel.VISITOR:
|
||||||
|
// This case should never happen
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildInvitedCase() {
|
||||||
|
return MaterialButton(
|
||||||
|
onPressed: _cancelMembership,
|
||||||
|
child: Text(tr("Cancel").toUpperCase()),
|
||||||
|
textColor: Colors.red,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _cancelMembership() async {
|
||||||
|
try {
|
||||||
|
await GroupsHelper.cancelInvitation(groupID, userID);
|
||||||
|
} catch (e, s) {
|
||||||
|
print("Could not cancel invitation! $e\n$s");
|
||||||
|
showSimpleSnack(context, tr("Could not cancel invitation!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.onUpdated();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user