Fixed "raw mentions" not being clickable with special characters appended to them (#2212)

This commit is contained in:
Paweł 2020-11-22 14:02:55 +01:00 committed by GitHub
parent 98035c5c83
commit b79d5fa6f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View file

@ -2,6 +2,7 @@
## Unversioned
- Minor: Made `Try to find usernames without @ prefix` option still resolve usernames when special characters (commas, dots, (semi)colons, exclamation mark, question mark) are appended to them. (#2212)
- Minor: Made usercard update user's display name (#2160)
- Minor: Added placeholder text for message text input box. (#2143, #2149)
- Minor: Added support for FrankerFaceZ badges. (#2101, part of #1658)

View file

@ -29,8 +29,13 @@
namespace {
const QString regexHelpString("(\\w+)[.,!?;:]*?$");
// matches a mention with punctuation at the end, like "@username," or "@username!!!" where capture group would return "username"
const QRegularExpression mentionRegex("^@(\\w+)[.,!?;]*?$");
const QRegularExpression mentionRegex("^@" + regexHelpString);
// if findAllUsernames setting is enabled, matches strings like in the examples above, but without @ symbol at the beginning
const QRegularExpression allUsernamesMentionRegex("^" + regexHelpString);
const QSet<QString> zeroWidthEmotes{
"SoSnowy", "IceCold", "SantaHat", "TopHat",
@ -474,6 +479,7 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
if (match.hasMatch())
{
QString username = match.captured(1);
this->emplace<TextElement>(string, MessageElementFlag::BoldUsername,
textColor, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, username});
@ -488,15 +494,18 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
if (this->twitchChannel != nullptr && getSettings()->findAllUsernames)
{
auto chatters = this->twitchChannel->accessChatters();
if (chatters->contains(string))
auto match = allUsernamesMentionRegex.match(string);
QString username = match.captured(1);
if (match.hasMatch() && chatters->contains(username))
{
this->emplace<TextElement>(string, MessageElementFlag::BoldUsername,
textColor, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, string});
->setLink({Link::UserInfo, username});
this->emplace<TextElement>(
string, MessageElementFlag::NonBoldUsername, textColor)
->setLink({Link::UserInfo, string});
->setLink({Link::UserInfo, username});
return;
}
}