mirror of https://github.com/ppy/osu
Remove duplicated api request
This commit is contained in:
parent
957b33b141
commit
db78b95228
|
@ -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";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,27 +10,32 @@ namespace osu.Game.Online.API.Requests
|
||||||
{
|
{
|
||||||
public class GetCommentsRequest : APIRequest<CommentBundle>
|
public class GetCommentsRequest : APIRequest<CommentBundle>
|
||||||
{
|
{
|
||||||
private readonly long id;
|
private readonly long commentableId;
|
||||||
private readonly int page;
|
|
||||||
private readonly CommentableType type;
|
private readonly CommentableType type;
|
||||||
private readonly CommentsSortCriteria sort;
|
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.type = type;
|
||||||
this.sort = sort;
|
this.sort = sort;
|
||||||
this.id = id;
|
|
||||||
this.page = page;
|
this.page = page;
|
||||||
|
this.parentId = parentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override WebRequest CreateWebRequest()
|
protected override WebRequest CreateWebRequest()
|
||||||
{
|
{
|
||||||
var req = base.CreateWebRequest();
|
var req = base.CreateWebRequest();
|
||||||
|
|
||||||
|
req.AddParameter("commentable_id", commentableId.ToString());
|
||||||
req.AddParameter("commentable_type", type.ToString().Underscore().ToLowerInvariant());
|
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("page", page.ToString());
|
||||||
|
req.AddParameter("sort", sort.ToString().ToLowerInvariant());
|
||||||
|
|
||||||
|
if (parentId != null)
|
||||||
|
req.AddParameter("parent_id", parentId.ToString());
|
||||||
|
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ private void getComments()
|
||||||
|
|
||||||
request?.Cancel();
|
request?.Cancel();
|
||||||
loadCancellation?.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;
|
request.Success += onSuccess;
|
||||||
api.PerformAsync(request);
|
api.PerformAsync(request);
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ private DrawableComment getDrawableComment(Comment comment)
|
||||||
|
|
||||||
private void onCommentRepliesRequested(DrawableComment drawableComment, int page)
|
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));
|
request.Success += response => Schedule(() => appendComments(drawableComment, response));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue