mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 06:03:08 +08:00
Move reporting code out of DrawableChatUsername
into more correct locations
This commit is contained in:
parent
2cb6642b0d
commit
8391e2a538
@ -616,7 +616,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
};
|
||||
});
|
||||
|
||||
AddStep("Show report popover", () => this.ChildrenOfType<DrawableChatUsername>().First().ShowPopover());
|
||||
AddStep("Show report popover", () => this.ChildrenOfType<ChatLine>().First().ShowPopover());
|
||||
|
||||
AddStep("Set report reason to other", () =>
|
||||
{
|
||||
|
@ -1,25 +1,28 @@
|
||||
// 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.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Extensions.LocalisationExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
|
||||
namespace osu.Game.Overlays.Chat
|
||||
{
|
||||
public partial class ChatLine : CompositeDrawable
|
||||
public partial class ChatLine : CompositeDrawable, IHasPopover
|
||||
{
|
||||
private Message message = null!;
|
||||
|
||||
@ -92,7 +95,7 @@ namespace osu.Game.Overlays.Chat
|
||||
Font = OsuFont.GetFont(size: FontSize * 0.75f, weight: FontWeight.SemiBold, fixedWidth: true),
|
||||
AlwaysPresent = true,
|
||||
},
|
||||
drawableUsername = new DrawableChatUsername(message.Sender, message.Id)
|
||||
drawableUsername = new DrawableChatUsername(message.Sender)
|
||||
{
|
||||
Width = UsernameWidth,
|
||||
FontSize = FontSize,
|
||||
@ -100,6 +103,7 @@ namespace osu.Game.Overlays.Chat
|
||||
Origin = Anchor.TopRight,
|
||||
Anchor = Anchor.TopRight,
|
||||
Margin = new MarginPadding { Horizontal = Spacing },
|
||||
ReportRequested = this.ShowPopover,
|
||||
},
|
||||
drawableContentFlow = new LinkFlowContainer(styleMessageContent)
|
||||
{
|
||||
@ -128,6 +132,8 @@ namespace osu.Game.Overlays.Chat
|
||||
FinishTransforms(true);
|
||||
}
|
||||
|
||||
public Popover GetPopover() => new ReportChatPopover(message);
|
||||
|
||||
/// <summary>
|
||||
/// Performs a highlight animation on this <see cref="ChatLine"/>.
|
||||
/// </summary>
|
||||
|
@ -5,7 +5,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -21,7 +20,6 @@ using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Localisation;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Resources.Localisation.Web;
|
||||
@ -31,8 +29,10 @@ using ChatStrings = osu.Game.Localisation.ChatStrings;
|
||||
|
||||
namespace osu.Game.Overlays.Chat
|
||||
{
|
||||
public partial class DrawableChatUsername : OsuClickableContainer, IHasContextMenu, IHasPopover
|
||||
public partial class DrawableChatUsername : OsuClickableContainer, IHasContextMenu
|
||||
{
|
||||
public Action? ReportRequested;
|
||||
|
||||
public Color4 AccentColour { get; }
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
|
||||
@ -73,15 +73,13 @@ namespace osu.Game.Overlays.Chat
|
||||
private Bindable<Channel?>? currentChannel { get; set; }
|
||||
|
||||
private readonly APIUser user;
|
||||
private readonly long? messageId;
|
||||
private readonly OsuSpriteText drawableText;
|
||||
|
||||
private readonly Drawable colouredDrawable;
|
||||
|
||||
public DrawableChatUsername(APIUser user, long? messageId)
|
||||
public DrawableChatUsername(APIUser user)
|
||||
{
|
||||
this.user = user;
|
||||
this.messageId = messageId;
|
||||
|
||||
Action = openUserProfile;
|
||||
|
||||
@ -174,34 +172,12 @@ namespace osu.Game.Overlays.Chat
|
||||
}
|
||||
|
||||
if (!user.Equals(api.LocalUser.Value))
|
||||
items.Add(new OsuMenuItem("Report", MenuItemType.Destructive, this.ShowPopover));
|
||||
items.Add(new OsuMenuItem("Report", MenuItemType.Destructive, ReportRequested));
|
||||
|
||||
return items.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public Popover GetPopover() => new ReportChatPopover(user)
|
||||
{
|
||||
Action = report
|
||||
};
|
||||
|
||||
private void report(ChatReportReason reason, string comments)
|
||||
{
|
||||
var request = new ChatReportRequest(messageId, reason, comments);
|
||||
|
||||
request.Failure += _ => Schedule(() =>
|
||||
{
|
||||
currentChannel?.Value?.AddNewMessages(new ErrorMessage("Report failed to send, please retry"));
|
||||
});
|
||||
|
||||
request.Success += () => Schedule(() =>
|
||||
{
|
||||
currentChannel?.Value?.AddNewMessages(new InfoMessage("Report has been sent"));
|
||||
});
|
||||
|
||||
api.Queue(request);
|
||||
}
|
||||
|
||||
private void openUserChannel()
|
||||
{
|
||||
chatManager?.OpenPrivateChannel(user);
|
||||
|
@ -1,22 +1,47 @@
|
||||
// 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.Allocation;
|
||||
using osu.Game.Graphics.UserInterfaceV2;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Resources.Localisation.Web;
|
||||
|
||||
namespace osu.Game.Overlays.Chat
|
||||
{
|
||||
public partial class ReportChatPopover : ReportPopover<ChatReportReason>
|
||||
{
|
||||
public ReportChatPopover(APIUser? user)
|
||||
: base(ReportStrings.UserTitle(user?.Username ?? @"Someone"))
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private ChannelManager channelManager { get; set; } = null!;
|
||||
|
||||
private readonly Message message;
|
||||
|
||||
public ReportChatPopover(Message message)
|
||||
: base(ReportStrings.UserTitle(message.Sender?.Username ?? @"Someone"))
|
||||
{
|
||||
this.message = message;
|
||||
Action = report;
|
||||
}
|
||||
|
||||
protected override bool CheckCanSubmitEmptyComment(ChatReportReason reason)
|
||||
{
|
||||
return reason != ChatReportReason.Other;
|
||||
}
|
||||
|
||||
private void report(ChatReportReason reason, string comments)
|
||||
{
|
||||
var request = new ChatReportRequest(message.Id, reason, comments);
|
||||
|
||||
request.Success += () => Schedule(() =>
|
||||
{
|
||||
channelManager.CurrentChannel.Value.AddNewMessages(new InfoMessage(UsersStrings.ReportThanks.ToString()));
|
||||
});
|
||||
|
||||
api.Queue(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user