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 URL handling to chat #1667

Merged
merged 122 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
01bea3b
Re-implemented message formatting (mostly taken from osu-stable code)
FreezyLemon Dec 1, 2017
f5f287b
Rolled back the idea that there should be a separate class for format…
FreezyLemon Dec 1, 2017
1f1c7dd
Moved LinkFlowContainer out of ProfileHeader to make it available for…
FreezyLemon Dec 1, 2017
8630271
Also moved LinkText to its own file so the chat could reuse it (Profi…
FreezyLemon Dec 1, 2017
152eb83
Added new class for chat lines, that colour the messages after format…
FreezyLemon Dec 1, 2017
78ff5d8
Fixed casting
FreezyLemon Dec 1, 2017
7f1f886
implemented method formatting into chat. Also added all necessary fil…
FreezyLemon Dec 1, 2017
7699a3b
Merge branch 'master' of https://github.com/ppy/osu into url-parsing-…
FreezyLemon Dec 1, 2017
ade7311
Updated implementation to be based around a "LinkId" (atm the positio…
FreezyLemon Dec 1, 2017
d22a9df
Added new request for getting the beatmapset from only a difficulty m…
FreezyLemon Dec 2, 2017
0aced85
Changed the LinkID to the link's own Index instead of the previous on…
FreezyLemon Dec 2, 2017
6d9dcc6
Added all files to the .csproj and also introduced basic action filte…
FreezyLemon Dec 2, 2017
efe6245
Fixed a bug where Drawable.Width could potentially be set to NaN (0/0…
FreezyLemon Dec 2, 2017
7f029a3
Made the Chat testcase include a beatmapsetoverlay so links can be cl…
FreezyLemon Dec 2, 2017
37490c6
Merge branch 'url-parsing-support' of https://github.com/freezylemon/…
FreezyLemon Dec 2, 2017
735dbdd
Changed URL detection to be more reliable and generally work better
FreezyLemon Dec 3, 2017
c574cc4
Removed unnecessary "using" statements
FreezyLemon Dec 3, 2017
2d270a1
Added ability to open other channels from chat links.
FreezyLemon Dec 3, 2017
3f336b8
Made the style a bit better, fixed a bug or two
FreezyLemon Dec 3, 2017
a839d0e
LoadComponent before assigning URL to ensure dependency loading
FreezyLemon Dec 3, 2017
bf97f8b
Added osu.ppy.sh/ss (screenshot) URL handling and calculate ID at ass…
FreezyLemon Dec 3, 2017
dcdc186
Added chatoverlay caching to testcase so test still works (chat needs…
FreezyLemon Dec 4, 2017
319f43e
Added "getIdFromUrl" call back to content.action because performance …
FreezyLemon Dec 4, 2017
cf96323
Added new OsuLinkSpriteText.TextColour property that sets the interna…
FreezyLemon Dec 4, 2017
fd13bac
Made default link ID -1 (if no link is present) because linkId is cur…
FreezyLemon Dec 4, 2017
9b866d2
Made it so the link ID is always added before loading the SpriteTexts…
FreezyLemon Dec 4, 2017
bb138cc
Added licence header and removed unnecessary whitespace
FreezyLemon Dec 4, 2017
63a6a8b
Fixed messages sent by yourself not being formatted
FreezyLemon Dec 4, 2017
b04ddba
Added basic "on click" actions to the in-chat links
FreezyLemon Dec 6, 2017
94eb853
Added centralised handling for some chat links
FreezyLemon Dec 6, 2017
7bf25bd
Changed it so the ":" character does not appear after usernames when …
FreezyLemon Dec 7, 2017
541c25e
Renamed ChatLinkSpriteText to ChatLink for convenience
FreezyLemon Dec 7, 2017
65afbd5
Added new test case for URL parsing / link display in chat
FreezyLemon Dec 7, 2017
006ac44
Fixed up style in the ChatDisplay test
FreezyLemon Dec 7, 2017
ec8b5c2
Permitted nulls in ChatOverlay.load() so that in testing, no "OsuGame…
FreezyLemon Dec 7, 2017
1b971c0
Fixed a bug where links would be out of order in their List which wou…
FreezyLemon Dec 7, 2017
f3f3d1d
Various test fixes
FreezyLemon Dec 7, 2017
bd11124
Removed unnecessary copy (pass-by-reference anyways)
FreezyLemon Dec 7, 2017
8a88040
Added tooltip to links
FreezyLemon Dec 7, 2017
f4f1291
Removed "wiki:" prefix from wiki links (links are visible on tooltips…
FreezyLemon Dec 7, 2017
a8599a1
Implemented new interface which allows parent containers to decide on…
FreezyLemon Dec 7, 2017
8ba6601
Implemented the new IHasHoverSounds interface in a private "ChatHover…
FreezyLemon Dec 7, 2017
07660a6
Added licence header to the new test case
FreezyLemon Dec 7, 2017
5ded6e8
Added some tooltip text handling.
FreezyLemon Dec 7, 2017
ca40db2
Fixed a bug where the hover wouldn't work correctly due to OsuLinkSpr…
FreezyLemon Dec 7, 2017
2129d6c
Renamed the "on click" method to OnClick() and moved most of the impl…
FreezyLemon Dec 7, 2017
18eabd3
Set an empty list as default for AvailableChannels (mostly so that te…
FreezyLemon Dec 7, 2017
d90eb2c
Moved "Does this channel exist" check to ChatLine so that if a #name …
FreezyLemon Dec 7, 2017
334cb3d
Removed TODO and added another test line
FreezyLemon Dec 7, 2017
2ceb073
Renamed OnClick to OnLinkClicked to (what should be) obvious reasons
FreezyLemon Dec 7, 2017
465f92a
Removed unnecessary whitespace
FreezyLemon Dec 7, 2017
772bba2
Small style changes
FreezyLemon Dec 7, 2017
ce9b003
Reverted GetUserRequest because spectating is not implemented yet, an…
FreezyLemon Dec 7, 2017
6b0b518
*ahem* REVERTED the changes to GetUserRequest because they're not nee…
FreezyLemon Dec 7, 2017
e05618a
Removed unnecessary "using" directives
FreezyLemon Dec 7, 2017
908553f
Added parameter for LoadMultiplayerLobby (CI warning for unused int)
FreezyLemon Dec 7, 2017
34a3793
Removed unused property and unnecessary return statement (CI)
FreezyLemon Dec 7, 2017
c950d13
various CI adjustments
FreezyLemon Dec 7, 2017
c5a7f5b
Renamed the static variables and made them readonly, aswell as other …
FreezyLemon Dec 7, 2017
6825509
Renamed the IHasHoverSounds interface to ICanDisableHoverSounds and m…
FreezyLemon Dec 7, 2017
5546b8c
Trimmed whitespace (CI)
FreezyLemon Dec 7, 2017
f8bc52b
Merged https://github.com/ppy/osu master branch
FreezyLemon Dec 11, 2017
2568ac1
Fixed small merging mistake
FreezyLemon Dec 11, 2017
13bc50a
Removed ICanDisableHoverSounds interface
FreezyLemon Dec 11, 2017
4d475f1
Changed it so ChatLinks handle hover and click sounds themselves
FreezyLemon Dec 11, 2017
bb0a32b
Removed private OsuHoverContainer "content" from OsuLinkSpriteText fo…
FreezyLemon Dec 11, 2017
6369889
Removed unnecessary container and fixed "HandleInput" for ChatLinks
FreezyLemon Dec 11, 2017
8a02507
Let regex handle "getIdFromUrl"
FreezyLemon Dec 11, 2017
bfa9beb
Switched to regex to handle most of the decision on what to do on cli…
FreezyLemon Dec 11, 2017
d0b7c92
Removed unnecessary usings.
FreezyLemon Dec 11, 2017
4f8bec8
Removed makeshift fix that has already been addressed elsewhere.
FreezyLemon Dec 19, 2017
270d81f
Made the Link's OnClick() Method return true
FreezyLemon Dec 19, 2017
a6496e3
Merge branch 'master' into url-parsing-support
peppy Dec 20, 2017
fc0b970
Move hover sound/container to base implementation
peppy Dec 20, 2017
a304480
Merge branch 'master' into url-parsing-support
FreezyLemon Dec 25, 2017
025d394
Fixed problems introduced by the merge
FreezyLemon Dec 25, 2017
962e4d7
Removed LinkId and word wrapping (for now).
FreezyLemon Dec 25, 2017
7c49bec
CI adjustments
FreezyLemon Dec 25, 2017
cbfef70
further CI adjustments
FreezyLemon Dec 25, 2017
c4f5754
Fixed only the links being italics for /me messages
FreezyLemon Dec 27, 2017
d21ef14
Better style; removed initial sprites
FreezyLemon Dec 27, 2017
4681a0c
handle chat == null gracefully and remove link from message if channe…
FreezyLemon Dec 27, 2017
54a11e2
Fixed links being removed too early
FreezyLemon Dec 27, 2017
128603a
Added more and fixed the old automated tests
FreezyLemon Dec 28, 2017
7454633
Refactor and general tidying up
FreezyLemon Dec 28, 2017
ae79be7
small style fixes plus new assert in test
FreezyLemon Dec 28, 2017
d66d741
fixed constant naming
FreezyLemon Dec 28, 2017
e7721d7
Changed chat link implementation according to review
FreezyLemon Dec 30, 2017
faf1181
Merge branch 'master' into url-parsing-support
peppy Jan 2, 2018
b035a92
Merge branch 'master' into url-parsing-support
peppy Jan 9, 2018
f80e97a
Merge branch 'master' into url-parsing-support
peppy Jan 9, 2018
1be0569
Update licence headers
peppy Jan 9, 2018
72624ae
Use a better method of link compilation
peppy Jan 9, 2018
3bf9901
Fixed bugs and added tests
FreezyLemon Jan 9, 2018
174fdf5
Nicer code to remove non-existent channels from links
FreezyLemon Jan 11, 2018
2c67ff7
added custom hoverclicksounds so links make sounds on hover&click
FreezyLemon Jan 11, 2018
45301d0
Merge branch 'master' into url-parsing-support
peppy Jan 12, 2018
54b0f4b
Merge branch 'master' into url-parsing-support
peppy Jan 17, 2018
2f7d903
Update framework
peppy Jan 17, 2018
783ca40
Update with upstream changes
peppy Jan 17, 2018
3eccfac
Update framework
peppy Jan 17, 2018
b27577e
Add temporary browser handling of beatmap difficulty loading
peppy Jan 17, 2018
5a80c49
Improve reference xmldoc
peppy Jan 17, 2018
3892965
Remove unnecessary region and make methods public
peppy Jan 17, 2018
38c5434
Remove placeholder methods in OsuGame
peppy Jan 17, 2018
73d69e2
Add more xmldoc
peppy Jan 17, 2018
a5b0d51
Merge remote-tracking branch 'upstream/master' into url-parsing-support
peppy Jan 27, 2018
2b14438
Merge remote-tracking branch 'upstream/master' into url-parsing-support
peppy Jan 29, 2018
df221b6
Remove usage of ValueTuple to allow for dynamic recompilation
peppy Jan 29, 2018
c07a31a
Add new (failing) tests
peppy Jan 29, 2018
f996acd
Add back old non-visual tests
peppy Jan 29, 2018
1920a4e
Prepare tests for fixing
peppy Jan 29, 2018
1dbaf9b
Add many more tests
peppy Jan 30, 2018
dd2731b
Add support for markdown style links
peppy Jan 30, 2018
662c7c5
Fix osump links
peppy Jan 30, 2018
d81d884
Remove unnecessary paren handling from regex
peppy Jan 30, 2018
e5188fd
Add better channel test cases (testing non-existent channels)
peppy Jan 30, 2018
53129e5
Fix text getting truncated after last link in chat line
peppy Jan 30, 2018
28b67e3
Merge branch 'master' into url-parsing-support
peppy Jan 30, 2018
a94b4a9
Merge branch 'master' into url-parsing-support
peppy Jan 30, 2018
2ffe16d
Improve clarity and coverage of unit tests
peppy Jan 30, 2018
d332a2d
Merge branch 'master' into url-parsing-support
smoogipoo Feb 1, 2018
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
247 changes: 247 additions & 0 deletions osu.Game.Tests/Chat/MessageFormatterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using NUnit.Framework;
using osu.Game.Online.Chat;

namespace osu.Game.Tests.Chat
{
[TestFixture]
public class MessageFormatterTests
{
[Test]
public void TestBareLink()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is a http://www.basic-link.com/?test=test." });

Assert.AreEqual(result.Content, result.DisplayContent);
Assert.AreEqual(1, result.Links.Count);
Assert.AreEqual("http://www.basic-link.com/?test=test", result.Links[0].Url);
Assert.AreEqual(10, result.Links[0].Index);
Assert.AreEqual(36, result.Links[0].Length);
}

[Test]
public void TestMultipleComplexLinks()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is a http://test.io/link#fragment. (see https://twitter.com). Also, This string should not be altered. http://example.com/" });

Assert.AreEqual(result.Content, result.DisplayContent);
Assert.AreEqual(3, result.Links.Count);

Assert.AreEqual("http://test.io/link#fragment", result.Links[0].Url);
Assert.AreEqual(10, result.Links[0].Index);
Assert.AreEqual(28, result.Links[0].Length);

Assert.AreEqual("https://twitter.com", result.Links[1].Url);
Assert.AreEqual(45, result.Links[1].Index);
Assert.AreEqual(19, result.Links[1].Length);

Assert.AreEqual("http://example.com/", result.Links[2].Url);
Assert.AreEqual(108, result.Links[2].Index);
Assert.AreEqual(19, result.Links[2].Length);
}

[Test]
public void TestAjaxLinks()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "https://twitter.com/#!/hashbanglinks" });

Assert.AreEqual(result.Content, result.DisplayContent);
Assert.AreEqual(result.Content, result.Links[0].Url);
Assert.AreEqual(0, result.Links[0].Index);
Assert.AreEqual(36, result.Links[0].Length);
}

[Test]
public void TestUnixHomeLinks()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "http://www.chiark.greenend.org.uk/~sgtatham/putty/" });

Assert.AreEqual(result.Content, result.DisplayContent);
Assert.AreEqual(result.Content, result.Links[0].Url);
Assert.AreEqual(0, result.Links[0].Index);
Assert.AreEqual(50, result.Links[0].Length);
}

[Test]
public void TestCaseInsensitiveLinks()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "look: http://puu.sh/7Ggh8xcC6/asf0asd9876.NEF" });

Assert.AreEqual(result.Content, result.DisplayContent);
Assert.AreEqual(6, result.Links[0].Index);
Assert.AreEqual(39, result.Links[0].Length);
}

[Test]
public void TestWikiLink()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is a [[Wiki Link]]." });

Assert.AreEqual("This is a Wiki Link.", result.DisplayContent);
Assert.AreEqual(1, result.Links.Count);
Assert.AreEqual("https://osu.ppy.sh/wiki/Wiki Link", result.Links[0].Url);
Assert.AreEqual(10, result.Links[0].Index);
Assert.AreEqual(9, result.Links[0].Length);
}

[Test]
public void TestMultiWikiLink()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is a [[Wiki Link]] [[Wiki:Link]][[Wiki.Link]]." });

Assert.AreEqual("This is a Wiki Link Wiki:LinkWiki.Link.", result.DisplayContent);
Assert.AreEqual(3, result.Links.Count);

Assert.AreEqual("https://osu.ppy.sh/wiki/Wiki Link", result.Links[0].Url);
Assert.AreEqual(10, result.Links[0].Index);
Assert.AreEqual(9, result.Links[0].Length);

Assert.AreEqual("https://osu.ppy.sh/wiki/Wiki:Link", result.Links[1].Url);
Assert.AreEqual(20, result.Links[1].Index);
Assert.AreEqual(9, result.Links[1].Length);

Assert.AreEqual("https://osu.ppy.sh/wiki/Wiki.Link", result.Links[2].Url);
Assert.AreEqual(29, result.Links[2].Index);
Assert.AreEqual(9, result.Links[2].Length);
}

[Test]
public void TestOldFormatLink()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is a (simple test)[https://osu.ppy.sh] of links." });

Assert.AreEqual("This is a simple test of links.", result.DisplayContent);
Assert.AreEqual(1, result.Links.Count);
Assert.AreEqual("https://osu.ppy.sh", result.Links[0].Url);
Assert.AreEqual(10, result.Links[0].Index);
Assert.AreEqual(11, result.Links[0].Length);
}

[Test]
public void TestNewFormatLink()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is a [https://osu.ppy.sh simple test]." });

Assert.AreEqual("This is a simple test.", result.DisplayContent);
Assert.AreEqual(1, result.Links.Count);
Assert.AreEqual("https://osu.ppy.sh", result.Links[0].Url);
Assert.AreEqual(10, result.Links[0].Index);
Assert.AreEqual(11, result.Links[0].Length);
}

[Test]
public void TestMarkdownFormatLink()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is a [simple test](https://osu.ppy.sh)." });

Assert.AreEqual("This is a simple test.", result.DisplayContent);
Assert.AreEqual(1, result.Links.Count);
Assert.AreEqual("https://osu.ppy.sh", result.Links[0].Url);
Assert.AreEqual(10, result.Links[0].Index);
Assert.AreEqual(11, result.Links[0].Length);
}

[Test]
public void TestChannelLink()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is an #english and #japanese." });

Assert.AreEqual(result.Content, result.DisplayContent);
Assert.AreEqual(2, result.Links.Count);
Assert.AreEqual("osu://chan/#english", result.Links[0].Url);
Assert.AreEqual("osu://chan/#japanese", result.Links[1].Url);
}

[Test]
public void TestOsuProtocol()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is a custom protocol osu://chan/#english." });

Assert.AreEqual(result.Content, result.DisplayContent);
Assert.AreEqual(1, result.Links.Count);
Assert.AreEqual("osu://chan/#english", result.Links[0].Url);
Assert.AreEqual(26, result.Links[0].Index);
Assert.AreEqual(19, result.Links[0].Length);

result = MessageFormatter.FormatMessage(new Message { Content = "This is a [custom protocol](osu://chan/#english)." });

Assert.AreEqual("This is a custom protocol.", result.DisplayContent);
Assert.AreEqual(1, result.Links.Count);
Assert.AreEqual("osu://chan/#english", result.Links[0].Url);
Assert.AreEqual("#english", result.Links[0].Argument);
Assert.AreEqual(10, result.Links[0].Index);
Assert.AreEqual(15, result.Links[0].Length);
}

[Test]
public void TestOsuMpProtocol()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "Join my multiplayer game osump://12346." });

Assert.AreEqual(result.Content, result.DisplayContent);
Assert.AreEqual(1, result.Links.Count);
Assert.AreEqual("osump://12346", result.Links[0].Url);
Assert.AreEqual(25, result.Links[0].Index);
Assert.AreEqual(13, result.Links[0].Length);
}

[Test]
public void TestRecursiveBreaking()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is a [https://osu.ppy.sh [[simple test]]]." });

Assert.AreEqual("This is a [[simple test]].", result.DisplayContent);
Assert.AreEqual(1, result.Links.Count);
Assert.AreEqual("https://osu.ppy.sh", result.Links[0].Url);
Assert.AreEqual(10, result.Links[0].Index);
Assert.AreEqual(15, result.Links[0].Length);
}

[Test]
public void TestLinkComplex()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "This is a [http://www.simple-test.com simple test] with some [traps] and [[wiki links]]. Don't forget to visit https://osu.ppy.sh (now!)[http://google.com]\uD83D\uDE12" });

Assert.AreEqual("This is a simple test with some [traps] and wiki links. Don't forget to visit https://osu.ppy.sh now!\0\0\0", result.DisplayContent);
Assert.AreEqual(5, result.Links.Count);

Link f = result.Links.Find(l => l.Url == "https://osu.ppy.sh/wiki/wiki links");
Assert.AreEqual(44, f.Index);
Assert.AreEqual(10, f.Length);

f = result.Links.Find(l => l.Url == "http://www.simple-test.com");
Assert.AreEqual(10, f.Index);
Assert.AreEqual(11, f.Length);

f = result.Links.Find(l => l.Url == "http://google.com");
Assert.AreEqual(97, f.Index);
Assert.AreEqual(4, f.Length);

f = result.Links.Find(l => l.Url == "https://osu.ppy.sh");
Assert.AreEqual(78, f.Index);
Assert.AreEqual(18, f.Length);

f = result.Links.Find(l => l.Url == "\uD83D\uDE12");
Assert.AreEqual(101, f.Index);
Assert.AreEqual(3, f.Length);
}

[Test]
public void TestEmoji()
{
Message result = MessageFormatter.FormatMessage(new Message { Content = "Hello world\uD83D\uDE12<--This is an emoji,There are more:\uD83D\uDE10\uD83D\uDE00,\uD83D\uDE20" });
Assert.AreEqual("Hello world\0\0\0<--This is an emoji,There are more:\0\0\0\0\0\0,\0\0\0", result.DisplayContent);
Assert.AreEqual(result.Links.Count, 4);
Assert.AreEqual(result.Links[0].Index, 11);
Assert.AreEqual(result.Links[1].Index, 49);
Assert.AreEqual(result.Links[2].Index, 52);
Assert.AreEqual(result.Links[3].Index, 56);
Assert.AreEqual(result.Links[0].Url, "\uD83D\uDE12");
Assert.AreEqual(result.Links[1].Url, "\uD83D\uDE10");
Assert.AreEqual(result.Links[2].Url, "\uD83D\uDE00");
Assert.AreEqual(result.Links[3].Url, "\uD83D\uDE20");
}
}
}
Loading