1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 08:15:16 +00:00

Can remove a friend from the list of friends

This commit is contained in:
2019-05-01 19:29:46 +02:00
parent a7b2bf410e
commit 7c3390f8af
4 changed files with 90 additions and 6 deletions

View File

@ -39,8 +39,10 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
set loading(bool loading) => setState(() => _loading = loading);
void _gotError() =>
error = _friendsList == null ? _ErrorsLevel.MAJOR : _ErrorsLevel.MINOR;
void _gotError() {
loading = false;
error = _friendsList == null ? _ErrorsLevel.MAJOR : _ErrorsLevel.MINOR;
}
@override
void didChangeDependencies() {
@ -109,6 +111,7 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
? AcceptedFriendTile(
friend: _friendsList[i],
user: _usersInfo.getUser(_friendsList[i].id),
onRequestDelete: _deleteFriend,
)
: PendingFriendTile(
friend: _friendsList[i],
@ -125,10 +128,45 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
loading = true;
if (!await _friendsHelper.respondRequest(f.id, accept))
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(tr("Could not respond to friendship request!"))));
showSimpleSnack(context, tr("Could not respond to friendship request!"));
// Load the list of friends again
_loadList();
}
/// Handles deletion request of a friend
Future<void> _deleteFriend(Friend f) async {
final choice = await showDialog<bool>(
context: context,
builder: (b) => AlertDialog(
title: Text(tr("Delete friend")),
content: Text(tr(
"Are you sure do you want to remove this friend from your list of friends ? A friendship request will have to be sent to get this user back to your list!")),
actions: <Widget>[
FlatButton(
onPressed: () => Navigator.pop(context, false),
child: Text(tr("Cancel").toUpperCase()),
),
FlatButton(
onPressed: () => Navigator.pop(context, true),
child: Text(
tr("Confirm").toUpperCase(),
style: TextStyle(color: Colors.red),
),
),
],
),
);
if (choice == null || !choice) return;
// Forward the request to the server
loading = true;
if (!await _friendsHelper.removeFriend(f.id))
showSimpleSnack(
context, tr("Could not delete this person from your friends list!"));
// Refresh list
_loadList();
}
}