Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for displaying "mapper" badge in comment section #27164

Merged
merged 9 commits into from
Feb 14, 2024
41 changes: 38 additions & 3 deletions osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ public void TestPostWithExistingComments()
});
}

[Test]
public void TestPostAsOwner()
{
setUpCommentsResponse(getExampleComments());
AddStep("show comments", () => commentsContainer.ShowComments(CommentableType.Beatmapset, 123));

setUpPostResponse(true);
AddStep("enter text", () => editorTextBox.Current.Value = "comm");
AddStep("submit", () => commentsContainer.ChildrenOfType<CommentEditor>().Single().ChildrenOfType<RoundedButton>().First().TriggerClick());

AddUntilStep("comment sent", () =>
{
string writtenText = editorTextBox.Current.Value;
var comment = commentsContainer.ChildrenOfType<DrawableComment>().LastOrDefault();
return comment != null && comment.ChildrenOfType<SpriteText>().Any(y => y.Text == writtenText) && comment.ChildrenOfType<SpriteText>().Any(y => y.Text == "MAPPER");
});
}

private void setUpCommentsResponse(CommentBundle commentBundle)
=> AddStep("set up response", () =>
{
Expand All @@ -183,15 +201,15 @@ private void setUpCommentsResponse(CommentBundle commentBundle)
};
});

private void setUpPostResponse()
private void setUpPostResponse(bool asOwner = false)
=> AddStep("set up response", () =>
{
dummyAPI.HandleRequest = request =>
{
if (!(request is CommentPostRequest req))
return false;

req.TriggerSuccess(new CommentBundle
var bundle = new CommentBundle
{
Comments = new List<Comment>
{
Expand All @@ -202,9 +220,26 @@ private void setUpPostResponse()
LegacyName = "FirstUser",
CreatedAt = DateTimeOffset.Now,
VotesCount = 98,
CommentableId = 2001,
CommentableType = "test",
}
}
});
};

if (asOwner)
{
bundle.Comments[0].UserId = 1001;
bundle.Comments[0].User = new APIUser { Id = 1001, Username = "FirstUser" };
bundle.CommentableMeta.Add(new CommentableMeta
{
Id = 2001,
OwnerId = 1001,
OwnerTitle = "MAPPER",
Type = "test",
});
}

req.TriggerSuccess(bundle);
return true;
};
});
Expand Down
86 changes: 45 additions & 41 deletions osu.Game.Tests/Visual/Online/TestSceneDrawableComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,66 @@
#nullable disable

using System;
using NUnit.Framework;
using osu.Framework.Allocation;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Overlays.Comments;
using osu.Game.Tests.Visual.UserInterface;

namespace osu.Game.Tests.Visual.Online
{
public partial class TestSceneDrawableComment : OsuTestScene
public partial class TestSceneDrawableComment : ThemeComparisonTestScene
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);

private Container container;

[SetUp]
public void SetUp() => Schedule(() =>
public TestSceneDrawableComment()
: base(false)
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background4,
},
container = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
};
});
}

[TestCaseSource(nameof(comments))]
public void TestComment(string description, string text)
protected override Drawable CreateContent() => new OsuScrollContainer(Direction.Vertical)
{
AddStep(description, () =>
RelativeSizeAxes = Axes.Both,
Child = new FillFlowContainer
{
comment.Pinned = description == "Pinned";
comment.Message = text;
container.Add(new DrawableComment(comment));
});
}
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
ChildrenEnumerable = comments.Select(info =>
{
var comment = new Comment
{
Id = 1,
UserId = 1000,
User = new APIUser { Id = 1000, Username = "Someone" },
CreatedAt = DateTimeOffset.Now,
VotesCount = 0,
Pinned = info[0] == "Pinned",
Message = info[1],
CommentableId = 2001,
CommentableType = "test"
};

private static readonly Comment comment = new Comment
{
Id = 1,
LegacyName = "Test User",
CreatedAt = DateTimeOffset.Now,
VotesCount = 0,
return new[]
{
new DrawableComment(comment, Array.Empty<CommentableMeta>()),
new DrawableComment(comment, new[]
{
new CommentableMeta
{
Id = 2001,
OwnerId = comment.UserId,
OwnerTitle = "MAPPER",
Type = "test",
},
new CommentableMeta { Title = "Other Meta" },
}),
};
}).SelectMany(c => c)
}
};

private static object[] comments =
private static readonly string[][] comments =
{
new[] { "Plain", "This is plain comment" },
new[] { "Pinned", "This is pinned comment" },
Expand Down
30 changes: 19 additions & 11 deletions osu.Game.Tests/Visual/UserInterface/ThemeComparisonTestScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,39 @@ namespace osu.Game.Tests.Visual.UserInterface
{
public abstract partial class ThemeComparisonTestScene : OsuGridTestScene
{
protected ThemeComparisonTestScene()
: base(1, 2)
private readonly bool showWithoutColourProvider;
Copy link
Member Author

Choose a reason for hiding this comment

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

Oh haha, this is the name I chose initially for the variable. It read slightly weird to me so I replaced Without with No.


protected ThemeComparisonTestScene(bool showWithoutColourProvider = true)
: base(1, showWithoutColourProvider ? 2 : 1)
{
this.showWithoutColourProvider = showWithoutColourProvider;
}

[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Cell(0, 0).AddRange(new[]
if (showWithoutColourProvider)
{
new Box
Cell(0, 0).AddRange(new[]
{
RelativeSizeAxes = Axes.Both,
Colour = colours.GreySeaFoam
},
CreateContent()
});
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.GreySeaFoam
},
CreateContent()
});
}
}

protected void CreateThemedContent(OverlayColourScheme colourScheme)
{
var colourProvider = new OverlayColourProvider(colourScheme);

Cell(0, 1).Clear();
Cell(0, 1).Add(new DependencyProvidingContainer
int col = showWithoutColourProvider ? 1 : 0;

Cell(0, col).Clear();
Cell(0, col).Add(new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[]
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Online/API/Requests/Responses/Comment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Comment
[JsonProperty(@"votes_count")]
public int VotesCount { get; set; }

[JsonProperty(@"commenatble_type")]
[JsonProperty(@"commentable_type")]
public string CommentableType { get; set; } = null!;

[JsonProperty(@"commentable_id")]
Expand Down
3 changes: 3 additions & 0 deletions osu.Game/Online/API/Requests/Responses/CommentBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ namespace osu.Game.Online.API.Requests.Responses
{
public class CommentBundle
{
[JsonProperty(@"commentable_meta")]
public List<CommentableMeta> CommentableMeta { get; set; } = new List<CommentableMeta>();

[JsonProperty(@"comments")]
public List<Comment> Comments { get; set; }

Expand Down
28 changes: 28 additions & 0 deletions osu.Game/Online/API/Requests/Responses/CommentableMeta.cs
Original file line number Diff line number Diff line change
@@ -0,0 +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 Newtonsoft.Json;

namespace osu.Game.Online.API.Requests.Responses
{
public class CommentableMeta
{
[JsonProperty("id")]
public long Id { get; set; }

[JsonProperty("owner_id")]
public long? OwnerId { get; set; }

[JsonProperty("owner_title")]
public string? OwnerTitle { get; set; }

[JsonProperty("title")]
public string Title { get; set; } = string.Empty;

[JsonProperty("type")]
public string Type { get; set; } = string.Empty;

[JsonProperty("url")]
public string Url { get; set; } = string.Empty;
}
}