Files
chatterino2/src/providers/twitch/ChatroomChannel.cpp
Rasmus Karlsson 256a65a12e Load mod badge information from the FFZ API instead of assuming the URL.
This lets us load all sizes of the emote if they are available.

Channel with all versions of the mod badge: https://api.frankerfacez.com/v1/room/pajlada
Channel with only one version of the mod badge: https://api.frankerfacez.com/v1/room/apa420
Channel with no mod badge: https://api.frankerfacez.com/v1/room/forsen
2019-09-08 14:08:18 +02:00

68 lines
1.9 KiB
C++

#include "ChatroomChannel.hpp"
#include <QDebug>
#include "TwitchApi.hpp"
#include "common/Common.hpp"
#include "messages/Emote.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/bttv/LoadBttvChannelEmote.hpp"
#include "singletons/Emotes.hpp"
namespace chatterino {
ChatroomChannel::ChatroomChannel(const QString &channelName,
TwitchBadges &globalTwitchBadges,
BttvEmotes &globalBttv, FfzEmotes &globalFfz)
: TwitchChannel(channelName, globalTwitchBadges, globalBttv, globalFfz)
{
auto listRef = channelName.splitRef(":");
if (listRef.size() > 2)
{
this->chatroomOwnerId = listRef[1].toString();
}
}
void ChatroomChannel::refreshBTTVChannelEmotes()
{
if (this->chatroomOwnerId.isEmpty())
{
return;
}
TwitchApi::findUserName(
this->chatroomOwnerId,
[this, weak = weakOf<Channel>(this)](QString username) {
BttvEmotes::loadChannel(username, [this, weak](auto &&emoteMap) {
if (auto shared = weak.lock())
this->bttvEmotes_.set(
std::make_shared<EmoteMap>(std::move(emoteMap)));
});
if (auto shared = weak.lock())
{
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)));
},
[this](auto &&modBadge) {
this->ffzCustomModBadge_ = std::move(modBadge);
});
}
const QString &ChatroomChannel::getDisplayName() const
{
return this->chatroomOwnerName;
}
} // namespace chatterino