1
0
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:
Pierre HUBERT 2019-05-01 18:01:20 +02:00
parent 5021ded039
commit a7b2bf410e
2 changed files with 51 additions and 23 deletions

View File

@ -24,15 +24,31 @@ class FriendsHelper {
// Parse and return the list of friends // Parse and return the list of friends
FriendsList list = FriendsList(); FriendsList list = FriendsList();
response.getArray().forEach((f) => response.getArray().forEach(
list.add(Friend( (f) => list.add(
id: f["ID_friend"], Friend(
accepted: f["accepted"] == 1, id: f["ID_friend"],
lastActive: f["time_last_activity"], accepted: f["accepted"] == 1,
following: f["following"] == 1, lastActive: f["time_last_activity"],
canPostTexts: f["canPostTexts"],),), following: f["following"] == 1,
); canPostTexts: f["canPostTexts"],
),
),
);
return list; 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;
}
}

View File

@ -2,6 +2,7 @@ import 'package:comunic/helpers/friends_helper.dart';
import 'package:comunic/helpers/users_helper.dart'; import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/friends_list.dart'; import 'package:comunic/lists/friends_list.dart';
import 'package:comunic/lists/users_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/accepted_friend_tile.dart';
import 'package:comunic/ui/tiles/pending_friend_tile.dart'; import 'package:comunic/ui/tiles/pending_friend_tile.dart';
import 'package:comunic/ui/widgets/safe_state.dart'; import 'package:comunic/ui/widgets/safe_state.dart';
@ -41,7 +42,6 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
void _gotError() => void _gotError() =>
error = _friendsList == null ? _ErrorsLevel.MAJOR : _ErrorsLevel.MINOR; error = _friendsList == null ? _ErrorsLevel.MAJOR : _ErrorsLevel.MINOR;
@override @override
void didChangeDependencies() { void didChangeDependencies() {
super.didChangeDependencies(); super.didChangeDependencies();
@ -75,8 +75,7 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
} }
/// Build and return loading error /// Build and return loading error
Widget _buildError() => Widget _buildError() => buildErrorCard(
buildErrorCard(
tr("Could not load your list of friends!"), tr("Could not load your list of friends!"),
actions: [ actions: [
FlatButton( FlatButton(
@ -96,7 +95,6 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
return Column( return Column(
children: <Widget>[ children: <Widget>[
// Check for errors // Check for errors
Container(child: _error != _ErrorsLevel.NONE ? _buildError() : null), Container(child: _error != _ErrorsLevel.NONE ? _buildError() : null),
@ -105,18 +103,32 @@ class _FriendsListScreenState extends SafeState<FriendsListScreen> {
// List of friends // List of friends
Expanded( Expanded(
child: ListView.builder(itemCount: _friendsList.length, itemBuilder: (c, i) => child: ListView.builder(
_friendsList[i].accepted ? AcceptedFriendTile( itemCount: _friendsList.length,
friend: _friendsList[i], itemBuilder: (c, i) => _friendsList[i].accepted
user: _usersInfo.getUser(_friendsList[i].id), ? AcceptedFriendTile(
) : PendingFriendTile( friend: _friendsList[i],
friend: _friendsList[i], user: _usersInfo.getUser(_friendsList[i].id),
user: _usersInfo.getUser(_friendsList[i].id), )
onRespond: (friend, accept){}, : 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();
}
} }