diff --git a/CHANGELOG.md b/CHANGELOG.md index 3749d52e..915fe939 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,7 +43,7 @@ - Minor: Added autocompletion for default Twitch commands starting with the dot (e.g. `.mods` which does the same as `/mods`). (#3144) - Minor: Sorted usernames in `Users joined/parted` messages alphabetically. (#3421) - Minor: Mod list, VIP list, and Users joined/parted messages are now searchable. (#3426) -- Minor: Add search to emote popup. (#3404) +- Minor: Add search to emote popup. (#3404, #3527) - 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) - Minor: Add feedback when using the whisper command `/w` incorrectly. (#3439) diff --git a/src/widgets/dialogs/EmotePopup.cpp b/src/widgets/dialogs/EmotePopup.cpp index d9a1ccc2..90cfc756 100644 --- a/src/widgets/dialogs/EmotePopup.cpp +++ b/src/widgets/dialogs/EmotePopup.cpp @@ -383,18 +383,9 @@ void EmotePopup::loadEmojis(Channel &channel, EmojiMap &emojiMap, channel.addMessage(makeEmojiMessage(emojiMap)); } -void EmotePopup::filterEmotes(const QString &searchText) +void EmotePopup::filterTwitchEmotes(std::shared_ptr searchChannel, + const QString &searchText) { - if (searchText.length() == 0) - { - this->notebook_->show(); - this->searchView_->hide(); - - return; - } - - auto searchChannel = std::make_shared("", Channel::Type::None); - auto twitchEmoteSets = getApp()->accounts->twitch.getCurrent()->accessEmotes()->emoteSets; std::vector> twitchGlobalEmotes{}; @@ -418,22 +409,6 @@ void EmotePopup::filterEmotes(const QString &searchText) searchText, getApp()->twitch2->getBttvEmotes().emotes()); auto ffzGlobalEmotes = this->filterEmoteMap( searchText, getApp()->twitch2->getFfzEmotes().emotes()); - auto bttvChannelEmotes = - this->filterEmoteMap(searchText, this->twitchChannel_->bttvEmotes()); - auto ffzChannelEmotes = - this->filterEmoteMap(searchText, this->twitchChannel_->ffzEmotes()); - - EmojiMap filteredEmojis{}; - int emojiCount = 0; - - getApp()->emotes->emojis.emojis.each( - [&, searchText](const auto &name, std::shared_ptr &emoji) { - if (emoji->shortCodes[0].contains(searchText, Qt::CaseInsensitive)) - { - filteredEmojis.insert(name, emoji); - emojiCount++; - } - }); // twitch addEmoteSets(twitchGlobalEmotes, *searchChannel, *searchChannel, @@ -447,6 +422,15 @@ void EmotePopup::filterEmotes(const QString &searchText) addEmotes(*searchChannel, *ffzGlobalEmotes, "FrankerFaceZ (Global)", MessageElementFlag::FfzEmote); + if (!this->twitchChannel_) + { + return; + } + + auto bttvChannelEmotes = + this->filterEmoteMap(searchText, this->twitchChannel_->bttvEmotes()); + auto ffzChannelEmotes = + this->filterEmoteMap(searchText, this->twitchChannel_->ffzEmotes()); // channel if (bttvChannelEmotes->size() > 0) addEmotes(*searchChannel, *bttvChannelEmotes, "BetterTTV (Channel)", @@ -454,7 +438,36 @@ void EmotePopup::filterEmotes(const QString &searchText) if (ffzChannelEmotes->size() > 0) addEmotes(*searchChannel, *ffzChannelEmotes, "FrankerFaceZ (Channel)", MessageElementFlag::FfzEmote); +} +void EmotePopup::filterEmotes(const QString &searchText) +{ + if (searchText.length() == 0) + { + this->notebook_->show(); + this->searchView_->hide(); + + return; + } + auto searchChannel = std::make_shared("", Channel::Type::None); + + // true in special channels like /mentions + if (this->channel_->isTwitchChannel()) + { + this->filterTwitchEmotes(searchChannel, searchText); + } + + EmojiMap filteredEmojis{}; + int emojiCount = 0; + + getApp()->emotes->emojis.emojis.each( + [&, searchText](const auto &name, std::shared_ptr &emoji) { + if (emoji->shortCodes[0].contains(searchText, Qt::CaseInsensitive)) + { + filteredEmojis.insert(name, emoji); + emojiCount++; + } + }); // emojis if (emojiCount > 0) this->loadEmojis(*searchChannel, filteredEmojis, "Emojis"); diff --git a/src/widgets/dialogs/EmotePopup.hpp b/src/widgets/dialogs/EmotePopup.hpp index 22e18373..8985e520 100644 --- a/src/widgets/dialogs/EmotePopup.hpp +++ b/src/widgets/dialogs/EmotePopup.hpp @@ -46,6 +46,8 @@ private: void loadEmojis(ChannelView &view, EmojiMap &emojiMap); void loadEmojis(Channel &channel, EmojiMap &emojiMap, const QString &title); + void filterTwitchEmotes(std::shared_ptr searchChannel, + const QString &searchText); void filterEmotes(const QString &text); EmoteMap *filterEmoteMap(const QString &text, std::shared_ptr emotes);