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

This commit is contained in:
Mm2PL
2022-01-22 13:05:01 +00:00
committed by GitHub
parent 1d272c399b
commit 6f7c3c8d7e
3 changed files with 43 additions and 28 deletions
+40 -27
View File
@@ -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{};
@@ -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,
@@ -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>("", 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");
+2
View File
@@ -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<Channel> searchChannel,
const QString &searchText);
void filterEmotes(const QString &text);
EmoteMap *filterEmoteMap(const QString &text,
std::shared_ptr<const EmoteMap> emotes);