Parse child comments

This commit is contained in:
Andrei Zavatski 2019-10-08 15:39:03 +03:00
parent 2564214a72
commit 451a7342ce
4 changed files with 92 additions and 43 deletions

View File

@ -9,8 +9,28 @@ namespace osu.Game.Online.API.Requests.Responses
{ {
public class APIComments public class APIComments
{ {
private List<Comment> comments;
[JsonProperty(@"comments")] [JsonProperty(@"comments")]
public List<Comment> Comments { get; set; } 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);
});
}
});
}
}
[JsonProperty(@"has_more")] [JsonProperty(@"has_more")]
public bool HasMore { get; set; } public bool HasMore { get; set; }

View File

@ -4,6 +4,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Game.Users; using osu.Game.Users;
using System; using System;
using System.Collections.Generic;
namespace osu.Game.Online.API.Requests.Responses namespace osu.Game.Online.API.Requests.Responses
{ {
@ -25,6 +26,8 @@ namespace osu.Game.Online.API.Requests.Responses
} }
} }
public List<Comment> ChildComments = new List<Comment>();
[JsonProperty(@"user_id")] [JsonProperty(@"user_id")]
public long UserId { get; set; } public long UserId { get; set; }

View File

@ -17,6 +17,8 @@ namespace osu.Game.Overlays.Comments
{ {
public class CommentsContainer : CompositeDrawable public class CommentsContainer : CompositeDrawable
{ {
private const float separator_height = 1.5f;
private readonly CommentableType type; private readonly CommentableType type;
private readonly long id; private readonly long id;
@ -97,7 +99,7 @@ namespace osu.Game.Overlays.Comments
new Container new Container
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 1, Height = separator_height,
Child = new Box Child = new Box
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,

View File

@ -17,78 +17,102 @@ namespace osu.Game.Overlays.Comments
{ {
private const int avatar_size = 40; private const int avatar_size = 40;
private const int margin = 10; private const int margin = 10;
private const int child_margin = 20;
public DrawableComment(Comment comment) public DrawableComment(Comment comment)
{ {
LinkFlowContainer username; LinkFlowContainer username;
FillFlowContainer childCommentsContainer;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
InternalChild = new GridContainer InternalChild = new FillFlowContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Margin = new MarginPadding(margin), Direction = FillDirection.Vertical,
ColumnDimensions = new[] Children = new Drawable[]
{ {
new Dimension(GridSizeMode.AutoSize), new GridContainer
new Dimension(),
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize)
},
Content = new[]
{
new Drawable[]
{ {
new UpdateableAvatar(comment.User) RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding(margin),
ColumnDimensions = new[]
{ {
Size = new Vector2(avatar_size), new Dimension(GridSizeMode.AutoSize),
Margin = new MarginPadding { Horizontal = margin }, new Dimension(),
Masking = true,
CornerRadius = avatar_size / 2,
}, },
new FillFlowContainer RowDimensions = new[]
{ {
RelativeSizeAxes = Axes.X, new Dimension(GridSizeMode.AutoSize),
AutoSizeAxes = Axes.Y, new Dimension(GridSizeMode.AutoSize)
Margin = new MarginPadding { Top = margin / 2 }, },
Spacing = new Vector2(0, 2), Content = new[]
Children = new Drawable[] {
new Drawable[]
{ {
username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true)) new UpdateableAvatar(comment.User)
{ {
AutoSizeAxes = Axes.Both, Size = new Vector2(avatar_size),
Margin = new MarginPadding { Horizontal = margin },
Masking = true,
CornerRadius = avatar_size / 2,
}, },
new TextFlowContainer(s => s.Font = OsuFont.GetFont(size: 14)) new FillFlowContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Text = comment.GetMessage() Margin = new MarginPadding { Top = margin / 2 },
Spacing = new Vector2(0, 2),
Children = new Drawable[]
{
username = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true))
{
AutoSizeAxes = Axes.Both,
},
new TextFlowContainer(s => s.Font = OsuFont.GetFont(size: 14))
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Text = comment.GetMessage()
}
}
}
},
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
},
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: 12),
Text = HumanizerUtils.Humanize(comment.CreatedAt)
} }
} }
} }
}, },
new Drawable[] childCommentsContainer = new FillFlowContainer
{ {
new Container Margin = new MarginPadding { Left = child_margin },
{ RelativeSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Both, AutoSizeAxes = Axes.Y,
}, Direction = FillDirection.Vertical
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.GetFont(size: 12),
Text = HumanizerUtils.Humanize(comment.CreatedAt)
}
} }
} }
}; };
username.AddUserLink(comment.User); username.AddUserLink(comment.User);
comment.ChildComments.ForEach(c =>
{
if (!c.IsDeleted)
childCommentsContainer.Add(new DrawableComment(c));
});
} }
} }
} }