mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Avoid a user to appear in its own friends list
This commit is contained in:
parent
6528ef5bc2
commit
f8ba06d0ae
@ -30,11 +30,12 @@ class _OtherUserFriendsListScreenState
|
|||||||
final FriendsHelper friendsHelper = FriendsHelper();
|
final FriendsHelper friendsHelper = FriendsHelper();
|
||||||
final UsersHelper usersHelper = UsersHelper();
|
final UsersHelper usersHelper = UsersHelper();
|
||||||
|
|
||||||
UsersList _list;
|
Set<int> _friendsList;
|
||||||
|
UsersList _usersInfo;
|
||||||
bool _error = false;
|
bool _error = false;
|
||||||
|
|
||||||
String get _routeName => tr("Friends of %name%",
|
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);
|
void setError(bool e) => setState(() => _error = e);
|
||||||
|
|
||||||
@ -49,12 +50,15 @@ class _OtherUserFriendsListScreenState
|
|||||||
setError(false);
|
setError(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final list = await usersHelper
|
final friendsList = await friendsHelper.getOtherUserList(widget.userID);
|
||||||
.getListWithThrow(await friendsHelper.getOtherUserList(widget.userID)
|
|
||||||
..add(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(() {
|
setState(() {
|
||||||
_list = list;
|
_friendsList = friendsList;
|
||||||
|
_usersInfo = users;
|
||||||
});
|
});
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
print(e);
|
print(e);
|
||||||
@ -67,16 +71,16 @@ class _OtherUserFriendsListScreenState
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (_error) return _buildError();
|
if (_error) return _buildError();
|
||||||
|
|
||||||
if (_list == null) return buildCenteredProgressBar();
|
if (_usersInfo == null) return buildCenteredProgressBar();
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(_routeName),
|
title: Text(_routeName),
|
||||||
),
|
),
|
||||||
body: ListView.builder(
|
body: ListView.builder(
|
||||||
itemCount: _list.length,
|
itemCount: _friendsList.length,
|
||||||
itemBuilder: (c, i) => SimpleUserTile(
|
itemBuilder: (c, i) => SimpleUserTile(
|
||||||
user: _list[i],
|
user: _usersInfo.getUser(_friendsList.elementAt(i)),
|
||||||
onTap: (u) => openUserPage(
|
onTap: (u) => openUserPage(
|
||||||
context: context,
|
context: context,
|
||||||
userID: u.id,
|
userID: u.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user