mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Can respond to friendship requests
This commit is contained in:
parent
5021ded039
commit
a7b2bf410e
@ -24,15 +24,31 @@ class FriendsHelper {
|
||||
|
||||
// Parse and return the list of friends
|
||||
FriendsList list = FriendsList();
|
||||
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"],),),
|
||||
);
|
||||
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"],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// 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;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ import 'package:comunic/helpers/friends_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/lists/friends_list.dart';
|
||||
import 'package:comunic/lists/users_list.dart';
|
||||
import 'package:comunic/models/friend.dart';
|
||||
import 'package:comunic/ui/tiles/accepted_friend_tile.dart';
|
||||
import 'package:comunic/ui/tiles/pending_friend_tile.dart';
|
||||
import 'package:comunic/ui/widgets/safe_state.dart';
|
||||
@ -41,7 +42,6 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
||||
void _gotError() =>
|
||||
error = _friendsList == null ? _ErrorsLevel.MAJOR : _ErrorsLevel.MINOR;
|
||||
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
@ -75,8 +75,7 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
||||
}
|
||||
|
||||
/// Build and return loading error
|
||||
Widget _buildError() =>
|
||||
buildErrorCard(
|
||||
Widget _buildError() => buildErrorCard(
|
||||
tr("Could not load your list of friends!"),
|
||||
actions: [
|
||||
FlatButton(
|
||||
@ -96,7 +95,6 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
||||
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
|
||||
// Check for errors
|
||||
Container(child: _error != _ErrorsLevel.NONE ? _buildError() : null),
|
||||
|
||||
@ -105,18 +103,32 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
|
||||
|
||||
// List of friends
|
||||
Expanded(
|
||||
child: ListView.builder(itemCount: _friendsList.length, itemBuilder: (c, i) =>
|
||||
_friendsList[i].accepted ? AcceptedFriendTile(
|
||||
friend: _friendsList[i],
|
||||
user: _usersInfo.getUser(_friendsList[i].id),
|
||||
) : PendingFriendTile(
|
||||
friend: _friendsList[i],
|
||||
user: _usersInfo.getUser(_friendsList[i].id),
|
||||
onRespond: (friend, accept){},
|
||||
)),
|
||||
child: ListView.builder(
|
||||
itemCount: _friendsList.length,
|
||||
itemBuilder: (c, i) => _friendsList[i].accepted
|
||||
? AcceptedFriendTile(
|
||||
friend: _friendsList[i],
|
||||
user: _usersInfo.getUser(_friendsList[i].id),
|
||||
)
|
||||
: PendingFriendTile(
|
||||
friend: _friendsList[i],
|
||||
user: _usersInfo.getUser(_friendsList[i].id),
|
||||
onRespond: _respondRequest,
|
||||
)),
|
||||
),
|
||||
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Respond to friendship request
|
||||
Future<void> _respondRequest(Friend f, bool accept) async {
|
||||
loading = true;
|
||||
|
||||
if (!await _friendsHelper.respondRequest(f.id, accept))
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Text(tr("Could not respond to friendship request!"))));
|
||||
|
||||
// Load the list of friends again
|
||||
_loadList();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user