2019-05-01 15:52:41 +00:00
|
|
|
import 'package:comunic/lists/friends_list.dart';
|
|
|
|
import 'package:comunic/models/api_request.dart';
|
|
|
|
import 'package:comunic/models/friend.dart';
|
|
|
|
|
|
|
|
/// Friends helper
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
|
|
|
class FriendsHelper {
|
|
|
|
/// Get the list of friends of the user
|
|
|
|
///
|
|
|
|
/// Returns the list of friends in case of success, or null if an error
|
|
|
|
/// occurred
|
|
|
|
Future<FriendsList> downloadList() async {
|
|
|
|
final response = await APIRequest(
|
|
|
|
uri: "friends/getList",
|
|
|
|
needLogin: true,
|
|
|
|
args: {
|
|
|
|
"complete": "true",
|
|
|
|
},
|
|
|
|
).exec();
|
|
|
|
|
|
|
|
if (response.code != 200) return null;
|
|
|
|
|
|
|
|
// Parse and return the list of friends
|
|
|
|
FriendsList list = FriendsList();
|
2019-05-01 16:01:20 +00:00
|
|
|
response.getArray().forEach(
|
|
|
|
(f) => list.add(
|
|
|
|
Friend(
|
|
|
|
id: f["ID_friend"],
|
|
|
|
accepted: f["accepted"] == 1,
|
|
|
|
lastActive: f["time_last_activity"],
|
|
|
|
following: f["following"] == 1,
|
|
|
|
canPostTexts: f["canPostTexts"],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2019-05-01 15:52:41 +00:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
2019-05-01 16:01:20 +00:00
|
|
|
|
|
|
|
/// Respond to friendship request
|
|
|
|
Future<bool> respondRequest(int friendID, bool accept) async {
|
|
|
|
final response = await APIRequest(
|
|
|
|
uri: "friends/respondRequest",
|
|
|
|
needLogin: true,
|
|
|
|
args: {
|
|
|
|
"friendID": friendID.toString(),
|
|
|
|
"accept": accept.toString()
|
|
|
|
}).exec();
|
|
|
|
|
|
|
|
return response.code == 200;
|
|
|
|
}
|
2019-05-01 17:29:46 +00:00
|
|
|
|
2019-05-01 17:46:13 +00:00
|
|
|
/// 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();
|
|
|
|
|
|
|
|
return response.code == 200;
|
|
|
|
}
|
|
|
|
|
2019-05-01 17:29:46 +00:00
|
|
|
/// 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;
|
|
|
|
}
|
2019-05-01 16:01:20 +00:00
|
|
|
}
|