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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 28 deletions

View file

@ -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: 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: Sorted usernames in `Users joined/parted` messages alphabetically. (#3421)
- Minor: Mod list, VIP list, and Users joined/parted messages are now searchable. (#3426) - 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: 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 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) - Minor: Add feedback when using the whisper command `/w` incorrectly. (#3439)

View file

@ -383,18 +383,9 @@ void EmotePopup::loadEmojis(Channel &channel, EmojiMap &emojiMap,
channel.addMessage(makeEmojiMessage(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 = auto twitchEmoteSets =
getApp()->accounts->twitch.getCurrent()->accessEmotes()->emoteSets; getApp()->accounts->twitch.getCurrent()->accessEmotes()->emoteSets;
std::vector<std::shared_ptr<TwitchAccount::EmoteSet>> twitchGlobalEmotes{}; std::vector<std::shared_ptr<TwitchAccount::EmoteSet>> twitchGlobalEmotes{};
@ -418,22 +409,6 @@ void EmotePopup::filterEmotes(const QString &searchText)
searchText, getApp()->twitch2->getBttvEmotes().emotes()); searchText, getApp()->twitch2->getBttvEmotes().emotes());
auto ffzGlobalEmotes = this->filterEmoteMap( auto ffzGlobalEmotes = this->filterEmoteMap(
searchText, getApp()->twitch2->getFfzEmotes().emotes()); 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 // twitch
addEmoteSets(twitchGlobalEmotes, *searchChannel, *searchChannel, addEmoteSets(twitchGlobalEmotes, *searchChannel, *searchChannel,
@ -447,6 +422,15 @@ void EmotePopup::filterEmotes(const QString &searchText)
addEmotes(*searchChannel, *ffzGlobalEmotes, "FrankerFaceZ (Global)", addEmotes(*searchChannel, *ffzGlobalEmotes, "FrankerFaceZ (Global)",
MessageElementFlag::FfzEmote); MessageElementFlag::FfzEmote);
if (!this->twitchChannel_)
{
return;
}
auto bttvChannelEmotes =
this->filterEmoteMap(searchText, this->twitchChannel_->bttvEmotes());
auto ffzChannelEmotes =
this->filterEmoteMap(searchText, this->twitchChannel_->ffzEmotes());
// channel // channel
if (bttvChannelEmotes->size() > 0) if (bttvChannelEmotes->size() > 0)
addEmotes(*searchChannel, *bttvChannelEmotes, "BetterTTV (Channel)", addEmotes(*searchChannel, *bttvChannelEmotes, "BetterTTV (Channel)",
@ -454,7 +438,36 @@ void EmotePopup::filterEmotes(const QString &searchText)
if (ffzChannelEmotes->size() > 0) if (ffzChannelEmotes->size() > 0)
addEmotes(*searchChannel, *ffzChannelEmotes, "FrankerFaceZ (Channel)", addEmotes(*searchChannel, *ffzChannelEmotes, "FrankerFaceZ (Channel)",
MessageElementFlag::FfzEmote); 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 // emojis
if (emojiCount > 0) if (emojiCount > 0)
this->loadEmojis(*searchChannel, filteredEmojis, "Emojis"); this->loadEmojis(*searchChannel, filteredEmojis, "Emojis");

View file

@ -46,6 +46,8 @@ private:
void loadEmojis(ChannelView &view, EmojiMap &emojiMap); void loadEmojis(ChannelView &view, EmojiMap &emojiMap);
void loadEmojis(Channel &channel, EmojiMap &emojiMap, const QString &title); void loadEmojis(Channel &channel, EmojiMap &emojiMap, const QString &title);
void filterTwitchEmotes(std::shared_ptr<Channel> searchChannel,
const QString &searchText);
void filterEmotes(const QString &text); void filterEmotes(const QString &text);
EmoteMap *filterEmoteMap(const QString &text, EmoteMap *filterEmoteMap(const QString &text,
std::shared_ptr<const EmoteMap> emotes); std::shared_ptr<const EmoteMap> emotes);