Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made emote search not crash in non-Twitch channels. #3527

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
67 changes: 40 additions & 27 deletions src/widgets/dialogs/EmotePopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Channel> searchChannel,
const QString &searchText)
{
if (searchText.length() == 0)
{
this->notebook_->show();
this->searchView_->hide();

return;
}

auto searchChannel = std::make_shared<Channel>("", Channel::Type::None);

auto twitchEmoteSets =
getApp()->accounts->twitch.getCurrent()->accessEmotes()->emoteSets;
std::vector<std::shared_ptr<TwitchAccount::EmoteSet>> twitchGlobalEmotes{};
Expand All @@ -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<EmojiData> &emoji) {
if (emoji->shortCodes[0].contains(searchText, Qt::CaseInsensitive))
{
filteredEmojis.insert(name, emoji);
emojiCount++;
}
});

// twitch
addEmoteSets(twitchGlobalEmotes, *searchChannel, *searchChannel,
Expand All @@ -447,14 +422,52 @@ 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)",
MessageElementFlag::BttvEmote);
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>("", 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<EmojiData> &emoji) {
if (emoji->shortCodes[0].contains(searchText, Qt::CaseInsensitive))
{
filteredEmojis.insert(name, emoji);
emojiCount++;
}
});
// emojis
if (emojiCount > 0)
this->loadEmojis(*searchChannel, filteredEmojis, "Emojis");
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/dialogs/EmotePopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class EmotePopup : public BasePopup

void loadEmojis(ChannelView &view, EmojiMap &emojiMap);
void loadEmojis(Channel &channel, EmojiMap &emojiMap, const QString &title);
void filterTwitchEmotes(std::shared_ptr<Channel> searchChannel,
const QString &searchText);
void filterEmotes(const QString &text);
EmoteMap *filterEmoteMap(const QString &text,
std::shared_ptr<const EmoteMap> emotes);
Expand Down