2023-01-19 15:01:37 +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 System;
|
2024-09-30 17:02:00 +08:00
|
|
|
using System.Collections.Generic;
|
2023-01-19 15:01:37 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Localisation;
|
|
|
|
using osu.Framework.Logging;
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Comments
|
|
|
|
{
|
|
|
|
public partial class ReplyCommentEditor : CancellableCommentEditor
|
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private CommentsContainer commentsContainer { get; set; } = null!;
|
|
|
|
|
|
|
|
private readonly Comment parentComment;
|
|
|
|
|
|
|
|
public Action<DrawableComment[]>? OnPost;
|
|
|
|
|
|
|
|
protected override LocalisableString FooterText => default;
|
2023-06-20 06:10:37 +08:00
|
|
|
|
2023-06-23 05:00:52 +08:00
|
|
|
protected override LocalisableString GetButtonText(bool isLoggedIn) =>
|
2023-06-20 06:10:37 +08:00
|
|
|
isLoggedIn ? CommonStrings.ButtonsReply : CommentsStrings.GuestButtonReply;
|
|
|
|
|
2024-09-30 17:02:00 +08:00
|
|
|
protected override LocalisableString GetPlaceholderText() => CommentsStrings.PlaceholderReply;
|
2023-01-19 15:01:37 +08:00
|
|
|
|
2024-09-30 17:02:00 +08:00
|
|
|
public ReplyCommentEditor(Comment parent, IEnumerable<CommentableMeta> meta)
|
2023-01-19 15:01:37 +08:00
|
|
|
{
|
|
|
|
parentComment = parent;
|
2024-09-30 17:02:00 +08:00
|
|
|
CommentableMeta.Value = meta.SingleOrDefault(m => m.Id == parent.CommentableId && m.Type == parent.CommentableType);
|
2023-01-19 15:01:37 +08:00
|
|
|
}
|
|
|
|
|
2023-01-19 15:08:27 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2023-06-20 05:08:04 +08:00
|
|
|
if (!TextBox.ReadOnly)
|
2024-05-27 17:23:32 +08:00
|
|
|
GetContainingFocusManager()!.ChangeFocus(TextBox);
|
2023-01-19 15:08:27 +08:00
|
|
|
}
|
|
|
|
|
2023-01-19 15:01:37 +08:00
|
|
|
protected override void OnCommit(string text)
|
|
|
|
{
|
|
|
|
ShowLoadingSpinner = true;
|
|
|
|
CommentPostRequest req = new CommentPostRequest(commentsContainer.Type.Value, commentsContainer.Id.Value, text, parentComment.Id);
|
|
|
|
req.Failure += e => Schedule(() =>
|
|
|
|
{
|
|
|
|
ShowLoadingSpinner = false;
|
|
|
|
Logger.Error(e, "Posting reply comment failed.");
|
|
|
|
});
|
|
|
|
req.Success += cb => Schedule(processPostedComments, cb);
|
2023-06-20 05:36:40 +08:00
|
|
|
API.Queue(req);
|
2023-01-19 15:01:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void processPostedComments(CommentBundle cb)
|
|
|
|
{
|
|
|
|
foreach (var comment in cb.Comments)
|
|
|
|
comment.ParentComment = parentComment;
|
|
|
|
|
2024-02-14 08:46:19 +08:00
|
|
|
var drawables = cb.Comments.Select(c => commentsContainer.GetDrawableComment(c, cb.CommentableMeta)).ToArray();
|
2023-01-19 15:01:37 +08:00
|
|
|
OnPost?.Invoke(drawables);
|
|
|
|
|
|
|
|
OnCancel!.Invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|