Use response params in next page request

This commit is contained in:
smoogipoo
2020-07-28 21:40:11 +09:00
parent 9f6446d836
commit db91d1de50
4 changed files with 53 additions and 47 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using JetBrains.Annotations;
using osu.Framework.IO.Network;
using osu.Game.Extensions;
using osu.Game.Online.API;
@ -16,31 +17,31 @@ namespace osu.Game.Online.Multiplayer
private readonly int roomId;
private readonly int playlistItemId;
private readonly Cursor cursor;
private readonly MultiplayerScoresSort? sort;
private readonly IndexScoresParams indexParams;
public IndexPlaylistScoresRequest(int roomId, int playlistItemId, Cursor cursor = null, MultiplayerScoresSort? sort = null)
public IndexPlaylistScoresRequest(int roomId, int playlistItemId)
{
this.roomId = roomId;
this.playlistItemId = playlistItemId;
}
public IndexPlaylistScoresRequest(int roomId, int playlistItemId, [NotNull] Cursor cursor, [NotNull] IndexScoresParams indexParams)
: this(roomId, playlistItemId)
{
this.cursor = cursor;
this.sort = sort;
this.indexParams = indexParams;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.AddCursor(cursor);
switch (sort)
if (cursor != null)
{
case MultiplayerScoresSort.Ascending:
req.AddParameter("sort", "score_asc");
break;
req.AddCursor(cursor);
case MultiplayerScoresSort.Descending:
req.AddParameter("sort", "score_desc");
break;
foreach (var (key, value) in indexParams.Properties)
req.AddParameter(key, value.ToString());
}
return req;

View File

@ -0,0 +1,20 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using JetBrains.Annotations;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace osu.Game.Online.Multiplayer
{
/// <summary>
/// A collection of parameters which should be passed to the index endpoint to fetch the next page.
/// </summary>
public class IndexScoresParams
{
[UsedImplicitly]
[JsonExtensionData]
public IDictionary<string, JToken> Properties;
}
}

View File

@ -29,5 +29,11 @@ namespace osu.Game.Online.Multiplayer
/// </summary>
[JsonProperty("user_score")]
public MultiplayerScore UserScore { get; set; }
/// <summary>
/// The parameters to be used to fetch the next page.
/// </summary>
[JsonProperty("params")]
public IndexScoresParams Params { get; set; }
}
}