mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Made emote search not crash in non-Twitch channels. (#3527)
This commit is contained in:
parent
1d272c399b
commit
6f7c3c8d7e
|
@ -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)
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue