Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion osu.Game/Online/Chat/ChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,16 @@ public void PostCommand(string text, Channel target = null)
AddInternal(new NowPlayingCommand(target));
break;

case @"watch":
if (string.IsNullOrWhiteSpace(content))
{
target.AddNewMessages(new ErrorMessage("Usage: /watch [user]"));
break;
}

AddInternal(new WatchCommand(target, content));
break;

case @"me":
if (string.IsNullOrWhiteSpace(content))
{
Expand Down Expand Up @@ -411,7 +421,7 @@ public void PostCommand(string text, Channel target = null)
break;

case @"help":
target.AddNewMessages(new InfoMessage("Supported commands: /help, /me [action], /join [channel], /chat [user], /np, /savelog, /roll [2-100] (multiplayer only)"));
target.AddNewMessages(new InfoMessage("Supported commands: /help, /me [action], /join [channel], /chat [user], /np, /watch [user], /savelog, /roll [2-100] (multiplayer only)"));
break;

default:
Expand Down
56 changes: 56 additions & 0 deletions osu.Game/Online/Chat/WatchCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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.Framework.Graphics;
using osu.Framework.Screens;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Screens;
using osu.Game.Screens.Play;

namespace osu.Game.Online.Chat
{
public partial class WatchCommand : Component
{
[Resolved]
private IChannelPostTarget channelManager { get; set; } = null!;

Check warning

Code scanning / InspectCode

Auto-property accessor is never used: Private accessibility Warning

Auto-property accessor 'channelManager.get' is never used
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

[Resolved]
private IAPIProvider api { get; set; } = null!;

[Resolved]
private IPerformFromScreenRunner performer { get; set; } = null!;

private readonly Channel? target;
private readonly string username;

public WatchCommand(Channel target, string username)
{
this.target = target;
this.username = username;
}

protected override void LoadComplete()
{
base.LoadComplete();

var request = new GetUserRequest(username);
request.Success += user =>
{
performer.PerformFromScreen(s => s.Push(new SoloSpectatorScreen(user)));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On stable, the command also fails if the user is not online. Technically this could be achieved via MetadataClient via something like

IDisposable? token = null;
if (!IsWatchingUserPresence)
   token = BeginWatchingUserPresence();
var status = GetPresence(userId)?.Status;
token?.Dispose();

if (status != Online) Fail();

I'm just not sure that it should be because this will work fine without it, by showing the spectator splash screen with the user card on it showing that the user is offline.

@peppy your opinion on how to proceed here please.

Expire();
};
request.Failure += e =>
{
target?.AddNewMessages(new ErrorMessage(
e.InnerException?.Message == @"NotFound"
? $"User '{username}' was not found."
: $"Could not fetch user '{username}'."));
Expire();
};

api.Queue(request);
}
}
}
Loading