diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f7184795..f8f51a2db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/providers/irc/IrcMessageBuilder.cpp b/src/providers/irc/IrcMessageBuilder.cpp index aa862d4aa..b58957f86 100644 --- a/src/providers/irc/IrcMessageBuilder.cpp +++ b/src/providers/irc/IrcMessageBuilder.cpp @@ -109,8 +109,7 @@ void IrcMessageBuilder::addWords(const QStringList &words) if (!i.hasNext()) { - this->emplace(string, MessageElementFlag::Text, - textColor); + this->addText(string, textColor); continue; } @@ -132,10 +131,9 @@ void IrcMessageBuilder::addWords(const QStringList &words) { textColor = defaultColor; } - this->emplace( - string.mid(lastPos, match.capturedStart() - lastPos), - MessageElementFlag::Text, textColor) - ->setTrailingSpace(false); + this->addText( + string.mid(lastPos, match.capturedStart() - lastPos), + 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(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; diff --git a/src/providers/irc/IrcMessageBuilder.hpp b/src/providers/irc/IrcMessageBuilder.hpp index d6a83da8a..0a380475d 100644 --- a/src/providers/irc/IrcMessageBuilder.hpp +++ b/src/providers/irc/IrcMessageBuilder.hpp @@ -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