mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Can remove a friend from the list of friends
This commit is contained in:
parent
a7b2bf410e
commit
7c3390f8af
@ -51,4 +51,15 @@ class FriendsHelper {
|
|||||||
|
|
||||||
return response.code == 200;
|
return response.code == 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Remove a friend from the list
|
||||||
|
Future<bool> removeFriend(int friendID) async {
|
||||||
|
final response = await APIRequest(
|
||||||
|
uri: "friends/remove",
|
||||||
|
needLogin: true,
|
||||||
|
args: {"friendID" : friendID.toString()}
|
||||||
|
).exec();
|
||||||
|
|
||||||
|
return response.code == 200;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,10 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
|||||||
|
|
||||||
set loading(bool loading) => setState(() => _loading = loading);
|
set loading(bool loading) => setState(() => _loading = loading);
|
||||||
|
|
||||||
void _gotError() =>
|
void _gotError() {
|
||||||
error = _friendsList == null ? _ErrorsLevel.MAJOR : _ErrorsLevel.MINOR;
|
loading = false;
|
||||||
|
error = _friendsList == null ? _ErrorsLevel.MAJOR : _ErrorsLevel.MINOR;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
@ -109,6 +111,7 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
|||||||
? AcceptedFriendTile(
|
? AcceptedFriendTile(
|
||||||
friend: _friendsList[i],
|
friend: _friendsList[i],
|
||||||
user: _usersInfo.getUser(_friendsList[i].id),
|
user: _usersInfo.getUser(_friendsList[i].id),
|
||||||
|
onRequestDelete: _deleteFriend,
|
||||||
)
|
)
|
||||||
: PendingFriendTile(
|
: PendingFriendTile(
|
||||||
friend: _friendsList[i],
|
friend: _friendsList[i],
|
||||||
@ -125,10 +128,45 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
|||||||
loading = true;
|
loading = true;
|
||||||
|
|
||||||
if (!await _friendsHelper.respondRequest(f.id, accept))
|
if (!await _friendsHelper.respondRequest(f.id, accept))
|
||||||
Scaffold.of(context).showSnackBar(SnackBar(
|
showSimpleSnack(context, tr("Could not respond to friendship request!"));
|
||||||
content: Text(tr("Could not respond to friendship request!"))));
|
|
||||||
|
|
||||||
// Load the list of friends again
|
// Load the list of friends again
|
||||||
_loadList();
|
_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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,23 @@ import 'package:flutter/material.dart';
|
|||||||
///
|
///
|
||||||
/// @author Pierre HUBERT
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
|
enum _FriendMenuChoices { REMOVE }
|
||||||
|
|
||||||
|
typedef OnRequestDeleteFriend = void Function(Friend);
|
||||||
|
|
||||||
class AcceptedFriendTile extends StatelessWidget {
|
class AcceptedFriendTile extends StatelessWidget {
|
||||||
final Friend friend;
|
final Friend friend;
|
||||||
final User user;
|
final User user;
|
||||||
|
final OnRequestDeleteFriend onRequestDelete;
|
||||||
|
|
||||||
const AcceptedFriendTile(
|
const AcceptedFriendTile(
|
||||||
{Key key, @required this.friend, @required this.user})
|
{Key key,
|
||||||
|
@required this.friend,
|
||||||
|
@required this.user,
|
||||||
|
@required this.onRequestDelete})
|
||||||
: assert(friend != null),
|
: assert(friend != null),
|
||||||
assert(user != null),
|
assert(user != null),
|
||||||
|
assert(onRequestDelete != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -32,8 +41,28 @@ class AcceptedFriendTile extends StatelessWidget {
|
|||||||
style: TextStyle(color: Colors.green),
|
style: TextStyle(color: Colors.green),
|
||||||
)
|
)
|
||||||
: Text(
|
: Text(
|
||||||
diffTimeFromNowToStr(friend.lastActive),
|
diffTimeFromNowToStr(friend.lastActive),
|
||||||
),
|
),
|
||||||
|
trailing: PopupMenuButton<_FriendMenuChoices>(
|
||||||
|
itemBuilder: (c) => [
|
||||||
|
PopupMenuItem(
|
||||||
|
child: Text(tr("Remove")),
|
||||||
|
value: _FriendMenuChoices.REMOVE,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
onSelected: _selectedMenuOption,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _selectedMenuOption(_FriendMenuChoices value) {
|
||||||
|
if (value == null) return;
|
||||||
|
|
||||||
|
switch (value) {
|
||||||
|
//Delete friend
|
||||||
|
case _FriendMenuChoices.REMOVE:
|
||||||
|
onRequestDelete(friend);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,3 +60,9 @@ void showImageFullScreen(BuildContext context, String url) {
|
|||||||
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Show simple snack
|
||||||
|
void showSimpleSnack(BuildContext context, String message) {
|
||||||
|
Scaffold.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user