1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 21:27:24 +08:00

Remove duplicated api request

This commit is contained in:
smoogipoo 2020-02-21 18:42:11 +09:00
parent 957b33b141
commit db78b95228
4 changed files with 13 additions and 53 deletions

View File

@ -1,45 +0,0 @@
// 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 Humanizer;
using osu.Framework.IO.Network;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Comments;
namespace osu.Game.Online.API.Requests
{
public class GetCommentRepliesRequest : APIRequest<CommentBundle>
{
private readonly long commentId;
private readonly CommentableType commentableType;
private readonly long commentableId;
private readonly int page;
private readonly CommentsSortCriteria sort;
public GetCommentRepliesRequest(long commentId, CommentableType commentableType, long commentableId, CommentsSortCriteria sort, int page)
{
this.commentId = commentId;
this.page = page;
this.sort = sort;
// These parameters are necessary to get deleted comments
this.commentableType = commentableType;
this.commentableId = commentableId;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.AddParameter("parent_id", commentId.ToString());
req.AddParameter("sort", sort.ToString().ToLowerInvariant());
req.AddParameter("commentable_type", commentableType.ToString().Underscore().ToLowerInvariant());
req.AddParameter("commentable_id", commentableId.ToString());
req.AddParameter("page", page.ToString());
return req;
}
protected override string Target => "comments";
}
}

View File

@ -10,27 +10,32 @@ namespace osu.Game.Online.API.Requests
{
public class GetCommentsRequest : APIRequest<CommentBundle>
{
private readonly long id;
private readonly int page;
private readonly long commentableId;
private readonly CommentableType type;
private readonly CommentsSortCriteria sort;
private readonly int page;
private readonly long? parentId;
public GetCommentsRequest(CommentableType type, long id, CommentsSortCriteria sort = CommentsSortCriteria.New, int page = 1)
public GetCommentsRequest(long commentableId, CommentableType type, CommentsSortCriteria sort = CommentsSortCriteria.New, int page = 1, long? parentId = null)
{
this.commentableId = commentableId;
this.type = type;
this.sort = sort;
this.id = id;
this.page = page;
this.parentId = parentId;
}
protected override WebRequest CreateWebRequest()
{
var req = base.CreateWebRequest();
req.AddParameter("commentable_id", commentableId.ToString());
req.AddParameter("commentable_type", type.ToString().Underscore().ToLowerInvariant());
req.AddParameter("commentable_id", id.ToString());
req.AddParameter("sort", sort.ToString().ToLowerInvariant());
req.AddParameter("page", page.ToString());
req.AddParameter("sort", sort.ToString().ToLowerInvariant());
if (parentId != null)
req.AddParameter("parent_id", parentId.ToString());
return req;
}

View File

@ -152,7 +152,7 @@ namespace osu.Game.Overlays.Comments
request?.Cancel();
loadCancellation?.Cancel();
request = new GetCommentsRequest(type.Value, id.Value, Sort.Value, currentPage++);
request = new GetCommentsRequest(id.Value, type.Value, Sort.Value, currentPage++, 0);
request.Success += onSuccess;
api.PerformAsync(request);
}

View File

@ -123,7 +123,7 @@ namespace osu.Game.Overlays.Comments
private void onCommentRepliesRequested(DrawableComment drawableComment, int page)
{
var request = new GetCommentRepliesRequest(drawableComment.Comment.Id, Type.Value, CommentableId.Value, Sort.Value, page);
var request = new GetCommentsRequest(CommentableId.Value, Type.Value, Sort.Value, page, drawableComment.Comment.Id);
request.Success += response => Schedule(() => appendComments(drawableComment, response));