mirror of
https://github.com/ppy/osu.git
synced 2025-01-18 10:02:54 +08:00
Simplify operations on local list
This commit is contained in:
parent
7268b2e077
commit
51c7c218bf
@ -612,14 +612,14 @@ namespace osu.Game.Online.API
|
||||
friendsReq.Failure += _ => state.Value = APIState.Failing;
|
||||
friendsReq.Success += res =>
|
||||
{
|
||||
// Add new friends into local list.
|
||||
HashSet<int> friendsSet = friends.Select(f => f.TargetID).ToHashSet();
|
||||
friends.AddRange(res.Where(f => !friendsSet.Contains(f.TargetID)));
|
||||
var existingFriends = friends.Select(f => f.TargetID).ToHashSet();
|
||||
var updatedFriends = res.Select(f => f.TargetID).ToHashSet();
|
||||
|
||||
// Remove non-friends from local lists.
|
||||
friendsSet.Clear();
|
||||
friendsSet.AddRange(res.Select(f => f.TargetID));
|
||||
friends.RemoveAll(f => !friendsSet.Contains(f.TargetID));
|
||||
// Add new friends into local list.
|
||||
friends.AddRange(res.Where(r => !existingFriends.Contains(r.TargetID)));
|
||||
|
||||
// Remove non-friends from local list.
|
||||
friends.RemoveAll(f => !updatedFriends.Contains(f.TargetID));
|
||||
};
|
||||
|
||||
Queue(friendsReq);
|
||||
|
Loading…
Reference in New Issue
Block a user