mirror of
https://github.com/ppy/osu.git
synced 2025-02-22 14:42:54 +08:00
Fix existing friend logic
This commit is contained in:
parent
bf53833b7b
commit
69b5bd3b50
@ -57,7 +57,7 @@ namespace osu.Game.Online.API
|
||||
private string password;
|
||||
|
||||
public IBindable<APIUser> LocalUser => localUser;
|
||||
public IBindableList<APIUser> Friends => friends;
|
||||
public IBindableList<APIRelation> Friends => friends;
|
||||
public IBindable<UserActivity> Activity => activity;
|
||||
public IBindable<UserStatistics> Statistics => statistics;
|
||||
|
||||
@ -67,7 +67,7 @@ namespace osu.Game.Online.API
|
||||
|
||||
private Bindable<APIUser> localUser { get; } = new Bindable<APIUser>(createGuestUser());
|
||||
|
||||
private BindableList<APIUser> friends { get; } = new BindableList<APIUser>();
|
||||
private BindableList<APIRelation> friends { get; } = new BindableList<APIRelation>();
|
||||
|
||||
private Bindable<UserActivity> activity { get; } = new Bindable<UserActivity>();
|
||||
|
||||
@ -360,19 +360,7 @@ namespace osu.Game.Online.API
|
||||
}
|
||||
}
|
||||
|
||||
var friendsReq = new GetFriendsRequest();
|
||||
friendsReq.Failure += _ => state.Value = APIState.Failing;
|
||||
friendsReq.Success += res =>
|
||||
{
|
||||
friends.Clear();
|
||||
friends.AddRange(res);
|
||||
};
|
||||
|
||||
if (!handleRequest(friendsReq))
|
||||
{
|
||||
state.Value = APIState.Failing;
|
||||
return;
|
||||
}
|
||||
UpdateLocalFriends();
|
||||
|
||||
// The Success callback event is fired on the main thread, so we should wait for that to run before proceeding.
|
||||
// Without this, we will end up circulating this Connecting loop multiple times and queueing up many web requests
|
||||
@ -624,6 +612,22 @@ namespace osu.Game.Online.API
|
||||
localUser.Value.Statistics = newStatistics;
|
||||
}
|
||||
|
||||
public void UpdateLocalFriends()
|
||||
{
|
||||
if (!IsLoggedIn)
|
||||
return;
|
||||
|
||||
var friendsReq = new GetFriendsRequest();
|
||||
friendsReq.Failure += _ => state.Value = APIState.Failing;
|
||||
friendsReq.Success += res =>
|
||||
{
|
||||
friends.Clear();
|
||||
friends.AddRange(res);
|
||||
};
|
||||
|
||||
Queue(friendsReq);
|
||||
}
|
||||
|
||||
private static APIUser createGuestUser() => new GuestUser();
|
||||
|
||||
private void setLocalUser(APIUser user) => Scheduler.Add(() =>
|
||||
|
@ -26,7 +26,7 @@ namespace osu.Game.Online.API
|
||||
Id = DUMMY_USER_ID,
|
||||
});
|
||||
|
||||
public BindableList<APIUser> Friends { get; } = new BindableList<APIUser>();
|
||||
public BindableList<APIRelation> Friends { get; } = new BindableList<APIRelation>();
|
||||
|
||||
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
|
||||
|
||||
@ -201,6 +201,10 @@ namespace osu.Game.Online.API
|
||||
LocalUser.Value.Statistics = newStatistics;
|
||||
}
|
||||
|
||||
public void UpdateLocalFriends()
|
||||
{
|
||||
}
|
||||
|
||||
public IHubClientConnector? GetHubConnector(string clientName, string endpoint, bool preferMessagePack) => null;
|
||||
|
||||
public IChatClient GetChatClient() => new TestChatClientConnector(this);
|
||||
@ -214,7 +218,7 @@ namespace osu.Game.Online.API
|
||||
public void SetState(APIState newState) => state.Value = newState;
|
||||
|
||||
IBindable<APIUser> IAPIProvider.LocalUser => LocalUser;
|
||||
IBindableList<APIUser> IAPIProvider.Friends => Friends;
|
||||
IBindableList<APIRelation> IAPIProvider.Friends => Friends;
|
||||
IBindable<UserActivity> IAPIProvider.Activity => Activity;
|
||||
IBindable<UserStatistics?> IAPIProvider.Statistics => Statistics;
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace osu.Game.Online.API
|
||||
/// <summary>
|
||||
/// The user's friends.
|
||||
/// </summary>
|
||||
IBindableList<APIUser> Friends { get; }
|
||||
IBindableList<APIRelation> Friends { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The current user's activity.
|
||||
@ -134,6 +134,11 @@ namespace osu.Game.Online.API
|
||||
/// </summary>
|
||||
void UpdateStatistics(UserStatistics newStatistics);
|
||||
|
||||
/// <summary>
|
||||
/// Update the friends status of the current user.
|
||||
/// </summary>
|
||||
void UpdateLocalFriends();
|
||||
|
||||
/// <summary>
|
||||
/// Schedule a callback to run on the update thread.
|
||||
/// </summary>
|
||||
|
@ -44,7 +44,7 @@ namespace osu.Game.Overlays.Dashboard.Friends
|
||||
private Container itemsPlaceholder;
|
||||
private LoadingLayer loading;
|
||||
|
||||
private readonly IBindableList<APIUser> apiFriends = new BindableList<APIUser>();
|
||||
private readonly IBindableList<APIRelation> apiFriends = new BindableList<APIRelation>();
|
||||
|
||||
public FriendDisplay()
|
||||
{
|
||||
@ -145,7 +145,7 @@ namespace osu.Game.Overlays.Dashboard.Friends
|
||||
controlBackground.Colour = colourProvider.Background5;
|
||||
|
||||
apiFriends.BindTo(api.Friends);
|
||||
apiFriends.BindCollectionChanged((_, _) => Schedule(() => Users = apiFriends.ToList()), true);
|
||||
apiFriends.BindCollectionChanged((_, _) => Schedule(() => Users = apiFriends.Select(f => f.TargetUser).ToList()), true);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
|
@ -316,7 +316,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
HasQuit.BindValueChanged(_ => updateState());
|
||||
|
||||
isFriend = User != null && api.Friends.Any(u => User.OnlineID == u.Id);
|
||||
isFriend = User != null && api.Friends.Any(u => User.OnlineID == u.TargetID);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
|
Loading…
Reference in New Issue
Block a user