1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 06:49:22 +00:00

Avoid a user to appear in its own friends list

This commit is contained in:
Pierre HUBERT 2020-05-16 17:31:16 +02:00
parent 6528ef5bc2
commit f8ba06d0ae

View File

@ -30,11 +30,12 @@ class _OtherUserFriendsListScreenState
final FriendsHelper friendsHelper = FriendsHelper();
final UsersHelper usersHelper = UsersHelper();
UsersList _list;
Set<int> _friendsList;
UsersList _usersInfo;
bool _error = false;
String get _routeName => tr("Friends of %name%",
args: {"name": _list.getUser(widget.userID).displayName});
args: {"name": _usersInfo.getUser(widget.userID).displayName});
void setError(bool e) => setState(() => _error = e);
@ -49,12 +50,15 @@ class _OtherUserFriendsListScreenState
setError(false);
try {
final list = await usersHelper
.getListWithThrow(await friendsHelper.getOtherUserList(widget.userID)
..add(widget.userID));
final friendsList = await friendsHelper.getOtherUserList(widget.userID);
// We use [Set.toSet] here to avoid the current user to appear in the list
final users = await usersHelper
.getListWithThrow(friendsList.toSet()..add(widget.userID));
setState(() {
_list = list;
_friendsList = friendsList;
_usersInfo = users;
});
} catch (e, st) {
print(e);
@ -67,16 +71,16 @@ class _OtherUserFriendsListScreenState
Widget build(BuildContext context) {
if (_error) return _buildError();
if (_list == null) return buildCenteredProgressBar();
if (_usersInfo == null) return buildCenteredProgressBar();
return Scaffold(
appBar: AppBar(
title: Text(_routeName),
),
body: ListView.builder(
itemCount: _list.length,
itemCount: _friendsList.length,
itemBuilder: (c, i) => SimpleUserTile(
user: _list[i],
user: _usersInfo.getUser(_friendsList.elementAt(i)),
onTap: (u) => openUserPage(
context: context,
userID: u.id,