Add support for Emoji in IRC. (#3354)

This commit is contained in:
Mm2PL 2021-11-20 11:18:40 +00:00 committed by GitHub
parent c19fd0d332
commit 6ac15adf45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 8 deletions

View file

@ -32,6 +32,7 @@
- Minor: IRC now parses/displays links like Twitch chat. (#3334)
- Minor: Added button & label for copying login name of user instead of display name in the user info popout. (#3335)
- Minor: Make `/delete` errors a bit more verbose (#3350)
- Minor: Add support for Emoji in IRC (#3354)
- Bugfix: Fixed colored usernames sometimes not working. (#3170)
- Bugfix: Restored ability to send duplicate `/me` messages. (#3166)
- Bugfix: Notifications for moderators about other moderators deleting messages can now be disabled. (#3121)

View file

@ -109,8 +109,7 @@ void IrcMessageBuilder::addWords(const QStringList &words)
if (!i.hasNext())
{
this->emplace<TextElement>(string, MessageElementFlag::Text,
textColor);
this->addText(string, textColor);
continue;
}
@ -132,10 +131,9 @@ void IrcMessageBuilder::addWords(const QStringList &words)
{
textColor = defaultColor;
}
this->emplace<TextElement>(
this->addText(
string.mid(lastPos, match.capturedStart() - lastPos),
MessageElementFlag::Text, textColor)
->setTrailingSpace(false);
textColor, false);
lastPos = match.capturedStart() + match.capturedLength();
}
if (!match.captured(1).isEmpty())
@ -173,13 +171,30 @@ void IrcMessageBuilder::addWords(const QStringList &words)
{
textColor = defaultColor;
}
this->emplace<TextElement>(string.mid(lastPos),
MessageElementFlag::Text, textColor);
this->addText(string.mid(lastPos), textColor);
}
this->message().elements.back()->setTrailingSpace(false);
}
void IrcMessageBuilder::addText(const QString &text, const QColor &color,
bool addSpace)
{
this->textColor_ = color;
for (auto &variant : getApp()->emotes->emojis.parse(text))
{
boost::apply_visitor(
[&](auto &&arg) {
this->addTextOrEmoji(arg);
},
variant);
if (!addSpace)
{
this->message().elements.back()->setTrailingSpace(false);
}
}
}
void IrcMessageBuilder::appendUsername()
{
QString username = this->userName;

View file

@ -36,6 +36,8 @@ private:
void appendUsername();
void addWords(const QStringList &words);
void addText(const QString &text, const QColor &color,
bool addSpace = true);
};
} // namespace chatterino