Skip to content

Commit

Permalink
Implement workaround for combined emoji (Chatterino#3469)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mm2PL authored Jan 11, 2022
1 parent dfa3818 commit 8200998
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- Minor: Mod list, VIP list, and Users joined/parted messages are now searchable. (#3426)
- Minor: Add search to emote popup. (#3404)
- Minor: Messages can now be highlighted by subscriber or founder badges. (#3445)
- Minor: Add workaround for multipart emoji as described in [the RFC](https://mm2pl.github.io/emoji_rfc.pdf). (#3469)
- Bugfix: Fix Split Input hotkeys not being available when input is hidden (#3362)
- Bugfix: Fixed colored usernames sometimes not working. (#3170)
- Bugfix: Restored ability to send duplicate `/me` messages. (#3166)
Expand Down
10 changes: 9 additions & 1 deletion src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ void sendWhisperMessage(const QString &text)
// (hemirt) pajlada: "we should not be sending whispers through jtv, but
// rather to your own username"
auto app = getApp();
app->twitch.server->sendMessage("jtv", text.simplified());
QString toSend = text.simplified();

// This is to make sure that combined emoji go through properly, see
// https://github.com/Chatterino/chatterino2/issues/3384 and
// https://mm2pl.github.io/emoji_rfc.pdf for more details
// Constants used here are defined in TwitchChannel.hpp
toSend.replace(ZERO_WIDTH_JOINER, ESCAPE_TAG);

app->twitch.server->sendMessage("jtv", toSend);
}

bool appendWhisperMessageWordsLocally(const QStringList &words)
Expand Down
17 changes: 13 additions & 4 deletions src/providers/twitch/IrcMessageHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,15 @@ std::vector<MessagePtr> IrcMessageHandler::parsePrivMessage(
void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message,
TwitchIrcServer &server)
{
this->addMessage(message, message->target(), message->content(), server,
false, message->isAction());
// This is to make sure that combined emoji go through properly, see
// https://github.com/Chatterino/chatterino2/issues/3384 and
// https://mm2pl.github.io/emoji_rfc.pdf for more details
// Constants used here are defined in TwitchChannel.hpp

this->addMessage(
message, message->target(),
message->content().replace(COMBINED_FIXER, ZERO_WIDTH_JOINER), server,
false, message->isAction());
}

void IrcMessageHandler::addMessage(Communi::IrcMessage *_message,
Expand Down Expand Up @@ -560,8 +567,10 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message)

auto c = getApp()->twitch.server->whispersChannel.get();

TwitchMessageBuilder builder(c, message, args, message->parameter(1),
false);
TwitchMessageBuilder builder(
c, message, args,
message->parameter(1).replace(COMBINED_FIXER, ZERO_WIDTH_JOINER),
false);

if (builder.isIgnored())
{
Expand Down
10 changes: 8 additions & 2 deletions src/providers/twitch/TwitchChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ namespace {

for (const auto jsonMessage : jsonMessages)
{
auto content = jsonMessage.toString().toUtf8();
auto content = jsonMessage.toString();
content.replace(COMBINED_FIXER, ZERO_WIDTH_JOINER);

auto message = Communi::IrcMessage::fromData(content, nullptr);
auto message =
Communi::IrcMessage::fromData(content.toUtf8(), nullptr);

if (message->command() == "CLEARCHAT")
{
Expand Down Expand Up @@ -365,6 +367,10 @@ void TwitchChannel::sendMessage(const QString &message)
// Do last message processing
QString parsedMessage = app->emotes->emojis.replaceShortCodes(message);

// This is to make sure that combined emoji go through properly, see
// https://github.com/Chatterino/chatterino2/issues/3384 and
// https://mm2pl.github.io/emoji_rfc.pdf for more details
parsedMessage.replace(ZERO_WIDTH_JOINER, ESCAPE_TAG);
parsedMessage = parsedMessage.simplified();

if (parsedMessage.isEmpty())
Expand Down
16 changes: 16 additions & 0 deletions src/providers/twitch/TwitchChannel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@

namespace chatterino {

// This is to make sure that combined emoji go through properly, see
// https://github.com/Chatterino/chatterino2/issues/3384 and
// https://mm2pl.github.io/emoji_rfc.pdf for more details
const QString ZERO_WIDTH_JOINER = QString(QChar(0x200D));

// Here be MSVC: Do NOT replace with "\U" literal, it will fail silently.
namespace {
const QChar ESCAPE_TAG_CHARS[2] = {QChar::highSurrogate(0xE0002),
QChar::lowSurrogate(0xE0002)};
}
const QString ESCAPE_TAG = QString(ESCAPE_TAG_CHARS, 2);

const static QRegularExpression COMBINED_FIXER(
QString("(?<!%1)%1").arg(ESCAPE_TAG),
QRegularExpression::UseUnicodePropertiesOption);

enum class HighlightState;

struct Emote;
Expand Down

0 comments on commit 8200998

Please sign in to comment.