fixed crash when moderation buttons are enabled

This commit is contained in:
fourtf
2018-08-12 00:01:37 +02:00
parent b3fd278c3c
commit 1ec1ecd52b
15 changed files with 89 additions and 68 deletions
@@ -17,12 +17,16 @@ void ModerationActions::initialize(Settings &settings, Paths &paths)
assert(!this->initialized_); assert(!this->initialized_);
this->initialized_ = true; this->initialized_ = true;
for (auto &val : this->setting_.getValue()) { this->setting_ =
std::make_unique<ChatterinoSetting<std::vector<ModerationAction>>>(
"/moderation/actions");
for (auto &val : this->setting_->getValue()) {
this->items.insertItem(val); this->items.insertItem(val);
} }
this->items.delayedItemsChanged.connect([this] { // this->items.delayedItemsChanged.connect([this] { //
this->setting_.setValue(this->items.getVector()); this->setting_->setValue(this->items.getVector());
}); });
} }
@@ -25,8 +25,7 @@ public:
ModerationActionModel *createModel(QObject *parent); ModerationActionModel *createModel(QObject *parent);
private: private:
ChatterinoSetting<std::vector<ModerationAction>> setting_ = { std::unique_ptr<ChatterinoSetting<std::vector<ModerationAction>>> setting_;
"/moderation/actions"};
bool initialized_ = false; bool initialized_ = false;
}; };
+4 -3
View File
@@ -3,6 +3,7 @@
#include "common/Common.hpp" #include "common/Common.hpp"
#include "common/NetworkRequest.hpp" #include "common/NetworkRequest.hpp"
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "messages/Emote.hpp"
#include "messages/Image.hpp" #include "messages/Image.hpp"
#include "messages/ImageSet.hpp" #include "messages/ImageSet.hpp"
#include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchChannel.hpp"
@@ -89,12 +90,12 @@ BttvEmotes::BttvEmotes()
{ {
} }
std::shared_ptr<const EmoteMap> BttvEmotes::global() const std::shared_ptr<const EmoteMap> BttvEmotes::emotes() const
{ {
return this->global_.get(); return this->global_.get();
} }
boost::optional<EmotePtr> BttvEmotes::global(const EmoteName &name) const boost::optional<EmotePtr> BttvEmotes::emote(const EmoteName &name) const
{ {
auto emotes = this->global_.get(); auto emotes = this->global_.get();
auto it = emotes->find(name); auto it = emotes->find(name);
@@ -103,7 +104,7 @@ boost::optional<EmotePtr> BttvEmotes::global(const EmoteName &name) const
return it->second; return it->second;
} }
void BttvEmotes::loadGlobal() void BttvEmotes::loadEmotes()
{ {
auto request = NetworkRequest(QString(globalEmoteApiUrl)); auto request = NetworkRequest(QString(globalEmoteApiUrl));
+9 -6
View File
@@ -1,13 +1,16 @@
#pragma once #pragma once
#include <boost/optional.hpp>
#include <memory> #include <memory>
#include "boost/optional.hpp"
#include "common/Aliases.hpp"
#include "common/Atomic.hpp" #include "common/Atomic.hpp"
#include "messages/Emote.hpp"
namespace chatterino { namespace chatterino {
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
class EmoteMap;
class BttvEmotes final class BttvEmotes final
{ {
static constexpr const char *globalEmoteApiUrl = static constexpr const char *globalEmoteApiUrl =
@@ -18,9 +21,9 @@ class BttvEmotes final
public: public:
BttvEmotes(); BttvEmotes();
std::shared_ptr<const EmoteMap> global() const; std::shared_ptr<const EmoteMap> emotes() const;
boost::optional<EmotePtr> global(const EmoteName &name) const; boost::optional<EmotePtr> emote(const EmoteName &name) const;
void loadGlobal(); void loadEmotes();
static void loadChannel(const QString &channelName, static void loadChannel(const QString &channelName,
std::function<void(EmoteMap &&)> callback); std::function<void(EmoteMap &&)> callback);
+4 -21
View File
@@ -104,12 +104,10 @@ void Emojis::load()
void Emojis::loadEmojis() void Emojis::loadEmojis()
{ {
std::map<std::string, QString> toneNames; auto toneNames = std::map<std::string, QString>{
toneNames["1F3FB"] = "tone1"; {"1F3FB", "tone1"}, {"1F3FC", "tone2"}, {"1F3FD", "tone3"},
toneNames["1F3FC"] = "tone2"; {"1F3FE", "tone4"}, {"1F3FF", "tone5"},
toneNames["1F3FD"] = "tone3"; };
toneNames["1F3FE"] = "tone4";
toneNames["1F3FF"] = "tone5";
QFile file(":/emoji.json"); QFile file(":/emoji.json");
file.open(QFile::ReadOnly); file.open(QFile::ReadOnly);
@@ -234,27 +232,12 @@ void Emojis::loadEmojiSet()
// {"Google", "https://cdn.jsdelivr.net/npm/emoji-datasource-google@4.0.4/img/google/64/"}, // {"Google", "https://cdn.jsdelivr.net/npm/emoji-datasource-google@4.0.4/img/google/64/"},
// {"Messenger", "https://cdn.jsdelivr.net/npm/emoji-datasource-messenger@4.0.4/img/messenger/64/"}, // {"Messenger", "https://cdn.jsdelivr.net/npm/emoji-datasource-messenger@4.0.4/img/messenger/64/"},
// {"EmojiOne 2", "https://cdnjs.cloudflare.com/ajax/libs/emojione/2.2.6/assets/png/"},
// {"EmojiOne 3", "https://braize.pajlada.com/emoji/img/emojione/64/"},
// {"Twitter", "https://braize.pajlada.com/emoji/img/twitter/64/"},
// {"Facebook", "https://braize.pajlada.com/emoji/img/facebook/64/"},
// {"Apple", "https://braize.pajlada.com/emoji/img/apple/64/"},
// {"Google", "https://braize.pajlada.com/emoji/img/google/64/"},
// {"Messenger", "https://braize.pajlada.com/emoji/img/messenger/64/"},
{"EmojiOne 3", "https://pajbot.com/static/emoji/img/emojione/64/"}, {"EmojiOne 3", "https://pajbot.com/static/emoji/img/emojione/64/"},
{"Twitter", "https://pajbot.com/static/emoji/img/twitter/64/"}, {"Twitter", "https://pajbot.com/static/emoji/img/twitter/64/"},
{"Facebook", "https://pajbot.com/static/emoji/img/facebook/64/"}, {"Facebook", "https://pajbot.com/static/emoji/img/facebook/64/"},
{"Apple", "https://pajbot.com/static/emoji/img/apple/64/"}, {"Apple", "https://pajbot.com/static/emoji/img/apple/64/"},
{"Google", "https://pajbot.com/static/emoji/img/google/64/"}, {"Google", "https://pajbot.com/static/emoji/img/google/64/"},
{"Messenger", "https://pajbot.com/static/emoji/img/messenger/64/"}, {"Messenger", "https://pajbot.com/static/emoji/img/messenger/64/"},
// {"EmojiOne 3", "https://cdn.fourtf.com/emoji/emojione/64/"},
// {"Twitter", "https://cdn.fourtf.com/emoji/twitter/64/"},
// {"Facebook", "https://cdn.fourtf.com/emoji/facebook/64/"},
// {"Apple", "https://cdn.fourtf.com/emoji/apple/64/"},
// {"Google", "https://cdn.fourtf.com/emoji/google/64/"},
// {"Messenger", "https://cdn.fourtf.com/emoji/messenger/64/"},
}; };
// clang-format on // clang-format on
+5 -4
View File
@@ -5,6 +5,7 @@
#include "common/NetworkRequest.hpp" #include "common/NetworkRequest.hpp"
#include "common/Outcome.hpp" #include "common/Outcome.hpp"
#include "debug/Log.hpp" #include "debug/Log.hpp"
#include "messages/Emote.hpp"
#include "messages/Image.hpp" #include "messages/Image.hpp"
namespace chatterino { namespace chatterino {
@@ -109,12 +110,12 @@ FfzEmotes::FfzEmotes()
{ {
} }
std::shared_ptr<const EmoteMap> FfzEmotes::global() const std::shared_ptr<const EmoteMap> FfzEmotes::emotes() const
{ {
return this->global_.get(); return this->global_.get();
} }
boost::optional<EmotePtr> FfzEmotes::global(const EmoteName &name) const boost::optional<EmotePtr> FfzEmotes::emote(const EmoteName &name) const
{ {
auto emotes = this->global_.get(); auto emotes = this->global_.get();
auto it = emotes->find(name); auto it = emotes->find(name);
@@ -122,7 +123,7 @@ boost::optional<EmotePtr> FfzEmotes::global(const EmoteName &name) const
return boost::none; return boost::none;
} }
void FfzEmotes::loadGlobal() void FfzEmotes::loadEmotes()
{ {
QString url("https://api.frankerfacez.com/v1/set/global"); QString url("https://api.frankerfacez.com/v1/set/global");
@@ -131,7 +132,7 @@ void FfzEmotes::loadGlobal()
request.setTimeout(30000); request.setTimeout(30000);
request.onSuccess([this](auto result) -> Outcome { request.onSuccess([this](auto result) -> Outcome {
auto emotes = this->global(); auto emotes = this->emotes();
auto pair = parseGlobalEmotes(result.parseJson(), *emotes); auto pair = parseGlobalEmotes(result.parseJson(), *emotes);
if (pair.first) if (pair.first)
this->global_.set( this->global_.set(
+9 -6
View File
@@ -1,24 +1,27 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include "boost/optional.hpp"
#include "common/Aliases.hpp"
#include "common/Atomic.hpp" #include "common/Atomic.hpp"
#include "messages/Emote.hpp"
namespace chatterino { namespace chatterino {
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
class EmoteMap;
class FfzEmotes final class FfzEmotes final
{ {
static constexpr const char *globalEmoteApiUrl = static constexpr const char *globalEmoteApiUrl =
"https://api.frankerfacez.com/v1/set/global"; "https://api.frankerfacez.com/v1/set/global";
static constexpr const char *channelEmoteApiUrl =
"https://api.betterttv.net/2/channels/";
public: public:
FfzEmotes(); FfzEmotes();
std::shared_ptr<const EmoteMap> global() const; std::shared_ptr<const EmoteMap> emotes() const;
boost::optional<EmotePtr> global(const EmoteName &name) const; boost::optional<EmotePtr> emote(const EmoteName &name) const;
void loadGlobal(); void loadEmotes();
static void loadChannel(const QString &channelName, static void loadChannel(const QString &channelName,
std::function<void(EmoteMap &&)> callback); std::function<void(EmoteMap &&)> callback);
+16 -3
View File
@@ -51,13 +51,16 @@ auto parseRecentMessages(const QJsonObject &jsonRoot, TwitchChannel &channel)
} }
} // namespace } // namespace
TwitchChannel::TwitchChannel(const QString &name) TwitchChannel::TwitchChannel(const QString &name, BttvEmotes &bttv,
FfzEmotes &ffz)
: Channel(name, Channel::Type::Twitch) : Channel(name, Channel::Type::Twitch)
, bttvEmotes_(std::make_shared<EmoteMap>())
, ffzEmotes_(std::make_shared<EmoteMap>())
, subscriptionUrl_("https://www.twitch.tv/subs/" + name) , subscriptionUrl_("https://www.twitch.tv/subs/" + name)
, channelUrl_("https://twitch.tv/" + name) , channelUrl_("https://twitch.tv/" + name)
, popoutPlayerUrl_("https://player.twitch.tv/?channel=" + name) , popoutPlayerUrl_("https://player.twitch.tv/?channel=" + name)
, globalBttv_(bttv)
, globalFfz_(ffz)
, bttvEmotes_(std::make_shared<EmoteMap>())
, ffzEmotes_(std::make_shared<EmoteMap>())
, mod_(false) , mod_(false)
{ {
log("[TwitchChannel:{}] Opened", name); log("[TwitchChannel:{}] Opened", name);
@@ -290,6 +293,16 @@ TwitchChannel::accessStreamStatus() const
return this->streamStatus_.accessConst(); 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 boost::optional<EmotePtr> TwitchChannel::bttvEmote(const EmoteName &name) const
{ {
auto emotes = this->bttvEmotes_.get(); auto emotes = this->bttvEmotes_.get();
+19 -9
View File
@@ -19,6 +19,9 @@ struct Emote;
using EmotePtr = std::shared_ptr<const Emote>; using EmotePtr = std::shared_ptr<const Emote>;
class EmoteMap; class EmoteMap;
class FfzEmotes;
class BttvEmotes;
class TwitchServer; class TwitchServer;
class TwitchChannel final : public Channel, pajlada::Signals::SignalHolder class TwitchChannel final : public Channel, pajlada::Signals::SignalHolder
@@ -60,25 +63,28 @@ public:
void addJoinedUser(const QString &user); void addJoinedUser(const QString &user);
void addPartedUser(const QString &user); void addPartedUser(const QString &user);
// Twitch data
bool isLive() const; bool isLive() const;
virtual bool isMod() const override; virtual bool isMod() const override;
void setMod(bool value); void setMod(bool value);
virtual bool isBroadcaster() const override; virtual bool isBroadcaster() const override;
// Data
const QString &subscriptionUrl();
const QString &channelUrl();
const QString &popoutPlayerUrl();
QString roomId() const; QString roomId() const;
void setRoomId(const QString &id); void setRoomId(const QString &id);
AccessGuard<const RoomModes> accessRoomModes() const; AccessGuard<const RoomModes> accessRoomModes() const;
void setRoomModes(const RoomModes &roomModes_); void setRoomModes(const RoomModes &roomModes_);
AccessGuard<const StreamStatus> accessStreamStatus() const; 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> bttvEmote(const EmoteName &name) const;
boost::optional<EmotePtr> ffzEmote(const EmoteName &name) const; boost::optional<EmotePtr> ffzEmote(const EmoteName &name) const;
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;
const QString &subscriptionUrl();
const QString &channelUrl();
const QString &popoutPlayerUrl();
boost::optional<EmotePtr> getTwitchBadge(const QString &set, boost::optional<EmotePtr> getTwitchBadge(const QString &set,
const QString &version) const; const QString &version) const;
@@ -109,7 +115,8 @@ private:
std::vector<CheerEmote> cheerEmotes; std::vector<CheerEmote> cheerEmotes;
}; };
explicit TwitchChannel(const QString &channelName); explicit TwitchChannel(const QString &channelName, BttvEmotes &bttv,
FfzEmotes &ffz);
// Methods // Methods
void refreshLiveStatus(); void refreshLiveStatus();
@@ -124,16 +131,19 @@ private:
void loadBadges(); void loadBadges();
void loadCheerEmotes(); void loadCheerEmotes();
// Twitch data // Data
const QString subscriptionUrl_;
const QString channelUrl_;
const QString popoutPlayerUrl_;
UniqueAccess<StreamStatus> streamStatus_; UniqueAccess<StreamStatus> streamStatus_;
UniqueAccess<UserState> userState_; UniqueAccess<UserState> userState_;
UniqueAccess<RoomModes> roomModes_; UniqueAccess<RoomModes> roomModes_;
// Emotes
BttvEmotes &globalBttv_;
FfzEmotes &globalFfz_;
Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_; Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_; Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_;
const QString subscriptionUrl_;
const QString channelUrl_;
const QString popoutPlayerUrl_;
bool mod_ = false; bool mod_ = false;
UniqueAccess<QString> roomID_; UniqueAccess<QString> roomID_;
@@ -640,12 +640,11 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
auto flags = MessageElementFlags(); auto flags = MessageElementFlags();
auto emote = boost::optional<EmotePtr>{}; auto emote = boost::optional<EmotePtr>{};
if ((emote = getApp()->emotes->bttv.global(name))) { if ((emote = this->twitchChannel->globalBttv().emote(name))) {
flags = MessageElementFlag::BttvEmote; flags = MessageElementFlag::BttvEmote;
} else if (twitchChannel && } else if ((emote = this->twitchChannel->bttvEmote(name))) {
(emote = this->twitchChannel->bttvEmote(name))) {
flags = MessageElementFlag::BttvEmote; flags = MessageElementFlag::BttvEmote;
} else if ((emote = getApp()->emotes->ffz.global(name))) { } else if ((emote = this->twitchChannel->globalFfz().emote(name))) {
flags = MessageElementFlag::FfzEmote; flags = MessageElementFlag::FfzEmote;
} else if (twitchChannel && (emote = this->twitchChannel->ffzEmote(name))) { } else if (twitchChannel && (emote = this->twitchChannel->ffzEmote(name))) {
flags = MessageElementFlag::FfzEmote; flags = MessageElementFlag::FfzEmote;
+5 -2
View File
@@ -40,6 +40,9 @@ void TwitchServer::initialize(Settings &settings, Paths &paths)
{ {
getApp()->accounts->twitch.currentUserChanged.connect( getApp()->accounts->twitch.currentUserChanged.connect(
[this]() { postToThread([this] { this->connect(); }); }); [this]() { postToThread([this] { this->connect(); }); });
this->bttv.loadEmotes();
this->ffz.loadEmotes();
} }
void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead, 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) std::shared_ptr<Channel> TwitchServer::createChannel(const QString &channelName)
{ {
auto channel = auto channel = std::shared_ptr<TwitchChannel>(
std::shared_ptr<TwitchChannel>(new TwitchChannel(channelName)); new TwitchChannel(channelName, this->bttv, this->ffz));
channel->refreshChannelEmotes(); channel->refreshChannelEmotes();
channel->sendMessageSignal.connect( channel->sendMessageSignal.connect(
+4
View File
@@ -4,6 +4,8 @@
#include "common/Channel.hpp" #include "common/Channel.hpp"
#include "common/Singleton.hpp" #include "common/Singleton.hpp"
#include "pajlada/signals/signalholder.hpp" #include "pajlada/signals/signalholder.hpp"
#include "providers/bttv/BttvEmotes.hpp"
#include "providers/ffz/FfzEmotes.hpp"
#include "providers/irc/AbstractIrcServer.hpp" #include "providers/irc/AbstractIrcServer.hpp"
#include <chrono> #include <chrono>
@@ -66,6 +68,8 @@ private:
std::chrono::steady_clock::time_point lastErrorTimeAmount_; std::chrono::steady_clock::time_point lastErrorTimeAmount_;
bool singleConnection_ = false; bool singleConnection_ = false;
BttvEmotes bttv;
FfzEmotes ffz;
pajlada::Signals::SignalHolder signalHolder_; pajlada::Signals::SignalHolder signalHolder_;
}; };
-2
View File
@@ -15,8 +15,6 @@ void Emotes::initialize(Settings &settings, Paths &paths)
[] { getApp()->accounts->twitch.getCurrent()->loadEmotes(); }); [] { getApp()->accounts->twitch.getCurrent()->loadEmotes(); });
this->emojis.load(); this->emojis.load();
this->bttv.loadGlobal();
this->ffz.loadGlobal();
this->gifTimer.initialize(); this->gifTimer.initialize();
} }
-2
View File
@@ -25,8 +25,6 @@ public:
bool isIgnoredEmote(const QString &emote); bool isIgnoredEmote(const QString &emote);
TwitchEmotes twitch; TwitchEmotes twitch;
BttvEmotes bttv;
FfzEmotes ffz;
Emojis emojis; Emojis emojis;
GIFTimer gifTimer; GIFTimer gifTimer;
+4 -2
View File
@@ -125,8 +125,10 @@ void EmotePopup::loadChannel(ChannelPtr _channel)
*globalChannel, *subChannel); *globalChannel, *subChannel);
// global // global
addEmotes(*globalChannel, *getApp()->emotes->bttv.global(), "BetterTTV"); addEmotes(*globalChannel, *twitchChannel->globalBttv().emotes(),
addEmotes(*globalChannel, *getApp()->emotes->ffz.global(), "FrankerFaceZ"); "BetterTTV");
addEmotes(*globalChannel, *twitchChannel->globalBttv().emotes(),
"FrankerFaceZ");
// channel // channel
addEmotes(*channelChannel, *twitchChannel->bttvEmotes(), "BetterTTV"); addEmotes(*channelChannel, *twitchChannel->bttvEmotes(), "BetterTTV");