mirror of
https://github.com/osukey/osukey.git
synced 2025-08-02 22:26:41 +09:00
Add ability to load long comment trees in CommentsContainer
This commit is contained in:
45
osu.Game/Online/API/Requests/GetCommentRepliesRequest.cs
Normal file
45
osu.Game/Online/API/Requests/GetCommentRepliesRequest.cs
Normal file
@ -0,0 +1,45 @@
|
||||
// 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";
|
||||
}
|
||||
}
|
@ -4,8 +4,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Users;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Online.API.Requests.Responses
|
||||
{
|
||||
@ -17,8 +15,6 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
[JsonProperty(@"parent_id")]
|
||||
public long? ParentId { get; set; }
|
||||
|
||||
public readonly List<Comment> ChildComments = new List<Comment>();
|
||||
|
||||
public Comment ParentComment { get; set; }
|
||||
|
||||
[JsonProperty(@"user_id")]
|
||||
@ -71,7 +67,5 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
public bool HasMessage => !string.IsNullOrEmpty(Message);
|
||||
|
||||
public bool IsVoted { get; set; }
|
||||
|
||||
public int DeletedChildrenCount => ChildComments.Count(c => c.IsDeleted);
|
||||
}
|
||||
}
|
||||
|
@ -9,31 +9,8 @@ namespace osu.Game.Online.API.Requests.Responses
|
||||
{
|
||||
public class CommentBundle
|
||||
{
|
||||
private List<Comment> comments;
|
||||
|
||||
[JsonProperty(@"comments")]
|
||||
public List<Comment> Comments
|
||||
{
|
||||
get => comments;
|
||||
set
|
||||
{
|
||||
comments = value;
|
||||
comments.ForEach(child =>
|
||||
{
|
||||
if (child.ParentId != null)
|
||||
{
|
||||
comments.ForEach(parent =>
|
||||
{
|
||||
if (parent.Id == child.ParentId)
|
||||
{
|
||||
parent.ChildComments.Add(child);
|
||||
child.ParentComment = parent;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
public List<Comment> Comments { get; set; }
|
||||
|
||||
[JsonProperty(@"has_more")]
|
||||
public bool HasMore { get; set; }
|
||||
|
Reference in New Issue
Block a user