2019-10-07 21:48:05 +08:00
|
|
|
|
// 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 Newtonsoft.Json;
|
2019-10-08 18:45:13 +08:00
|
|
|
|
using osu.Game.Users;
|
2019-10-07 21:48:05 +08:00
|
|
|
|
using System;
|
2019-10-08 20:39:03 +08:00
|
|
|
|
using System.Collections.Generic;
|
2019-10-09 18:37:07 +08:00
|
|
|
|
using System.Linq;
|
2019-10-14 22:02:48 +08:00
|
|
|
|
using System.Net;
|
2019-10-14 21:43:43 +08:00
|
|
|
|
using System.Text.RegularExpressions;
|
2019-10-07 21:48:05 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Online.API.Requests.Responses
|
|
|
|
|
{
|
|
|
|
|
public class Comment
|
|
|
|
|
{
|
|
|
|
|
[JsonProperty(@"id")]
|
|
|
|
|
public long Id { get; set; }
|
|
|
|
|
|
2019-10-07 21:58:24 +08:00
|
|
|
|
private long? parentId;
|
|
|
|
|
|
2019-10-07 21:48:05 +08:00
|
|
|
|
[JsonProperty(@"parent_id")]
|
2019-10-07 21:58:24 +08:00
|
|
|
|
public long? ParentId
|
|
|
|
|
{
|
|
|
|
|
get => parentId;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
parentId = value;
|
2019-10-07 23:45:22 +08:00
|
|
|
|
IsTopLevel = value == null;
|
2019-10-07 21:58:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-07 21:48:05 +08:00
|
|
|
|
|
2019-10-08 20:39:03 +08:00
|
|
|
|
public List<Comment> ChildComments = new List<Comment>();
|
|
|
|
|
|
2019-10-09 00:09:02 +08:00
|
|
|
|
public Comment ParentComment { get; set; }
|
|
|
|
|
|
2019-10-07 21:48:05 +08:00
|
|
|
|
[JsonProperty(@"user_id")]
|
2019-10-09 03:46:42 +08:00
|
|
|
|
public long? UserId { get; set; }
|
2019-10-07 21:48:05 +08:00
|
|
|
|
|
2019-10-08 18:45:13 +08:00
|
|
|
|
public User User { get; set; }
|
|
|
|
|
|
2019-10-07 21:48:05 +08:00
|
|
|
|
[JsonProperty(@"message")]
|
|
|
|
|
public string Message { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"message_html")]
|
2019-10-14 22:33:14 +08:00
|
|
|
|
public string MessageHtml { get; set; }
|
2019-10-07 21:48:05 +08:00
|
|
|
|
|
|
|
|
|
[JsonProperty(@"replies_count")]
|
|
|
|
|
public int RepliesCount { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"votes_count")]
|
|
|
|
|
public int VotesCount { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"commenatble_type")]
|
|
|
|
|
public string CommentableType { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"commentable_id")]
|
|
|
|
|
public int CommentableId { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"legacy_name")]
|
|
|
|
|
public string LegacyName { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"created_at")]
|
|
|
|
|
public DateTimeOffset CreatedAt { get; set; }
|
|
|
|
|
|
|
|
|
|
[JsonProperty(@"updated_at")]
|
2019-10-07 23:26:07 +08:00
|
|
|
|
public DateTimeOffset? UpdatedAt { get; set; }
|
2019-10-07 21:48:05 +08:00
|
|
|
|
|
2019-10-07 23:45:22 +08:00
|
|
|
|
private DateTimeOffset? deletedAt;
|
|
|
|
|
|
2019-10-07 21:48:05 +08:00
|
|
|
|
[JsonProperty(@"deleted_at")]
|
2019-10-07 23:45:22 +08:00
|
|
|
|
public DateTimeOffset? DeletedAt
|
|
|
|
|
{
|
|
|
|
|
get => deletedAt;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
deletedAt = value;
|
|
|
|
|
IsDeleted = value != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-07 21:48:05 +08:00
|
|
|
|
|
|
|
|
|
[JsonProperty(@"edited_at")]
|
2019-10-07 23:26:07 +08:00
|
|
|
|
public DateTimeOffset? EditedAt { get; set; }
|
2019-10-07 21:48:05 +08:00
|
|
|
|
|
|
|
|
|
[JsonProperty(@"edited_by_id")]
|
2019-10-07 23:26:07 +08:00
|
|
|
|
public long? EditedById { get; set; }
|
2019-10-07 21:58:24 +08:00
|
|
|
|
|
2019-10-09 16:32:17 +08:00
|
|
|
|
public User EditedUser { get; set; }
|
|
|
|
|
|
2019-10-07 21:58:24 +08:00
|
|
|
|
public bool IsTopLevel { get; set; }
|
2019-10-07 23:45:22 +08:00
|
|
|
|
|
|
|
|
|
public bool IsDeleted { get; set; }
|
2019-10-08 18:31:49 +08:00
|
|
|
|
|
|
|
|
|
public string GetMessage()
|
|
|
|
|
{
|
2019-10-14 21:43:43 +08:00
|
|
|
|
if (IsDeleted)
|
|
|
|
|
return @"deleted";
|
|
|
|
|
|
2019-10-14 22:33:14 +08:00
|
|
|
|
return WebUtility.HtmlDecode(Regex.Replace(MessageHtml, @"<(.|\n)*?>", string.Empty));
|
2019-10-08 18:31:49 +08:00
|
|
|
|
}
|
2019-10-09 18:37:07 +08:00
|
|
|
|
|
|
|
|
|
public int GetDeletedChildsCount()
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
|
|
if (ChildComments.Any())
|
|
|
|
|
ChildComments.ForEach(child =>
|
|
|
|
|
{
|
|
|
|
|
if (child.IsDeleted)
|
|
|
|
|
count++;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
2019-10-07 21:48:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|