fixed crash when moderation buttons are enabled
This commit is contained in:
@@ -51,13 +51,16 @@ auto parseRecentMessages(const QJsonObject &jsonRoot, TwitchChannel &channel)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TwitchChannel::TwitchChannel(const QString &name)
|
||||
TwitchChannel::TwitchChannel(const QString &name, BttvEmotes &bttv,
|
||||
FfzEmotes &ffz)
|
||||
: Channel(name, Channel::Type::Twitch)
|
||||
, bttvEmotes_(std::make_shared<EmoteMap>())
|
||||
, ffzEmotes_(std::make_shared<EmoteMap>())
|
||||
, subscriptionUrl_("https://www.twitch.tv/subs/" + name)
|
||||
, channelUrl_("https://twitch.tv/" + name)
|
||||
, popoutPlayerUrl_("https://player.twitch.tv/?channel=" + name)
|
||||
, globalBttv_(bttv)
|
||||
, globalFfz_(ffz)
|
||||
, bttvEmotes_(std::make_shared<EmoteMap>())
|
||||
, ffzEmotes_(std::make_shared<EmoteMap>())
|
||||
, mod_(false)
|
||||
{
|
||||
log("[TwitchChannel:{}] Opened", name);
|
||||
@@ -290,6 +293,16 @@ TwitchChannel::accessStreamStatus() const
|
||||
return this->streamStatus_.accessConst();
|
||||
}
|
||||
|
||||
const BttvEmotes &TwitchChannel::globalBttv() const
|
||||
{
|
||||
return this->globalBttv_;
|
||||
}
|
||||
|
||||
const FfzEmotes &TwitchChannel::globalFfz() const
|
||||
{
|
||||
return this->globalFfz_;
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> TwitchChannel::bttvEmote(const EmoteName &name) const
|
||||
{
|
||||
auto emotes = this->bttvEmotes_.get();
|
||||
|
||||
@@ -19,6 +19,9 @@ struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
class EmoteMap;
|
||||
|
||||
class FfzEmotes;
|
||||
class BttvEmotes;
|
||||
|
||||
class TwitchServer;
|
||||
|
||||
class TwitchChannel final : public Channel, pajlada::Signals::SignalHolder
|
||||
@@ -60,25 +63,28 @@ public:
|
||||
void addJoinedUser(const QString &user);
|
||||
void addPartedUser(const QString &user);
|
||||
|
||||
// Twitch data
|
||||
bool isLive() const;
|
||||
virtual bool isMod() const override;
|
||||
void setMod(bool value);
|
||||
virtual bool isBroadcaster() const override;
|
||||
|
||||
// Data
|
||||
const QString &subscriptionUrl();
|
||||
const QString &channelUrl();
|
||||
const QString &popoutPlayerUrl();
|
||||
QString roomId() const;
|
||||
void setRoomId(const QString &id);
|
||||
AccessGuard<const RoomModes> accessRoomModes() const;
|
||||
void setRoomModes(const RoomModes &roomModes_);
|
||||
AccessGuard<const StreamStatus> accessStreamStatus() const;
|
||||
|
||||
// Emotes
|
||||
const BttvEmotes &globalBttv() const;
|
||||
const FfzEmotes &globalFfz() const;
|
||||
boost::optional<EmotePtr> bttvEmote(const EmoteName &name) const;
|
||||
boost::optional<EmotePtr> ffzEmote(const EmoteName &name) const;
|
||||
std::shared_ptr<const EmoteMap> bttvEmotes() const;
|
||||
std::shared_ptr<const EmoteMap> ffzEmotes() const;
|
||||
const QString &subscriptionUrl();
|
||||
const QString &channelUrl();
|
||||
const QString &popoutPlayerUrl();
|
||||
|
||||
boost::optional<EmotePtr> getTwitchBadge(const QString &set,
|
||||
const QString &version) const;
|
||||
@@ -109,7 +115,8 @@ private:
|
||||
std::vector<CheerEmote> cheerEmotes;
|
||||
};
|
||||
|
||||
explicit TwitchChannel(const QString &channelName);
|
||||
explicit TwitchChannel(const QString &channelName, BttvEmotes &bttv,
|
||||
FfzEmotes &ffz);
|
||||
|
||||
// Methods
|
||||
void refreshLiveStatus();
|
||||
@@ -124,16 +131,19 @@ private:
|
||||
void loadBadges();
|
||||
void loadCheerEmotes();
|
||||
|
||||
// Twitch data
|
||||
// Data
|
||||
const QString subscriptionUrl_;
|
||||
const QString channelUrl_;
|
||||
const QString popoutPlayerUrl_;
|
||||
UniqueAccess<StreamStatus> streamStatus_;
|
||||
UniqueAccess<UserState> userState_;
|
||||
UniqueAccess<RoomModes> roomModes_;
|
||||
|
||||
// Emotes
|
||||
BttvEmotes &globalBttv_;
|
||||
FfzEmotes &globalFfz_;
|
||||
Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_;
|
||||
Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_;
|
||||
const QString subscriptionUrl_;
|
||||
const QString channelUrl_;
|
||||
const QString popoutPlayerUrl_;
|
||||
|
||||
bool mod_ = false;
|
||||
UniqueAccess<QString> roomID_;
|
||||
|
||||
@@ -640,12 +640,11 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
|
||||
auto flags = MessageElementFlags();
|
||||
auto emote = boost::optional<EmotePtr>{};
|
||||
|
||||
if ((emote = getApp()->emotes->bttv.global(name))) {
|
||||
if ((emote = this->twitchChannel->globalBttv().emote(name))) {
|
||||
flags = MessageElementFlag::BttvEmote;
|
||||
} else if (twitchChannel &&
|
||||
(emote = this->twitchChannel->bttvEmote(name))) {
|
||||
} else if ((emote = this->twitchChannel->bttvEmote(name))) {
|
||||
flags = MessageElementFlag::BttvEmote;
|
||||
} else if ((emote = getApp()->emotes->ffz.global(name))) {
|
||||
} else if ((emote = this->twitchChannel->globalFfz().emote(name))) {
|
||||
flags = MessageElementFlag::FfzEmote;
|
||||
} else if (twitchChannel && (emote = this->twitchChannel->ffzEmote(name))) {
|
||||
flags = MessageElementFlag::FfzEmote;
|
||||
|
||||
@@ -40,6 +40,9 @@ void TwitchServer::initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
getApp()->accounts->twitch.currentUserChanged.connect(
|
||||
[this]() { postToThread([this] { this->connect(); }); });
|
||||
|
||||
this->bttv.loadEmotes();
|
||||
this->ffz.loadEmotes();
|
||||
}
|
||||
|
||||
void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead,
|
||||
@@ -80,8 +83,8 @@ void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead,
|
||||
|
||||
std::shared_ptr<Channel> TwitchServer::createChannel(const QString &channelName)
|
||||
{
|
||||
auto channel =
|
||||
std::shared_ptr<TwitchChannel>(new TwitchChannel(channelName));
|
||||
auto channel = std::shared_ptr<TwitchChannel>(
|
||||
new TwitchChannel(channelName, this->bttv, this->ffz));
|
||||
channel->refreshChannelEmotes();
|
||||
|
||||
channel->sendMessageSignal.connect(
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "common/Channel.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "pajlada/signals/signalholder.hpp"
|
||||
#include "providers/bttv/BttvEmotes.hpp"
|
||||
#include "providers/ffz/FfzEmotes.hpp"
|
||||
#include "providers/irc/AbstractIrcServer.hpp"
|
||||
|
||||
#include <chrono>
|
||||
@@ -66,6 +68,8 @@ private:
|
||||
std::chrono::steady_clock::time_point lastErrorTimeAmount_;
|
||||
|
||||
bool singleConnection_ = false;
|
||||
BttvEmotes bttv;
|
||||
FfzEmotes ffz;
|
||||
|
||||
pajlada::Signals::SignalHolder signalHolder_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user