feat(emote-popup): automatically reload Twitch emotes (#5580)

This commit is contained in:
nerix
2024-09-01 13:44:36 +02:00
committed by GitHub
parent 820aa12af6
commit 61b04dbe7b
8 changed files with 79 additions and 15 deletions
+38 -8
View File
@@ -78,6 +78,8 @@ auto makeEmoteMessage(const EmoteMap &map, const MessageElementFlag &emoteFlag)
if (map.empty())
{
MessageBuilder builder;
builder->flags.set(MessageFlag::Centered);
builder->flags.set(MessageFlag::DisableCompactEmotes);
builder.emplace<TextElement>("no emotes available",
MessageElementFlag::Text,
MessageColor::System);
@@ -129,7 +131,7 @@ void addTwitchEmoteSets(const std::shared_ptr<const EmoteMap> &local,
{
if (!local->empty())
{
addEmotes(subChannel, *local, channelName % u" (follower)",
addEmotes(subChannel, *local, channelName % u" (Follower)",
MessageElementFlag::TwitchEmote);
}
@@ -293,6 +295,17 @@ EmotePopup::EmotePopup(QWidget *parent)
});
this->search_->setFocus();
this->signalHolder_.managedConnect(
getApp()->getAccounts()->twitch.emotesReloaded,
[this](auto * /*caller*/, const auto &result) {
if (!result)
{
// some error occurred, no need to reload
return;
}
this->reloadEmotes();
});
}
void EmotePopup::addShortcuts()
@@ -402,9 +415,30 @@ void EmotePopup::loadChannel(ChannelPtr channel)
return;
}
auto subChannel = std::make_shared<Channel>("", Channel::Type::None);
auto globalChannel = std::make_shared<Channel>("", Channel::Type::None);
auto channelChannel = std::make_shared<Channel>("", Channel::Type::None);
this->globalEmotesView_->setChannel(
std::make_shared<Channel>("", Channel::Type::None));
this->subEmotesView_->setChannel(
std::make_shared<Channel>("", Channel::Type::None));
this->channelEmotesView_->setChannel(
std::make_shared<Channel>("", Channel::Type::None));
this->reloadEmotes();
}
void EmotePopup::reloadEmotes()
{
if (this->twitchChannel_ == nullptr)
{
return;
}
auto subChannel = this->subEmotesView_->underlyingChannel();
auto globalChannel = this->globalEmotesView_->underlyingChannel();
auto channelChannel = this->channelEmotesView_->underlyingChannel();
subChannel->clearMessages();
globalChannel->clearMessages();
channelChannel->clearMessages();
// twitch
addTwitchEmoteSets(
@@ -447,10 +481,6 @@ void EmotePopup::loadChannel(ChannelPtr channel)
"7TV", MessageElementFlag::SevenTVEmote);
}
this->globalEmotesView_->setChannel(globalChannel);
this->subEmotesView_->setChannel(subChannel);
this->channelEmotesView_->setChannel(channelChannel);
if (subChannel->getMessageSnapshot().size() == 0)
{
MessageBuilder builder;
+2
View File
@@ -52,6 +52,8 @@ private:
void addShortcuts() override;
bool eventFilter(QObject *object, QEvent *event) override;
void reloadEmotes();
void saveBounds() const;
};