feat: Show FrankerFaceZ channel badges (#5119)
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "providers/bttv/BttvEmotes.hpp"
|
||||
#include "providers/bttv/BttvLiveUpdates.hpp"
|
||||
#include "providers/bttv/liveupdates/BttvLiveUpdateMessages.hpp"
|
||||
#include "providers/ffz/FfzBadges.hpp"
|
||||
#include "providers/ffz/FfzEmotes.hpp"
|
||||
#include "providers/recentmessages/Api.hpp"
|
||||
#include "providers/seventv/eventapi/Dispatch.hpp"
|
||||
@@ -333,6 +334,14 @@ void TwitchChannel::refreshFFZChannelEmotes(bool manualRefresh)
|
||||
std::forward<decltype(vipBadge)>(vipBadge));
|
||||
}
|
||||
},
|
||||
[this, weak = weakOf<Channel>(this)](auto &&channelBadges) {
|
||||
if (auto shared = weak.lock())
|
||||
{
|
||||
this->tgFfzChannelBadges_.guard();
|
||||
this->ffzChannelBadges_ =
|
||||
std::forward<decltype(channelBadges)>(channelBadges);
|
||||
}
|
||||
},
|
||||
manualRefresh);
|
||||
}
|
||||
|
||||
@@ -1707,6 +1716,33 @@ std::optional<EmotePtr> TwitchChannel::twitchBadge(const QString &set,
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::vector<FfzBadges::Badge> TwitchChannel::ffzChannelBadges(
|
||||
const QString &userID) const
|
||||
{
|
||||
this->tgFfzChannelBadges_.guard();
|
||||
|
||||
auto it = this->ffzChannelBadges_.find(userID);
|
||||
if (it == this->ffzChannelBadges_.end())
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<FfzBadges::Badge> badges;
|
||||
|
||||
const auto *ffzBadges = getIApp()->getFfzBadges();
|
||||
|
||||
for (const auto &badgeID : it->second)
|
||||
{
|
||||
auto badge = ffzBadges->getBadge(badgeID);
|
||||
if (badge.has_value())
|
||||
{
|
||||
badges.emplace_back(*badge);
|
||||
}
|
||||
}
|
||||
|
||||
return badges;
|
||||
}
|
||||
|
||||
std::optional<EmotePtr> TwitchChannel::ffzCustomModBadge() const
|
||||
{
|
||||
return this->ffzCustomModBadge_.get();
|
||||
|
||||
@@ -6,8 +6,11 @@
|
||||
#include "common/ChannelChatters.hpp"
|
||||
#include "common/Common.hpp"
|
||||
#include "common/UniqueAccess.hpp"
|
||||
#include "providers/ffz/FfzBadges.hpp"
|
||||
#include "providers/ffz/FfzEmotes.hpp"
|
||||
#include "providers/twitch/TwitchEmotes.hpp"
|
||||
#include "util/QStringHash.hpp"
|
||||
#include "util/ThreadGuard.hpp"
|
||||
|
||||
#include <boost/circular_buffer/space_optimized.hpp>
|
||||
#include <boost/signals2.hpp>
|
||||
@@ -200,6 +203,10 @@ public:
|
||||
std::optional<EmotePtr> ffzCustomVipBadge() const;
|
||||
std::optional<EmotePtr> twitchBadge(const QString &set,
|
||||
const QString &version) const;
|
||||
/**
|
||||
* Returns a list of channel-specific FrankerFaceZ badges for the given user
|
||||
*/
|
||||
std::vector<FfzBadges::Badge> ffzChannelBadges(const QString &userID) const;
|
||||
|
||||
// Cheers
|
||||
std::optional<CheerEmote> cheerEmote(const QString &string);
|
||||
@@ -393,6 +400,9 @@ protected:
|
||||
Atomic<std::optional<EmotePtr>> ffzCustomModBadge_;
|
||||
Atomic<std::optional<EmotePtr>> ffzCustomVipBadge_;
|
||||
|
||||
FfzChannelBadgeMap ffzChannelBadges_;
|
||||
ThreadGuard tgFfzChannelBadges_;
|
||||
|
||||
private:
|
||||
// Badges
|
||||
UniqueAccess<std::map<QString, std::map<QString, EmotePtr>>>
|
||||
|
||||
@@ -1447,6 +1447,18 @@ void TwitchMessageBuilder::appendFfzBadges()
|
||||
this->emplace<FfzBadgeElement>(
|
||||
badge.emote, MessageElementFlag::BadgeFfz, badge.color);
|
||||
}
|
||||
|
||||
if (this->twitchChannel == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &badge :
|
||||
this->twitchChannel->ffzChannelBadges(this->userId_))
|
||||
{
|
||||
this->emplace<FfzBadgeElement>(
|
||||
badge.emote, MessageElementFlag::BadgeFfz, badge.color);
|
||||
}
|
||||
}
|
||||
|
||||
void TwitchMessageBuilder::appendSeventvBadges()
|
||||
|
||||
Reference in New Issue
Block a user