Fetch FFZ channel emotes with channel id instead of name

This commit is contained in:
apa420 2019-08-27 18:45:55 +00:00 committed by fourtf
parent 450f3bc492
commit a624d14a4f
8 changed files with 41 additions and 23 deletions

View file

@ -151,12 +151,12 @@ void FfzEmotes::loadEmotes()
.execute(); .execute();
} }
void FfzEmotes::loadChannel(const QString &channelName, void FfzEmotes::loadChannel(const QString &channelId,
std::function<void(EmoteMap &&)> callback) std::function<void(EmoteMap &&)> callback)
{ {
log("[FFZEmotes] Reload FFZ Channel Emotes for channel {}\n", channelName); log("[FFZEmotes] Reload FFZ Channel Emotes for channel {}\n", channelId);
NetworkRequest("https://api.frankerfacez.com/v1/room/" + channelName) NetworkRequest("https://api.frankerfacez.com/v1/room/id/" + channelId)
.timeout(20000) .timeout(20000)
.onSuccess([callback = std::move(callback)](auto result) -> Outcome { .onSuccess([callback = std::move(callback)](auto result) -> Outcome {
@ -165,7 +165,7 @@ void FfzEmotes::loadChannel(const QString &channelName,
callback(std::move(pair.second)); callback(std::move(pair.second));
return pair.first; return pair.first;
}) })
.onError([channelName](int result) { .onError([channelId](int result) {
if (result == 203) if (result == 203)
{ {
// User does not have any FFZ emotes // User does not have any FFZ emotes
@ -176,12 +176,12 @@ void FfzEmotes::loadChannel(const QString &channelName,
{ {
// TODO: Auto retry in case of a timeout, with a delay // TODO: Auto retry in case of a timeout, with a delay
log("Fetching FFZ emotes for channel {} failed due to timeout", log("Fetching FFZ emotes for channel {} failed due to timeout",
channelName); channelId);
return true; return true;
} }
log("Error fetching FFZ emotes for channel {}, error {}", log("Error fetching FFZ emotes for channel {}, error {}", channelId,
channelName, result); result);
return true; return true;
}) })

View file

@ -22,7 +22,7 @@ public:
std::shared_ptr<const EmoteMap> emotes() const; std::shared_ptr<const EmoteMap> emotes() const;
boost::optional<EmotePtr> emote(const EmoteName &name) const; boost::optional<EmotePtr> emote(const EmoteName &name) const;
void loadEmotes(); void loadEmotes();
static void loadChannel(const QString &channelName, static void loadChannel(const QString &channelId,
std::function<void(EmoteMap &&)> callback); std::function<void(EmoteMap &&)> callback);
private: private:

View file

@ -22,7 +22,7 @@ ChatroomChannel::ChatroomChannel(const QString &channelName,
} }
} }
void ChatroomChannel::refreshChannelEmotes() void ChatroomChannel::refreshBTTVChannelEmotes()
{ {
if (this->chatroomOwnerId.isEmpty()) if (this->chatroomOwnerId.isEmpty())
{ {
@ -36,17 +36,22 @@ void ChatroomChannel::refreshChannelEmotes()
this->bttvEmotes_.set( this->bttvEmotes_.set(
std::make_shared<EmoteMap>(std::move(emoteMap))); std::make_shared<EmoteMap>(std::move(emoteMap)));
}); });
FfzEmotes::loadChannel(username, [this, weak](auto &&emoteMap) {
if (auto shared = weak.lock())
this->ffzEmotes_.set(
std::make_shared<EmoteMap>(std::move(emoteMap)));
});
if (auto shared = weak.lock()) if (auto shared = weak.lock())
{ {
this->chatroomOwnerName = username; this->chatroomOwnerName = username;
} }
}); });
} }
void ChatroomChannel::refreshFFZChannelEmotes()
{
if (this->chatroomOwnerId.isEmpty())
{
return;
}
FfzEmotes::loadChannel(this->chatroomOwnerId, [this](auto &&emoteMap) {
this->ffzEmotes_.set(std::make_shared<EmoteMap>(std::move(emoteMap)));
});
}
const QString &ChatroomChannel::getDisplayName() const const QString &ChatroomChannel::getDisplayName() const
{ {

View file

@ -13,7 +13,8 @@ protected:
explicit ChatroomChannel(const QString &channelName, explicit ChatroomChannel(const QString &channelName,
TwitchBadges &globalTwitchBadges, TwitchBadges &globalTwitchBadges,
BttvEmotes &globalBttv, FfzEmotes &globalFfz); BttvEmotes &globalBttv, FfzEmotes &globalFfz);
virtual void refreshChannelEmotes() override; virtual void refreshBTTVChannelEmotes() override;
virtual void refreshFFZChannelEmotes() override;
virtual const QString &getDisplayName() const override; virtual const QString &getDisplayName() const override;
QString chatroomOwnerId; QString chatroomOwnerId;

View file

@ -113,6 +113,7 @@ TwitchChannel::TwitchChannel(const QString &name,
this->refreshLiveStatus(); this->refreshLiveStatus();
this->refreshBadges(); this->refreshBadges();
this->refreshCheerEmotes(); this->refreshCheerEmotes();
this->refreshFFZChannelEmotes();
}); });
// timers // timers
@ -135,7 +136,7 @@ TwitchChannel::TwitchChannel(const QString &name,
void TwitchChannel::initialize() void TwitchChannel::initialize()
{ {
this->refreshChatters(); this->refreshChatters();
this->refreshChannelEmotes(); this->refreshBTTVChannelEmotes();
this->refreshBadges(); this->refreshBadges();
this->ffzCustomModBadge_.loadCustomModBadge(); this->ffzCustomModBadge_.loadCustomModBadge();
} }
@ -150,7 +151,7 @@ bool TwitchChannel::canSendMessage() const
return !this->isEmpty(); return !this->isEmpty();
} }
void TwitchChannel::refreshChannelEmotes() void TwitchChannel::refreshBTTVChannelEmotes()
{ {
BttvEmotes::loadChannel( BttvEmotes::loadChannel(
this->getName(), [this, weak = weakOf<Channel>(this)](auto &&emoteMap) { this->getName(), [this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
@ -158,8 +159,12 @@ void TwitchChannel::refreshChannelEmotes()
this->bttvEmotes_.set( this->bttvEmotes_.set(
std::make_shared<EmoteMap>(std::move(emoteMap))); std::make_shared<EmoteMap>(std::move(emoteMap)));
}); });
}
void TwitchChannel::refreshFFZChannelEmotes()
{
FfzEmotes::loadChannel( FfzEmotes::loadChannel(
this->getName(), [this, weak = weakOf<Channel>(this)](auto &&emoteMap) { this->roomId(), [this, weak = weakOf<Channel>(this)](auto &&emoteMap) {
if (auto shared = weak.lock()) if (auto shared = weak.lock())
this->ffzEmotes_.set( this->ffzEmotes_.set(
std::make_shared<EmoteMap>(std::move(emoteMap))); std::make_shared<EmoteMap>(std::move(emoteMap)));

View file

@ -85,7 +85,8 @@ public:
std::shared_ptr<const EmoteMap> bttvEmotes() const; std::shared_ptr<const EmoteMap> bttvEmotes() const;
std::shared_ptr<const EmoteMap> ffzEmotes() const; std::shared_ptr<const EmoteMap> ffzEmotes() const;
virtual void refreshChannelEmotes(); virtual void refreshBTTVChannelEmotes();
virtual void refreshFFZChannelEmotes();
// Badges // Badges
boost::optional<EmotePtr> ffzCustomModBadge() const; boost::optional<EmotePtr> ffzCustomModBadge() const;

View file

@ -663,7 +663,10 @@ void Split::reloadChannelAndSubscriberEmotes()
auto channel = this->getChannel(); auto channel = this->getChannel();
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get())) if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get()))
twitchChannel->refreshChannelEmotes(); {
twitchChannel->refreshBTTVChannelEmotes();
twitchChannel->refreshFFZChannelEmotes();
}
} }
template <typename Iter, typename RandomGenerator> template <typename Iter, typename RandomGenerator>

View file

@ -713,7 +713,10 @@ void SplitHeader::reloadChannelEmotes()
auto channel = this->split_->getChannel(); auto channel = this->split_->getChannel();
if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get())) if (auto twitchChannel = dynamic_cast<TwitchChannel *>(channel.get()))
twitchChannel->refreshChannelEmotes(); {
twitchChannel->refreshFFZChannelEmotes();
twitchChannel->refreshBTTVChannelEmotes();
}
} }
void SplitHeader::reloadSubscriberEmotes() void SplitHeader::reloadSubscriberEmotes()