query friends endpoint to fetch friendlist

This commit is contained in:
Aergwyn
2017-12-28 19:32:06 +01:00
parent 0fe78bee6e
commit 66f076815f
4 changed files with 53 additions and 21 deletions

View 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";
}
}

View File

@ -22,7 +22,7 @@ namespace osu.Game.Overlays.Social
public enum SocialSortCriteria public enum SocialSortCriteria
{ {
Rank, Rank,
Location, //Location,
//[Description("Time Zone")] //[Description("Time Zone")]
//TimeZone, //TimeZone,
//[Description("World Map")] //[Description("World Map")]

View File

@ -64,7 +64,7 @@ namespace osu.Game.Overlays
// TODO sort our list in some way (either locally or with API call) // TODO sort our list in some way (either locally or with API call)
//Filter.DisplayStyleControl.Dropdown.Current.ValueChanged += rankStatus => Scheduler.AddOnce(updateSearch); //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 => currentQuery.ValueChanged += v =>
{ {
@ -81,7 +81,7 @@ namespace osu.Game.Overlays
currentQuery.BindTo(Filter.Search.Current); 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 Scheduler.AddOnce(updateSearch); // so it displays something once it's first opened
} }
@ -141,6 +141,7 @@ namespace osu.Game.Overlays
} }
private GetUsersRequest getUsersRequest; private GetUsersRequest getUsersRequest;
private GetFriendsRequest getFriendsRequest;
private readonly Bindable<string> currentQuery = new Bindable<string>(); private readonly Bindable<string> currentQuery = new Bindable<string>();
@ -155,33 +156,50 @@ namespace osu.Game.Overlays
Users = null; Users = null;
loading.Hide(); loading.Hide();
getUsersRequest?.Cancel(); clearRequests();
if (api == null || api.State == APIState.Offline) if (api == null || api.State == APIState.Offline)
return; return;
getUsersRequest = new GetUsersRequest(); // TODO filter/sort values?!? switch (Header.Tabs.Current.Value)
getUsersRequest.Success += response =>
{ {
Task.Run(() => case SocialTab.OnlinePlayers:
{ getUsersRequest = new GetUsersRequest(); // TODO filter???
var newUsers = response.Select(r => r.User); getUsersRequest.Success += response => finishRequest(response.Select(r => r.User));
queueRequest(getUsersRequest);
Schedule(() => break;
{ case SocialTab.OnlineFriends:
Users = newUsers; getFriendsRequest = new GetFriendsRequest(); // TODO filter???
recreatePanels(Filter.DisplayStyleControl.DisplayStyle.Value); getFriendsRequest.Success += finishRequest;
loading.Hide(); queueRequest(getFriendsRequest);
}); break;
}); }
};
loading.Show(); 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 public enum SortDirection
{ {
Descending, Descending,

View File

@ -268,6 +268,7 @@
<Compile Include="Beatmaps\Formats\LegacyStoryboardDecoder.cs" /> <Compile Include="Beatmaps\Formats\LegacyStoryboardDecoder.cs" />
<Compile Include="Database\DatabaseContextFactory.cs" /> <Compile Include="Database\DatabaseContextFactory.cs" />
<Compile Include="Database\IHasPrimaryKey.cs" /> <Compile Include="Database\IHasPrimaryKey.cs" />
<Compile Include="Online\API\Requests\GetFriendsRequest.cs" />
<Compile Include="Overlays\Settings\DangerousSettingsButton.cs" /> <Compile Include="Overlays\Settings\DangerousSettingsButton.cs" />
<Compile Include="Graphics\UserInterface\HoverClickSounds.cs" /> <Compile Include="Graphics\UserInterface\HoverClickSounds.cs" />
<Compile Include="Graphics\UserInterface\HoverSounds.cs" /> <Compile Include="Graphics\UserInterface\HoverSounds.cs" />