mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Can respond to friendship requests
This commit is contained in:
		@@ -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(
 | 
				
			||||||
 | 
					                Friend(
 | 
				
			||||||
                  id: f["ID_friend"],
 | 
					                  id: f["ID_friend"],
 | 
				
			||||||
                  accepted: f["accepted"] == 1,
 | 
					                  accepted: f["accepted"] == 1,
 | 
				
			||||||
                  lastActive: f["time_last_activity"],
 | 
					                  lastActive: f["time_last_activity"],
 | 
				
			||||||
                  following: f["following"] == 1,
 | 
					                  following: f["following"] == 1,
 | 
				
			||||||
          canPostTexts: f["canPostTexts"],),),
 | 
					                  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;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -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,
 | 
				
			||||||
 | 
					              itemBuilder: (c, i) => _friendsList[i].accepted
 | 
				
			||||||
 | 
					                  ? AcceptedFriendTile(
 | 
				
			||||||
                      friend: _friendsList[i],
 | 
					                      friend: _friendsList[i],
 | 
				
			||||||
                      user: _usersInfo.getUser(_friendsList[i].id),
 | 
					                      user: _usersInfo.getUser(_friendsList[i].id),
 | 
				
			||||||
          ) : PendingFriendTile(
 | 
					                    )
 | 
				
			||||||
 | 
					                  : PendingFriendTile(
 | 
				
			||||||
                      friend: _friendsList[i],
 | 
					                      friend: _friendsList[i],
 | 
				
			||||||
                      user: _usersInfo.getUser(_friendsList[i].id),
 | 
					                      user: _usersInfo.getUser(_friendsList[i].id),
 | 
				
			||||||
            onRespond: (friend, accept){},
 | 
					                      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();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user