mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 14:17:26 +08:00
query friends endpoint to fetch friendlist
This commit is contained in:
parent
0fe78bee6e
commit
66f076815f
13
osu.Game/Online/API/Requests/GetFriendsRequest.cs
Normal file
13
osu.Game/Online/API/Requests/GetFriendsRequest.cs
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetFriendsRequest : APIRequest<List<User>>
|
||||
{
|
||||
protected override string Target => @"friends";
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ namespace osu.Game.Overlays.Social
|
||||
public enum SocialSortCriteria
|
||||
{
|
||||
Rank,
|
||||
Location,
|
||||
//Location,
|
||||
//[Description("Time Zone")]
|
||||
//TimeZone,
|
||||
//[Description("World Map")]
|
||||
|
@ -64,7 +64,7 @@ namespace osu.Game.Overlays
|
||||
// TODO sort our list in some way (either locally or with API call)
|
||||
//Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += rankStatus => Scheduler.AddOnce(updateSearch);
|
||||
|
||||
Header.Tabs.Current.ValueChanged += _ => Scheduler.AddOnce(updateSearch);
|
||||
Header.Tabs.Current.ValueChanged += tab => Scheduler.AddOnce(updateSearch);
|
||||
|
||||
currentQuery.ValueChanged += v =>
|
||||
{
|
||||
@ -81,7 +81,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
currentQuery.BindTo(Filter.Search.Current);
|
||||
|
||||
Filter.Tabs.Current.ValueChanged += _ => Scheduler.AddOnce(updateSearch);
|
||||
Filter.Tabs.Current.ValueChanged += sortCriteria => Scheduler.AddOnce(updateSearch);
|
||||
|
||||
Scheduler.AddOnce(updateSearch); // so it displays something once it's first opened
|
||||
}
|
||||
@ -141,6 +141,7 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
|
||||
private GetUsersRequest getUsersRequest;
|
||||
private GetFriendsRequest getFriendsRequest;
|
||||
|
||||
private readonly Bindable<string> currentQuery = new Bindable<string>();
|
||||
|
||||
@ -155,33 +156,50 @@ namespace osu.Game.Overlays
|
||||
|
||||
Users = null;
|
||||
loading.Hide();
|
||||
getUsersRequest?.Cancel();
|
||||
clearRequests();
|
||||
|
||||
if (api == null || api.State == APIState.Offline)
|
||||
return;
|
||||
|
||||
getUsersRequest = new GetUsersRequest(); // TODO filter/sort values?!?
|
||||
|
||||
getUsersRequest.Success += response =>
|
||||
switch (Header.Tabs.Current.Value)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
var newUsers = response.Select(r => r.User);
|
||||
|
||||
Schedule(() =>
|
||||
{
|
||||
Users = newUsers;
|
||||
recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value);
|
||||
loading.Hide();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
case SocialTab.OnlinePlayers:
|
||||
getUsersRequest = new GetUsersRequest(); // TODO filter???
|
||||
getUsersRequest.Success += response => finishRequest(response.Select(r => r.User));
|
||||
queueRequest(getUsersRequest);
|
||||
break;
|
||||
case SocialTab.OnlineFriends:
|
||||
getFriendsRequest = new GetFriendsRequest(); // TODO filter???
|
||||
getFriendsRequest.Success += finishRequest;
|
||||
queueRequest(getFriendsRequest);
|
||||
break;
|
||||
}
|
||||
loading.Show();
|
||||
api.Queue(getUsersRequest);
|
||||
}
|
||||
|
||||
private void clearRequests()
|
||||
{
|
||||
getUsersRequest?.Cancel();
|
||||
getFriendsRequest?.Cancel();
|
||||
}
|
||||
|
||||
private void finishRequest(IEnumerable<User> newUsers)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
Schedule(() =>
|
||||
{
|
||||
Users = newUsers;
|
||||
recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value);
|
||||
loading.Hide();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void queueRequest(APIRequest request) => api.Queue(request);
|
||||
}
|
||||
|
||||
|
||||
public enum SortDirection
|
||||
{
|
||||
Descending,
|
||||
|
@ -268,6 +268,7 @@
|
||||
<Compile Include="Beatmaps\Formats\LegacyStoryboardDecoder.cs" />
|
||||
<Compile Include="Database\DatabaseContextFactory.cs" />
|
||||
<Compile Include="Database\IHasPrimaryKey.cs" />
|
||||
<Compile Include="Online\API\Requests\GetFriendsRequest.cs" />
|
||||
<Compile Include="Overlays\Settings\DangerousSettingsButton.cs" />
|
||||
<Compile Include="Graphics\UserInterface\HoverClickSounds.cs" />
|
||||
<Compile Include="Graphics\UserInterface\HoverSounds.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user