Add support for deleted comments with message

This commit is contained in:
Andrei Zavatski 2019-10-15 12:07:01 +03:00
parent 213f00556d
commit 96e31b9cca
2 changed files with 18 additions and 13 deletions

View File

@ -70,13 +70,9 @@ public class Comment
public bool IsDeleted => DeletedAt.HasValue;
public string GetMessage()
{
if (IsDeleted)
return @"deleted";
public bool HasMessage => !string.IsNullOrEmpty(MessageHtml);
return WebUtility.HtmlDecode(Regex.Replace(MessageHtml, @"<(.|\n)*?>", string.Empty));
}
public string GetMessage => HasMessage ? WebUtility.HtmlDecode(Regex.Replace(MessageHtml, @"<(.|\n)*?>", string.Empty)) : string.Empty;
public int DeletedChildrenCount => ChildComments.Count(c => c.IsDeleted);
}

View File

@ -198,12 +198,13 @@ public DrawableComment(Comment comment)
});
}
if (!comment.IsDeleted)
if (comment.HasMessage)
{
var formattedSource = MessageFormatter.FormatText(comment.GetMessage());
var formattedSource = MessageFormatter.FormatText(comment.GetMessage);
message.AddLinks(formattedSource.Text, formattedSource.Links);
}
else
if (comment.IsDeleted)
{
content.FadeColour(OsuColour.Gray(0.5f));
votePill.Hide();
@ -297,13 +298,13 @@ protected override void OnExpandedChanged(ValueChangedEvent<bool> expanded)
private class ParentUsername : FillFlowContainer, IHasTooltip
{
public string TooltipText => comment.ParentComment?.GetMessage() ?? "";
public string TooltipText => getParentMessage();
private readonly Comment comment;
private readonly Comment parentComment;
public ParentUsername(Comment comment)
{
this.comment = comment;
parentComment = comment.ParentComment;
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
@ -319,10 +320,18 @@ public ParentUsername(Comment comment)
new SpriteText
{
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, italics: true),
Text = comment.ParentComment?.User?.Username ?? comment.ParentComment?.LegacyName
Text = parentComment?.User?.Username ?? parentComment?.LegacyName
}
};
}
private string getParentMessage()
{
if (parentComment == null)
return string.Empty;
return parentComment.HasMessage ? parentComment.GetMessage : parentComment.IsDeleted ? @"deleted" : string.Empty;
}
}
private class VotePill : CircularContainer