2019-10-08 19:51:12 +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 osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osuTK;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using osu.Game.Users.Drawables;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-10-09 00:18:46 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2019-10-09 16:07:56 +08:00
|
|
|
|
using System.Linq;
|
2019-11-25 10:30:55 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-01-07 01:56:32 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-02-10 20:43:11 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-02-13 07:21:13 +08:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2020-02-18 18:37:59 +08:00
|
|
|
|
using System.Collections.Specialized;
|
2022-12-16 17:16:26 +08:00
|
|
|
|
using System.Diagnostics;
|
2022-12-19 12:10:22 +08:00
|
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2023-01-18 22:30:34 +08:00
|
|
|
|
using osu.Framework.Logging;
|
2022-10-14 03:18:26 +08:00
|
|
|
|
using osu.Framework.Platform;
|
2022-09-28 22:49:37 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-09-27 23:23:15 +08:00
|
|
|
|
using osu.Game.Online.API;
|
2022-09-27 23:33:16 +08:00
|
|
|
|
using osu.Game.Online.API.Requests;
|
2020-07-11 13:01:11 +08:00
|
|
|
|
using osu.Game.Overlays.Comments.Buttons;
|
2022-09-27 23:33:16 +08:00
|
|
|
|
using osu.Game.Overlays.Dialog;
|
2022-10-17 00:57:21 +08:00
|
|
|
|
using osu.Game.Overlays.OSD;
|
2021-08-08 18:21:29 +08:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2019-10-08 19:51:12 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Comments
|
|
|
|
|
{
|
2022-10-20 23:47:42 +08:00
|
|
|
|
[Cached]
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class DrawableComment : CompositeDrawable
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
|
|
|
|
private const int avatar_size = 40;
|
2019-10-09 17:18:49 +08:00
|
|
|
|
|
2022-10-08 22:11:09 +08:00
|
|
|
|
public Action<DrawableComment, int> RepliesRequested = null!;
|
2020-02-10 20:43:11 +08:00
|
|
|
|
|
|
|
|
|
public readonly Comment Comment;
|
2024-02-14 08:46:19 +08:00
|
|
|
|
public readonly IReadOnlyList<CommentableMeta> Meta;
|
2020-02-10 20:43:11 +08:00
|
|
|
|
|
2019-10-09 17:18:49 +08:00
|
|
|
|
public readonly BindableBool ShowDeleted = new BindableBool();
|
2020-02-10 20:43:11 +08:00
|
|
|
|
public readonly Bindable<CommentsSortCriteria> Sort = new Bindable<CommentsSortCriteria>();
|
2020-02-13 07:37:41 +08:00
|
|
|
|
private readonly Dictionary<long, Comment> loadedReplies = new Dictionary<long, Comment>();
|
2019-10-08 21:00:34 +08:00
|
|
|
|
|
2020-02-13 07:47:13 +08:00
|
|
|
|
public readonly BindableList<DrawableComment> Replies = new BindableList<DrawableComment>();
|
2020-02-13 05:19:21 +08:00
|
|
|
|
|
2019-10-15 05:32:21 +08:00
|
|
|
|
private readonly BindableBool childrenExpanded = new BindableBool(true);
|
2019-10-08 21:00:34 +08:00
|
|
|
|
|
2020-02-10 20:43:11 +08:00
|
|
|
|
private int currentPage;
|
|
|
|
|
|
2022-10-08 23:41:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Local field for tracking comment state. Initialized from Comment.IsDeleted, may change when deleting was requested by user.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool WasDeleted { get; protected set; }
|
|
|
|
|
|
2023-01-18 07:11:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tracks this comment's level of nesting. 0 means that this comment has no parents.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Level { get; private set; }
|
|
|
|
|
|
2022-10-08 22:11:09 +08:00
|
|
|
|
private FillFlowContainer childCommentsVisibilityContainer = null!;
|
|
|
|
|
private FillFlowContainer childCommentsContainer = null!;
|
|
|
|
|
private LoadRepliesButton loadRepliesButton = null!;
|
|
|
|
|
private ShowMoreRepliesButton showMoreButton = null!;
|
|
|
|
|
private ShowRepliesButton showRepliesButton = null!;
|
|
|
|
|
private ChevronButton chevronButton = null!;
|
|
|
|
|
private LinkFlowContainer actionsContainer = null!;
|
|
|
|
|
private LoadingSpinner actionsLoading = null!;
|
|
|
|
|
private DeletedCommentsCounter deletedCommentsCounter = null!;
|
2024-02-14 08:38:49 +08:00
|
|
|
|
private CommentAuthorLine author = null!;
|
2022-10-08 23:41:08 +08:00
|
|
|
|
private GridContainer content = null!;
|
|
|
|
|
private VotePill votePill = null!;
|
2023-01-19 01:50:07 +08:00
|
|
|
|
private Container<CommentEditor> replyEditorContainer = null!;
|
2023-02-03 16:47:10 +08:00
|
|
|
|
private Container repliesButtonContainer = null!;
|
2019-10-08 19:51:12 +08:00
|
|
|
|
|
2023-01-18 07:10:02 +08:00
|
|
|
|
[Resolved]
|
2022-10-08 22:11:09 +08:00
|
|
|
|
private IDialogOverlay? dialogOverlay { get; set; }
|
2022-09-28 03:46:23 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
2022-10-08 22:11:09 +08:00
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2022-09-28 03:46:23 +08:00
|
|
|
|
|
2022-10-14 03:18:26 +08:00
|
|
|
|
[Resolved]
|
2023-07-11 17:42:31 +08:00
|
|
|
|
private Clipboard clipboard { get; set; } = null!;
|
2022-10-14 03:18:26 +08:00
|
|
|
|
|
2023-01-18 07:10:02 +08:00
|
|
|
|
[Resolved]
|
2022-10-17 00:57:21 +08:00
|
|
|
|
private OnScreenDisplay? onScreenDisplay { get; set; }
|
2022-10-14 21:26:25 +08:00
|
|
|
|
|
2024-02-14 08:46:19 +08:00
|
|
|
|
public DrawableComment(Comment comment, IReadOnlyList<CommentableMeta> meta)
|
2020-01-07 01:56:32 +08:00
|
|
|
|
{
|
2020-02-10 20:43:11 +08:00
|
|
|
|
Comment = comment;
|
2024-02-14 08:46:19 +08:00
|
|
|
|
Meta = meta;
|
2020-01-07 01:56:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2023-01-18 07:11:07 +08:00
|
|
|
|
private void load(OverlayColourProvider colourProvider, DrawableComment? parentComment)
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2019-10-09 16:32:17 +08:00
|
|
|
|
FillFlowContainer info;
|
2021-07-26 19:18:55 +08:00
|
|
|
|
CommentMarkdownContainer message;
|
2019-10-09 17:18:49 +08:00
|
|
|
|
|
2023-01-18 07:11:07 +08:00
|
|
|
|
Level = parentComment?.Level + 1 ?? 0;
|
|
|
|
|
|
|
|
|
|
float childrenPadding = Level < 6 ? 20 : 5;
|
|
|
|
|
|
2019-10-08 19:51:12 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2020-02-10 20:43:11 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2020-07-28 07:36:25 +08:00
|
|
|
|
new Container
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2020-02-10 20:43:11 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-07-28 07:36:25 +08:00
|
|
|
|
Padding = getPadding(Comment.IsTopLevel),
|
|
|
|
|
Child = new FillFlowContainer
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2020-07-28 07:36:25 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = new Drawable[]
|
2019-10-08 20:39:03 +08:00
|
|
|
|
{
|
2020-07-28 07:36:25 +08:00
|
|
|
|
content = new GridContainer
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2020-02-10 20:43:11 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
ColumnDimensions = new[]
|
2019-10-08 19:51:12 +08:00
|
|
|
|
{
|
2020-07-28 07:36:25 +08:00
|
|
|
|
new Dimension(GridSizeMode.Absolute, size: avatar_size + 10),
|
2020-02-10 20:43:11 +08:00
|
|
|
|
new Dimension(),
|
|
|
|
|
},
|
|
|
|
|
RowDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize)
|
|
|
|
|
},
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
2019-10-09 00:56:43 +08:00
|
|
|
|
{
|
2020-07-28 07:36:25 +08:00
|
|
|
|
new Container
|
2019-10-09 00:56:43 +08:00
|
|
|
|
{
|
2020-07-28 07:36:25 +08:00
|
|
|
|
Size = new Vector2(avatar_size),
|
2020-02-10 20:43:11 +08:00
|
|
|
|
Children = new Drawable[]
|
2019-10-14 22:26:12 +08:00
|
|
|
|
{
|
2023-11-15 08:15:22 +08:00
|
|
|
|
new UpdateableAvatar(Comment.User, showUserPanelOnHover: true)
|
2020-02-10 20:43:11 +08:00
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(avatar_size),
|
|
|
|
|
Masking = true,
|
|
|
|
|
CornerRadius = avatar_size / 2f,
|
|
|
|
|
CornerExponent = 2,
|
|
|
|
|
},
|
2020-07-28 07:36:25 +08:00
|
|
|
|
votePill = new VotePill(Comment)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Right = 5
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-10 20:43:11 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
2019-10-08 20:39:03 +08:00
|
|
|
|
{
|
2020-02-10 20:43:11 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-07-28 07:36:25 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 4),
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Vertical = 2
|
|
|
|
|
},
|
2020-02-10 20:43:11 +08:00
|
|
|
|
Children = new Drawable[]
|
2019-10-09 00:09:02 +08:00
|
|
|
|
{
|
2024-02-14 08:48:45 +08:00
|
|
|
|
author = new CommentAuthorLine(Comment, Meta),
|
2021-07-26 19:18:55 +08:00
|
|
|
|
message = new CommentMarkdownContainer
|
2019-10-10 16:43:45 +08:00
|
|
|
|
{
|
2020-02-10 20:43:11 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2021-07-26 19:18:55 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
DocumentMargin = new MarginPadding(0),
|
|
|
|
|
DocumentPadding = new MarginPadding(0),
|
2020-02-10 20:43:11 +08:00
|
|
|
|
},
|
2022-09-27 23:23:15 +08:00
|
|
|
|
new FillFlowContainer
|
2020-02-10 20:43:11 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2020-07-28 07:36:25 +08:00
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(10, 0),
|
2022-09-28 22:49:37 +08:00
|
|
|
|
Children = new Drawable[]
|
2019-10-14 22:26:12 +08:00
|
|
|
|
{
|
2022-09-27 23:23:15 +08:00
|
|
|
|
info = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(10, 0),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new DrawableDate(Comment.CreatedAt, 12, false)
|
|
|
|
|
{
|
2024-02-14 08:38:49 +08:00
|
|
|
|
Colour = colourProvider.Foreground1,
|
2022-09-27 23:23:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-09-28 22:49:37 +08:00
|
|
|
|
actionsContainer = new LinkFlowContainer(s => s.Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold))
|
2020-02-10 20:43:11 +08:00
|
|
|
|
{
|
2022-10-08 23:53:41 +08:00
|
|
|
|
Name = @"Actions buttons",
|
2022-09-27 23:23:15 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2022-09-28 22:49:37 +08:00
|
|
|
|
},
|
|
|
|
|
actionsLoading = new LoadingSpinner
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(12f),
|
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
|
Origin = Anchor.TopLeft
|
2020-07-28 07:36:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-01-19 01:50:07 +08:00
|
|
|
|
replyEditorContainer = new Container<CommentEditor>
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Padding = new MarginPadding { Top = 10 },
|
2023-02-03 16:47:10 +08:00
|
|
|
|
Alpha = 0,
|
2023-01-19 01:50:07 +08:00
|
|
|
|
},
|
2023-02-03 16:47:10 +08:00
|
|
|
|
repliesButtonContainer = new Container
|
2020-07-28 07:36:25 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2023-02-03 16:47:10 +08:00
|
|
|
|
Alpha = 0,
|
2020-07-28 07:36:25 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2020-07-11 13:01:11 +08:00
|
|
|
|
showRepliesButton = new ShowRepliesButton(Comment.RepliesCount)
|
2020-02-10 20:43:11 +08:00
|
|
|
|
{
|
|
|
|
|
Expanded = { BindTarget = childrenExpanded }
|
|
|
|
|
},
|
2020-07-11 13:01:11 +08:00
|
|
|
|
loadRepliesButton = new LoadRepliesButton
|
2020-02-10 20:43:11 +08:00
|
|
|
|
{
|
2020-07-14 20:02:29 +08:00
|
|
|
|
Action = () => RepliesRequested(this, ++currentPage)
|
2020-02-10 20:43:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-14 22:26:12 +08:00
|
|
|
|
}
|
2019-10-09 17:18:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-08 21:00:34 +08:00
|
|
|
|
}
|
2019-10-08 19:51:12 +08:00
|
|
|
|
}
|
2020-07-28 07:36:25 +08:00
|
|
|
|
},
|
|
|
|
|
childCommentsVisibilityContainer = new FillFlowContainer
|
2019-10-10 16:43:45 +08:00
|
|
|
|
{
|
2023-01-19 01:50:07 +08:00
|
|
|
|
Name = @"Children comments",
|
2020-07-28 07:36:25 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
2023-01-18 07:11:07 +08:00
|
|
|
|
Padding = new MarginPadding { Left = childrenPadding },
|
2020-07-28 07:36:25 +08:00
|
|
|
|
Children = new Drawable[]
|
2020-02-10 20:43:11 +08:00
|
|
|
|
{
|
2020-07-28 07:36:25 +08:00
|
|
|
|
childCommentsContainer = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical
|
|
|
|
|
},
|
|
|
|
|
deletedCommentsCounter = new DeletedCommentsCounter
|
|
|
|
|
{
|
|
|
|
|
ShowDeleted = { BindTarget = ShowDeleted },
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = 10
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-07-30 10:02:01 +08:00
|
|
|
|
showMoreButton = new ShowMoreRepliesButton
|
2020-07-28 07:36:25 +08:00
|
|
|
|
{
|
|
|
|
|
Action = () => RepliesRequested(this, ++currentPage)
|
|
|
|
|
}
|
2020-02-10 20:43:11 +08:00
|
|
|
|
}
|
2020-07-28 07:36:25 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
2019-10-08 19:51:12 +08:00
|
|
|
|
}
|
2020-02-10 20:43:11 +08:00
|
|
|
|
},
|
2020-07-28 05:29:17 +08:00
|
|
|
|
new Container
|
2020-02-10 20:43:11 +08:00
|
|
|
|
{
|
2020-07-28 05:29:17 +08:00
|
|
|
|
Size = new Vector2(70, 40),
|
2020-02-10 20:43:11 +08:00
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
2020-07-28 05:29:17 +08:00
|
|
|
|
Margin = new MarginPadding { Horizontal = 5 },
|
|
|
|
|
Child = chevronButton = new ChevronButton
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Expanded = { BindTarget = childrenExpanded },
|
|
|
|
|
Alpha = 0
|
|
|
|
|
}
|
2019-10-08 19:51:12 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-28 03:45:05 +08:00
|
|
|
|
if (Comment.EditedAt.HasValue && Comment.EditedUser != null)
|
2019-10-09 16:32:17 +08:00
|
|
|
|
{
|
2021-02-16 10:38:54 +08:00
|
|
|
|
var font = OsuFont.GetFont(size: 12, weight: FontWeight.Regular);
|
|
|
|
|
var colour = colourProvider.Foreground1;
|
|
|
|
|
|
|
|
|
|
info.Add(new FillFlowContainer
|
2019-10-09 16:32:17 +08:00
|
|
|
|
{
|
2021-02-16 10:38:54 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = font,
|
|
|
|
|
Text = "edited ",
|
|
|
|
|
Colour = colour
|
|
|
|
|
},
|
|
|
|
|
new DrawableDate(Comment.EditedAt.Value)
|
|
|
|
|
{
|
|
|
|
|
Font = font,
|
|
|
|
|
Colour = colour
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Font = font,
|
|
|
|
|
Text = $@" by {Comment.EditedUser.Username}",
|
|
|
|
|
Colour = colour
|
|
|
|
|
},
|
|
|
|
|
}
|
2019-10-09 16:32:17 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 20:43:11 +08:00
|
|
|
|
if (Comment.HasMessage)
|
2021-07-26 19:18:55 +08:00
|
|
|
|
message.Text = Comment.Message;
|
2019-10-15 17:07:01 +08:00
|
|
|
|
|
2022-10-08 23:41:08 +08:00
|
|
|
|
WasDeleted = Comment.IsDeleted;
|
|
|
|
|
if (WasDeleted)
|
|
|
|
|
makeDeleted();
|
2019-10-09 17:18:49 +08:00
|
|
|
|
|
2022-11-29 12:01:52 +08:00
|
|
|
|
actionsContainer.AddLink(CommonStrings.ButtonsPermalink, copyUrl);
|
2022-10-20 23:47:42 +08:00
|
|
|
|
actionsContainer.AddArbitraryDrawable(Empty().With(d => d.Width = 10));
|
2023-01-19 01:50:07 +08:00
|
|
|
|
actionsContainer.AddLink(CommonStrings.ButtonsReply.ToLower(), toggleReply);
|
|
|
|
|
actionsContainer.AddArbitraryDrawable(Empty().With(d => d.Width = 10));
|
2022-10-14 03:18:26 +08:00
|
|
|
|
|
2022-09-27 23:23:15 +08:00
|
|
|
|
if (Comment.UserId.HasValue && Comment.UserId.Value == api.LocalUser.Value.Id)
|
2022-12-19 12:10:22 +08:00
|
|
|
|
actionsContainer.AddLink(CommonStrings.ButtonsDelete.ToLower(), deleteComment);
|
2022-10-14 20:52:09 +08:00
|
|
|
|
else
|
2022-10-22 07:47:11 +08:00
|
|
|
|
actionsContainer.AddArbitraryDrawable(new CommentReportButton(Comment));
|
2022-09-27 23:23:15 +08:00
|
|
|
|
|
2020-02-10 20:43:11 +08:00
|
|
|
|
if (Comment.IsTopLevel)
|
2019-10-09 17:18:49 +08:00
|
|
|
|
{
|
2020-02-10 20:43:11 +08:00
|
|
|
|
AddInternal(new Box
|
2019-10-09 17:18:49 +08:00
|
|
|
|
{
|
2019-10-09 19:10:05 +08:00
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
2020-02-10 20:43:11 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 1.5f,
|
|
|
|
|
Colour = OsuColour.Gray(0.1f)
|
2019-10-09 17:18:49 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2020-02-13 05:19:21 +08:00
|
|
|
|
|
2020-02-13 07:47:13 +08:00
|
|
|
|
if (Replies.Any())
|
|
|
|
|
onRepliesAdded(Replies);
|
2020-02-18 18:37:59 +08:00
|
|
|
|
|
|
|
|
|
Replies.CollectionChanged += (_, args) =>
|
|
|
|
|
{
|
|
|
|
|
switch (args.Action)
|
|
|
|
|
{
|
|
|
|
|
case NotifyCollectionChangedAction.Add:
|
2022-12-16 17:16:26 +08:00
|
|
|
|
Debug.Assert(args.NewItems != null);
|
|
|
|
|
|
2020-02-18 18:37:59 +08:00
|
|
|
|
onRepliesAdded(args.NewItems.Cast<DrawableComment>());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new NotSupportedException(@"You can only add replies to this list. Other actions are not supported.");
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-10-09 00:18:46 +08:00
|
|
|
|
}
|
2019-10-08 21:00:34 +08:00
|
|
|
|
|
2022-10-08 23:41:08 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Transforms some comment's components to show it as deleted. Invoked both from loading and deleting.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void makeDeleted()
|
|
|
|
|
{
|
2024-02-14 08:38:49 +08:00
|
|
|
|
author.MarkDeleted();
|
2022-10-08 23:41:08 +08:00
|
|
|
|
content.FadeColour(OsuColour.Gray(0.5f));
|
|
|
|
|
votePill.Hide();
|
|
|
|
|
actionsContainer.Expire();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 22:15:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invokes comment deletion with confirmation.
|
|
|
|
|
/// </summary>
|
2022-09-28 22:49:37 +08:00
|
|
|
|
private void deleteComment()
|
|
|
|
|
{
|
2022-10-08 22:11:09 +08:00
|
|
|
|
if (dialogOverlay == null)
|
|
|
|
|
deleteCommentRequest();
|
|
|
|
|
else
|
|
|
|
|
dialogOverlay.Push(new ConfirmDialog("Do you really want to delete your comment?", deleteCommentRequest));
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 22:15:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invokes comment deletion directly.
|
|
|
|
|
/// </summary>
|
2022-10-08 22:11:09 +08:00
|
|
|
|
private void deleteCommentRequest()
|
|
|
|
|
{
|
|
|
|
|
actionsContainer.Hide();
|
|
|
|
|
actionsLoading.Show();
|
|
|
|
|
var request = new CommentDeleteRequest(Comment.Id);
|
2022-10-08 22:15:10 +08:00
|
|
|
|
request.Success += _ => Schedule(() =>
|
2022-09-28 22:49:37 +08:00
|
|
|
|
{
|
2022-10-08 22:11:09 +08:00
|
|
|
|
actionsLoading.Hide();
|
2022-10-08 23:41:08 +08:00
|
|
|
|
makeDeleted();
|
|
|
|
|
WasDeleted = true;
|
|
|
|
|
if (!ShowDeleted.Value)
|
|
|
|
|
Hide();
|
2022-10-08 22:15:10 +08:00
|
|
|
|
});
|
2023-01-18 22:30:34 +08:00
|
|
|
|
request.Failure += e => Schedule(() =>
|
2022-10-08 22:11:09 +08:00
|
|
|
|
{
|
2023-01-18 22:30:34 +08:00
|
|
|
|
Logger.Error(e, "Failed to delete comment");
|
2022-10-08 22:11:09 +08:00
|
|
|
|
actionsLoading.Hide();
|
|
|
|
|
actionsContainer.Show();
|
2022-10-08 22:15:10 +08:00
|
|
|
|
});
|
2022-10-08 22:11:09 +08:00
|
|
|
|
api.Queue(request);
|
2022-09-28 22:49:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-14 03:18:26 +08:00
|
|
|
|
private void copyUrl()
|
|
|
|
|
{
|
2023-07-11 17:42:31 +08:00
|
|
|
|
clipboard.SetText($@"{api.APIEndpointUrl}/comments/{Comment.Id}");
|
2022-10-14 03:18:26 +08:00
|
|
|
|
onScreenDisplay?.Display(new CopyUrlToast());
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 01:50:07 +08:00
|
|
|
|
private void toggleReply()
|
|
|
|
|
{
|
|
|
|
|
if (replyEditorContainer.Count == 0)
|
|
|
|
|
{
|
2023-02-03 16:47:10 +08:00
|
|
|
|
replyEditorContainer.Show();
|
2023-01-19 01:50:07 +08:00
|
|
|
|
replyEditorContainer.Add(new ReplyCommentEditor(Comment)
|
|
|
|
|
{
|
|
|
|
|
OnPost = comments =>
|
|
|
|
|
{
|
|
|
|
|
Comment.RepliesCount += comments.Length;
|
|
|
|
|
showRepliesButton.Count = Comment.RepliesCount;
|
|
|
|
|
Replies.AddRange(comments);
|
2023-02-03 16:48:32 +08:00
|
|
|
|
},
|
|
|
|
|
OnCancel = toggleReply
|
2023-01-19 01:50:07 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-02-08 07:15:51 +08:00
|
|
|
|
replyEditorContainer.ForEach(e => e.Expire());
|
2023-02-03 16:47:10 +08:00
|
|
|
|
replyEditorContainer.Hide();
|
2023-01-19 01:50:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 00:18:46 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
2019-10-15 16:30:50 +08:00
|
|
|
|
ShowDeleted.BindValueChanged(show =>
|
|
|
|
|
{
|
2022-10-08 23:41:08 +08:00
|
|
|
|
if (WasDeleted)
|
2019-10-15 16:30:50 +08:00
|
|
|
|
this.FadeTo(show.NewValue ? 1 : 0);
|
|
|
|
|
}, true);
|
2019-10-15 05:32:21 +08:00
|
|
|
|
childrenExpanded.BindValueChanged(expanded => childCommentsVisibilityContainer.FadeTo(expanded.NewValue ? 1 : 0), true);
|
2020-02-10 20:43:11 +08:00
|
|
|
|
updateButtonsState();
|
2019-10-09 00:18:46 +08:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-13 07:47:13 +08:00
|
|
|
|
private void onRepliesAdded(IEnumerable<DrawableComment> replies)
|
2020-02-10 20:43:11 +08:00
|
|
|
|
{
|
2020-02-13 05:19:21 +08:00
|
|
|
|
var page = createRepliesPage(replies);
|
|
|
|
|
|
|
|
|
|
if (LoadState == LoadState.Loading)
|
2020-02-10 20:43:11 +08:00
|
|
|
|
{
|
2020-02-13 05:19:21 +08:00
|
|
|
|
addRepliesPage(page, replies);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LoadComponentAsync(page, loaded => addRepliesPage(loaded, replies));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addRepliesPage(FillFlowContainer<DrawableComment> page, IEnumerable<DrawableComment> replies)
|
|
|
|
|
{
|
|
|
|
|
childCommentsContainer.Add(page);
|
|
|
|
|
|
|
|
|
|
var newReplies = replies.Select(reply => reply.Comment);
|
2020-02-13 07:37:41 +08:00
|
|
|
|
newReplies.ForEach(reply => loadedReplies.Add(reply.Id, reply));
|
2020-02-13 05:19:21 +08:00
|
|
|
|
deletedCommentsCounter.Count.Value += newReplies.Count(reply => reply.IsDeleted);
|
|
|
|
|
updateButtonsState();
|
2020-02-10 20:43:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private FillFlowContainer<DrawableComment> createRepliesPage(IEnumerable<DrawableComment> replies) => new FillFlowContainer<DrawableComment>
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Children = replies.ToList()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private void updateButtonsState()
|
|
|
|
|
{
|
2021-12-10 13:04:31 +08:00
|
|
|
|
int loadedRepliesCount = loadedReplies.Count;
|
|
|
|
|
bool hasUnloadedReplies = loadedRepliesCount != Comment.RepliesCount;
|
2020-02-10 20:43:11 +08:00
|
|
|
|
|
2023-02-03 16:47:10 +08:00
|
|
|
|
showRepliesButton.FadeTo(loadedRepliesCount != 0 ? 1 : 0);
|
2021-12-10 13:04:31 +08:00
|
|
|
|
loadRepliesButton.FadeTo(hasUnloadedReplies && loadedRepliesCount == 0 ? 1 : 0);
|
2023-02-05 12:11:29 +08:00
|
|
|
|
repliesButtonContainer.FadeTo(repliesButtonContainer.Any(child => child.Alpha > 0) ? 1 : 0);
|
2023-02-03 16:47:10 +08:00
|
|
|
|
|
2021-12-10 13:04:31 +08:00
|
|
|
|
showMoreButton.FadeTo(hasUnloadedReplies && loadedRepliesCount > 0 ? 1 : 0);
|
2020-02-10 20:43:11 +08:00
|
|
|
|
|
|
|
|
|
if (Comment.IsTopLevel)
|
2021-12-10 13:04:31 +08:00
|
|
|
|
chevronButton.FadeTo(loadedRepliesCount != 0 ? 1 : 0);
|
2020-02-10 20:43:11 +08:00
|
|
|
|
|
2020-07-14 20:02:29 +08:00
|
|
|
|
showMoreButton.IsLoading = loadRepliesButton.IsLoading = false;
|
2020-02-10 20:43:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 07:36:25 +08:00
|
|
|
|
private MarginPadding getPadding(bool isTopLevel)
|
|
|
|
|
{
|
|
|
|
|
if (isTopLevel)
|
|
|
|
|
{
|
|
|
|
|
return new MarginPadding
|
|
|
|
|
{
|
2023-04-03 11:45:09 +08:00
|
|
|
|
Horizontal = WaveOverlayContainer.HORIZONTAL_PADDING,
|
2020-07-28 07:36:25 +08:00
|
|
|
|
Vertical = 15
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Top = 10
|
|
|
|
|
};
|
|
|
|
|
}
|
2019-10-08 19:51:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|