mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 23:42:55 +08:00
use endpoint
This commit is contained in:
parent
db227b1798
commit
8518d15b8d
@ -8,6 +8,7 @@ using System.Linq;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -32,6 +33,7 @@ using osu.Game.Overlays.Chat.ChannelList;
|
|||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
using osu.Game.Graphics.UserInterfaceV2;
|
using osu.Game.Graphics.UserInterfaceV2;
|
||||||
|
using osu.Game.Overlays.Comments;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Online
|
namespace osu.Game.Tests.Visual.Online
|
||||||
{
|
{
|
||||||
@ -55,6 +57,9 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
|
|
||||||
private int currentMessageId;
|
private int currentMessageId;
|
||||||
|
|
||||||
|
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
|
||||||
|
private readonly ManualResetEventSlim requestLock = new ManualResetEventSlim();
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp() => Schedule(() =>
|
public void SetUp() => Schedule(() =>
|
||||||
{
|
{
|
||||||
@ -581,6 +586,8 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestChatReport()
|
public void TestChatReport()
|
||||||
{
|
{
|
||||||
|
ChatReportRequest request = null;
|
||||||
|
|
||||||
AddStep("Show overlay with channel", () =>
|
AddStep("Show overlay with channel", () =>
|
||||||
{
|
{
|
||||||
chatOverlay.Show();
|
chatOverlay.Show();
|
||||||
@ -590,6 +597,26 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
AddAssert("Overlay is visible", () => chatOverlay.State.Value == Visibility.Visible);
|
AddAssert("Overlay is visible", () => chatOverlay.State.Value == Visibility.Visible);
|
||||||
waitForChannel1Visible();
|
waitForChannel1Visible();
|
||||||
|
|
||||||
|
AddStep("Setup request handling", () =>
|
||||||
|
{
|
||||||
|
requestLock.Reset();
|
||||||
|
|
||||||
|
dummyAPI.HandleRequest = r =>
|
||||||
|
{
|
||||||
|
if (!(r is ChatReportRequest req))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
request = req;
|
||||||
|
requestLock.Wait(10000);
|
||||||
|
req.TriggerSuccess();
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
AddStep("Show report popover", () => this.ChildrenOfType<DrawableUsername>().First().ShowPopover());
|
AddStep("Show report popover", () => this.ChildrenOfType<DrawableUsername>().First().ShowPopover());
|
||||||
|
|
||||||
AddStep("Try to report", () =>
|
AddStep("Try to report", () =>
|
||||||
@ -599,7 +626,11 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
InputManager.Click(MouseButton.Left);
|
InputManager.Click(MouseButton.Left);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("Report message sended", () => channelManager.CurrentChannel.Value.Messages.Any(x => x.Content.Contains("!report")));
|
AddWaitStep("Wait", 3);
|
||||||
|
|
||||||
|
AddAssert("Overlay closed", () => !this.ChildrenOfType<ReportChatPopover>().Any());
|
||||||
|
AddStep("Complete request", () => requestLock.Set());
|
||||||
|
AddUntilStep("Request sent", () => request != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void joinTestChannel(int i)
|
private void joinTestChannel(int i)
|
||||||
|
38
osu.Game/Online/API/Requests/ChatReportRequest.cs
Normal file
38
osu.Game/Online/API/Requests/ChatReportRequest.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// 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.Net.Http;
|
||||||
|
using osu.Framework.IO.Network;
|
||||||
|
using osu.Game.Online.Chat;
|
||||||
|
using osu.Game.Overlays.Chat;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.API.Requests;
|
||||||
|
|
||||||
|
public class ChatReportRequest : APIRequest
|
||||||
|
{
|
||||||
|
public readonly long? MessageId;
|
||||||
|
public readonly ChatReportReason Reason;
|
||||||
|
public readonly string Comment;
|
||||||
|
|
||||||
|
public ChatReportRequest(long? id, ChatReportReason reason, string comment)
|
||||||
|
{
|
||||||
|
MessageId = id;
|
||||||
|
Reason = reason;
|
||||||
|
Comment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override WebRequest CreateWebRequest()
|
||||||
|
{
|
||||||
|
var req = base.CreateWebRequest();
|
||||||
|
req.Method = HttpMethod.Post;
|
||||||
|
|
||||||
|
req.AddParameter(@"reportable_type", @"message");
|
||||||
|
req.AddParameter(@"reportable_id", $"{MessageId}");
|
||||||
|
req.AddParameter(@"reason", Reason.ToString());
|
||||||
|
req.AddParameter(@"comments", Comment);
|
||||||
|
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Target => @"reports";
|
||||||
|
}
|
@ -92,7 +92,7 @@ namespace osu.Game.Overlays.Chat
|
|||||||
Font = OsuFont.GetFont(size: FontSize * 0.75f, weight: FontWeight.SemiBold, fixedWidth: true),
|
Font = OsuFont.GetFont(size: FontSize * 0.75f, weight: FontWeight.SemiBold, fixedWidth: true),
|
||||||
AlwaysPresent = true,
|
AlwaysPresent = true,
|
||||||
},
|
},
|
||||||
drawableUsername = new DrawableUsername(message.Sender)
|
drawableUsername = new DrawableUsername(message)
|
||||||
{
|
{
|
||||||
Width = UsernameWidth,
|
Width = UsernameWidth,
|
||||||
FontSize = FontSize,
|
FontSize = FontSize,
|
||||||
|
@ -21,6 +21,7 @@ using osu.Game.Graphics.Sprites;
|
|||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Localisation;
|
using osu.Game.Localisation;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Online.Chat;
|
using osu.Game.Online.Chat;
|
||||||
using osu.Game.Resources.Localisation.Web;
|
using osu.Game.Resources.Localisation.Web;
|
||||||
@ -72,13 +73,15 @@ namespace osu.Game.Overlays.Chat
|
|||||||
private Bindable<Channel?>? currentChannel { get; set; }
|
private Bindable<Channel?>? currentChannel { get; set; }
|
||||||
|
|
||||||
private readonly APIUser user;
|
private readonly APIUser user;
|
||||||
|
private readonly Message message;
|
||||||
private readonly OsuSpriteText drawableText;
|
private readonly OsuSpriteText drawableText;
|
||||||
|
|
||||||
private readonly Drawable colouredDrawable;
|
private readonly Drawable colouredDrawable;
|
||||||
|
|
||||||
public DrawableUsername(APIUser user)
|
public DrawableUsername(Message message)
|
||||||
{
|
{
|
||||||
this.user = user;
|
this.message = message;
|
||||||
|
user = message.Sender;
|
||||||
|
|
||||||
Action = openUserProfile;
|
Action = openUserProfile;
|
||||||
|
|
||||||
@ -171,7 +174,8 @@ namespace osu.Game.Overlays.Chat
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
items.Add(new OsuMenuItem("Report", MenuItemType.Destructive, this.ShowPopover));
|
if (!user.Equals(api.LocalUser.Value))
|
||||||
|
items.Add(new OsuMenuItem("Report", MenuItemType.Destructive, this.ShowPopover));
|
||||||
|
|
||||||
return items.ToArray();
|
return items.ToArray();
|
||||||
}
|
}
|
||||||
@ -179,7 +183,19 @@ namespace osu.Game.Overlays.Chat
|
|||||||
|
|
||||||
private void report(ChatReportReason reason, string comments)
|
private void report(ChatReportReason reason, string comments)
|
||||||
{
|
{
|
||||||
chatManager?.PostMessage($"!report {user.Username} ({reason.GetDescription()}): {comments}");
|
var request = new ChatReportRequest(message.Id, 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()
|
private void openUserChannel()
|
||||||
|
Loading…
Reference in New Issue
Block a user