1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 16:32:54 +08:00

Add friends list to API providers

This commit is contained in:
Salman Ahmed 2020-12-17 13:30:55 +03:00
parent 76ffe31855
commit 78ce6f1cd2
3 changed files with 25 additions and 2 deletions

View File

@ -41,6 +41,8 @@ namespace osu.Game.Online.API
public Bindable<User> LocalUser { get; } = new Bindable<User>(createGuestUser()); public Bindable<User> LocalUser { get; } = new Bindable<User>(createGuestUser());
public BindableList<User> Friends { get; } = new BindableList<User>();
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>(); public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password)); protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
@ -143,6 +145,10 @@ namespace osu.Game.Online.API
failureCount = 0; failureCount = 0;
var friendsReq = new GetFriendsRequest();
friendsReq.Success += f => Friends.AddRange(f);
handleRequest(friendsReq);
//we're connected! //we're connected!
state.Value = APIState.Online; state.Value = APIState.Online;
}; };
@ -352,8 +358,12 @@ namespace osu.Game.Online.API
password = null; password = null;
authentication.Clear(); authentication.Clear();
// Scheduled prior to state change such that the state changed event is invoked with the correct user present // Scheduled prior to state change such that the state changed event is invoked with the correct user and their friends present
Schedule(() => LocalUser.Value = createGuestUser()); Schedule(() =>
{
LocalUser.Value = createGuestUser();
Friends.Clear();
});
state.Value = APIState.Offline; state.Value = APIState.Offline;
} }

View File

@ -5,6 +5,7 @@ using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Users; using osu.Game.Users;
@ -18,6 +19,12 @@ namespace osu.Game.Online.API
Id = 1001, Id = 1001,
}); });
public BindableList<User> Friends { get; } = new BindableList<User>(new User
{
Username = @"Dummy's friend",
Id = 2002,
}.Yield());
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>(); public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>();
public string AccessToken => "token"; public string AccessToken => "token";

View File

@ -15,6 +15,12 @@ namespace osu.Game.Online.API
/// </summary> /// </summary>
Bindable<User> LocalUser { get; } Bindable<User> LocalUser { get; }
/// <summary>
/// The user's friends.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// </summary>
BindableList<User> Friends { get; }
/// <summary> /// <summary>
/// The current user's activity. /// The current user's activity.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component. /// This is not thread-safe and should be scheduled locally if consumed from a drawable component.