computeFriends method
Lists all users where the users have mutually sent a friend request to each other. Use with FriendList.addListener or use it as a Provider and use with FriendList.timeline.whenSynchronized to ensure the local state matches the global state before making further decisions.
Implementation
List<LocalityUser> computeFriends() {
List<LocalityUser> friends = [];
List<FriendRequest> sentFriendRequests = [];
Map<String, FriendRequest> receivedFriendRequestsBySenderID = {};
for (int i = 0; i < friendRequests.length; i++) {
FriendRequest friendRequest = friendRequests[i];
if (friendRequest.sender.id == owner.id) {
sentFriendRequests.add(friendRequest);
} else {
receivedFriendRequestsBySenderID[friendRequest.sender.id] =
friendRequests[i];
}
}
for (int i = 0; i < sentFriendRequests.length; i++) {
FriendRequest friendRequest = sentFriendRequests[i];
if (receivedFriendRequestsBySenderID
.containsKey(friendRequest.recipient)) {
friends.add(friendRequest.recipient);
}
}
return friends;
}