From 27eb2d8abc0018ca4f18092607580d9049dbe9af Mon Sep 17 00:00:00 2001 From: hemirt Date: Thu, 15 Nov 2018 21:11:50 +0100 Subject: [PATCH 1/4] fix surrogatepairs messing position of emotes to be removed (mismatch between actual position, and position in unicode codepoints) --- src/providers/twitch/TwitchMessageBuilder.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 10ca6ba12..38595c70f 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -183,9 +183,18 @@ MessagePtr TwitchMessageBuilder::build() auto app = getApp(); const auto &phrases = app->ignores->phrases.getVector(); auto removeEmotesInRange = - [](int pos, int len, + [&message = this->originalMessage_](int pos, int len, std::vector> &twitchEmotes) mutable { + int emotePos = 0; + for(int i = 0; i < pos; ++i) { + ++emotePos; + if (message.at(i).isLowSurrogate()) { + --emotePos; + } + } + pos = emotePos; + auto it = std::partition(twitchEmotes.begin(), twitchEmotes.end(), [pos, len](const auto &item) { From d2e43d78fc811ec2eb28c06d1ddde6802f13ea43 Mon Sep 17 00:00:00 2001 From: hemirt Date: Sat, 17 Nov 2018 11:00:44 +0100 Subject: [PATCH 2/4] fixes twitch emotes position changes the position in unicodepoints to position in char16 array (qstring) --- src/providers/twitch/TwitchMessageBuilder.cpp | 39 +++++++------------ src/providers/twitch/TwitchMessageBuilder.hpp | 5 +-- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 38595c70f..f7e192308 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -174,11 +174,18 @@ MessagePtr TwitchMessageBuilder::build() if (iterator != this->tags.end()) { QStringList emoteString = iterator.value().toString().split('/'); - + std::vector correctPositions; + for (int i = 0; i < this->originalMessage_.size(); ++i) { + if (!this->originalMessage_.at(i).isLowSurrogate()) { + correctPositions.push_back(i); + } + } for (QString emote : emoteString) { - this->appendTwitchEmote(emote, twitchEmotes); + this->appendTwitchEmote(emote, twitchEmotes, correctPositions); } + + } auto app = getApp(); const auto &phrases = app->ignores->phrases.getVector(); @@ -186,15 +193,6 @@ MessagePtr TwitchMessageBuilder::build() [&message = this->originalMessage_](int pos, int len, std::vector> &twitchEmotes) mutable { - int emotePos = 0; - for(int i = 0; i < pos; ++i) { - ++emotePos; - if (message.at(i).isLowSurrogate()) { - --emotePos; - } - } - pos = emotePos; - auto it = std::partition(twitchEmotes.begin(), twitchEmotes.end(), [pos, len](const auto &item) { @@ -461,17 +459,7 @@ void TwitchMessageBuilder::addWords( variant); } - for (int j = 0; j < word.size(); j++) - { - i++; - - if (word.at(j).isHighSurrogate()) - { - j++; - } - } - - i++; + i += word.size() + 1; } } @@ -944,7 +932,8 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) void TwitchMessageBuilder::appendTwitchEmote( const QString &emote, - std::vector> &vec) + std::vector> &vec, + std::vector & correctPositions) { auto app = getApp(); if (!emote.contains(':')) @@ -972,8 +961,8 @@ void TwitchMessageBuilder::appendTwitchEmote( return; } - auto start = coords.at(0).toInt(); - auto end = coords.at(1).toInt(); + auto start = correctPositions[coords.at(0).toInt()]; + auto end = correctPositions[coords.at(1).toInt()]; if (start >= end || start < 0 || end > this->originalMessage_.length()) { diff --git a/src/providers/twitch/TwitchMessageBuilder.hpp b/src/providers/twitch/TwitchMessageBuilder.hpp index e46bf8d4e..5aa72b204 100644 --- a/src/providers/twitch/TwitchMessageBuilder.hpp +++ b/src/providers/twitch/TwitchMessageBuilder.hpp @@ -55,9 +55,8 @@ private: void appendUsername(); void parseHighlights(bool isPastMsg); - void appendTwitchEmote( - const QString &emote, - std::vector> &vec); + void appendTwitchEmote(const QString &emote, + std::vector> &vec, std::vector &correctPositions); Outcome tryAppendEmote(const EmoteName &name); void addWords( From a5bed6d7e44da069d07ddcc921641552ba9dfac4 Mon Sep 17 00:00:00 2001 From: hemirt Date: Sat, 17 Nov 2018 11:09:31 +0100 Subject: [PATCH 3/4] remove unused variable, format --- src/providers/twitch/TwitchMessageBuilder.cpp | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index f7e192308..cf0423ff8 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -175,8 +175,10 @@ MessagePtr TwitchMessageBuilder::build() { QStringList emoteString = iterator.value().toString().split('/'); std::vector correctPositions; - for (int i = 0; i < this->originalMessage_.size(); ++i) { - if (!this->originalMessage_.at(i).isLowSurrogate()) { + for (int i = 0; i < this->originalMessage_.size(); ++i) + { + if (!this->originalMessage_.at(i).isLowSurrogate()) + { correctPositions.push_back(i); } } @@ -184,13 +186,11 @@ MessagePtr TwitchMessageBuilder::build() { this->appendTwitchEmote(emote, twitchEmotes, correctPositions); } - - } auto app = getApp(); const auto &phrases = app->ignores->phrases.getVector(); auto removeEmotesInRange = - [&message = this->originalMessage_](int pos, int len, + [](int pos, int len, std::vector> &twitchEmotes) mutable { auto it = @@ -933,7 +933,7 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) void TwitchMessageBuilder::appendTwitchEmote( const QString &emote, std::vector> &vec, - std::vector & correctPositions) + std::vector &correctPositions) { auto app = getApp(); if (!emote.contains(':')) @@ -985,19 +985,24 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) { // Special channels, like /whispers and /channels return here // This means they will not render any BTTV or FFZ emotes - if (this->twitchChannel == nullptr) { + if (this->twitchChannel == nullptr) + { auto *app = getApp(); const auto &bttvemotes = app->twitch.server->getBttvEmotes(); const auto &ffzemotes = app->twitch.server->getFfzEmotes(); auto flags = MessageElementFlags(); auto emote = boost::optional{}; { // bttv/ffz emote - if ((emote = bttvemotes.emote(name))) { + if ((emote = bttvemotes.emote(name))) + { flags = MessageElementFlag::BttvEmote; - } else if ((emote = ffzemotes.emote(name))) { + } + else if ((emote = ffzemotes.emote(name))) + { flags = MessageElementFlag::FfzEmote; } - if (emote) { + if (emote) + { this->emplace(emote.get(), flags); return Success; } From 88cffb19492a45f246f585fe4c17d1b9407a29cf Mon Sep 17 00:00:00 2001 From: hemirt Date: Sat, 17 Nov 2018 16:41:22 +0100 Subject: [PATCH 4/4] show users in ignore page sorted --- src/widgets/settingspages/IgnoresPage.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/widgets/settingspages/IgnoresPage.cpp b/src/widgets/settingspages/IgnoresPage.cpp index 62fbe80b0..122dc1109 100644 --- a/src/widgets/settingspages/IgnoresPage.cpp +++ b/src/widgets/settingspages/IgnoresPage.cpp @@ -108,6 +108,7 @@ void IgnoresPage::onShow() { users << ignoredUser.name; } + users.sort(Qt::CaseInsensitive); this->userListModel_.setStringList(users); }