mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Can get the list of friends of a user
This commit is contained in:
@ -9,7 +9,6 @@ import 'package:meta/meta.dart';
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
class FriendsHelper {
|
||||
|
||||
final FriendsDatabaseHelper _friendsDatabaseHelper = FriendsDatabaseHelper();
|
||||
|
||||
/// Get the list of friends of the user from the server
|
||||
@ -50,10 +49,8 @@ class FriendsHelper {
|
||||
|
||||
/// Get the list, either from an online or an offline source
|
||||
Future<FriendsList> getList({@required bool online}) async {
|
||||
|
||||
if(online)
|
||||
if (online)
|
||||
return await _downloadList();
|
||||
|
||||
else
|
||||
return FriendsList()..addAll(await _friendsDatabaseHelper.getAll());
|
||||
}
|
||||
@ -74,13 +71,12 @@ class FriendsHelper {
|
||||
/// Update following status for a friend
|
||||
Future<bool> setFollowing(int friendID, bool follow) async {
|
||||
final response = await APIRequest(
|
||||
uri: "friends/setFollowing",
|
||||
needLogin: true,
|
||||
args: {
|
||||
"friendID" : friendID.toString(),
|
||||
"follow": follow.toString()
|
||||
}
|
||||
).exec();
|
||||
uri: "friends/setFollowing",
|
||||
needLogin: true,
|
||||
args: {
|
||||
"friendID": friendID.toString(),
|
||||
"follow": follow.toString()
|
||||
}).exec();
|
||||
|
||||
return response.code == 200;
|
||||
}
|
||||
@ -88,11 +84,26 @@ class FriendsHelper {
|
||||
/// 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();
|
||||
uri: "friends/remove",
|
||||
needLogin: true,
|
||||
args: {"friendID": friendID.toString()}).exec();
|
||||
|
||||
return response.code == 200;
|
||||
}
|
||||
|
||||
/// Get and return the list of friends of an other user
|
||||
///
|
||||
/// Throws an Exception if could not get the list of friends
|
||||
Future<Set<int>> getOtherUserList(int userID) async {
|
||||
final response = await APIRequest(
|
||||
uri: "friends/get_user_list",
|
||||
needLogin: true,
|
||||
args: {"userID": userID.toString()},
|
||||
).exec();
|
||||
|
||||
if (response.code != 200)
|
||||
throw new Exception("Could not get the list of friends of this user!");
|
||||
|
||||
return Set<int>.from(response.getArray());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user