mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
fixed crash when moderation buttons are enabled
This commit is contained in:
parent
b3fd278c3c
commit
1ec1ecd52b
|
@ -17,12 +17,16 @@ void ModerationActions::initialize(Settings &settings, Paths &paths)
|
|||
assert(!this->initialized_);
|
||||
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.delayedItemsChanged.connect([this] { //
|
||||
this->setting_.setValue(this->items.getVector());
|
||||
this->setting_->setValue(this->items.getVector());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,7 @@ public:
|
|||
ModerationActionModel *createModel(QObject *parent);
|
||||
|
||||
private:
|
||||
ChatterinoSetting<std::vector<ModerationAction>> setting_ = {
|
||||
"/moderation/actions"};
|
||||
std::unique_ptr<ChatterinoSetting<std::vector<ModerationAction>>> setting_;
|
||||
bool initialized_ = false;
|
||||
};
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "common/Common.hpp"
|
||||
#include "common/NetworkRequest.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
#include "messages/ImageSet.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();
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> BttvEmotes::global(const EmoteName &name) const
|
||||
boost::optional<EmotePtr> BttvEmotes::emote(const EmoteName &name) const
|
||||
{
|
||||
auto emotes = this->global_.get();
|
||||
auto it = emotes->find(name);
|
||||
|
@ -103,7 +104,7 @@ boost::optional<EmotePtr> BttvEmotes::global(const EmoteName &name) const
|
|||
return it->second;
|
||||
}
|
||||
|
||||
void BttvEmotes::loadGlobal()
|
||||
void BttvEmotes::loadEmotes()
|
||||
{
|
||||
auto request = NetworkRequest(QString(globalEmoteApiUrl));
|
||||
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <memory>
|
||||
|
||||
#include "boost/optional.hpp"
|
||||
#include "common/Aliases.hpp"
|
||||
#include "common/Atomic.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
class EmoteMap;
|
||||
|
||||
class BttvEmotes final
|
||||
{
|
||||
static constexpr const char *globalEmoteApiUrl =
|
||||
|
@ -18,9 +21,9 @@ class BttvEmotes final
|
|||
public:
|
||||
BttvEmotes();
|
||||
|
||||
std::shared_ptr<const EmoteMap> global() const;
|
||||
boost::optional<EmotePtr> global(const EmoteName &name) const;
|
||||
void loadGlobal();
|
||||
std::shared_ptr<const EmoteMap> emotes() const;
|
||||
boost::optional<EmotePtr> emote(const EmoteName &name) const;
|
||||
void loadEmotes();
|
||||
static void loadChannel(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback);
|
||||
|
||||
|
|
|
@ -104,12 +104,10 @@ void Emojis::load()
|
|||
|
||||
void Emojis::loadEmojis()
|
||||
{
|
||||
std::map<std::string, QString> toneNames;
|
||||
toneNames["1F3FB"] = "tone1";
|
||||
toneNames["1F3FC"] = "tone2";
|
||||
toneNames["1F3FD"] = "tone3";
|
||||
toneNames["1F3FE"] = "tone4";
|
||||
toneNames["1F3FF"] = "tone5";
|
||||
auto toneNames = std::map<std::string, QString>{
|
||||
{"1F3FB", "tone1"}, {"1F3FC", "tone2"}, {"1F3FD", "tone3"},
|
||||
{"1F3FE", "tone4"}, {"1F3FF", "tone5"},
|
||||
};
|
||||
|
||||
QFile file(":/emoji.json");
|
||||
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/"},
|
||||
// {"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/"},
|
||||
{"Twitter", "https://pajbot.com/static/emoji/img/twitter/64/"},
|
||||
{"Facebook", "https://pajbot.com/static/emoji/img/facebook/64/"},
|
||||
{"Apple", "https://pajbot.com/static/emoji/img/apple/64/"},
|
||||
{"Google", "https://pajbot.com/static/emoji/img/google/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
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "common/NetworkRequest.hpp"
|
||||
#include "common/Outcome.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
boost::optional<EmotePtr> FfzEmotes::global(const EmoteName &name) const
|
||||
boost::optional<EmotePtr> FfzEmotes::emote(const EmoteName &name) const
|
||||
{
|
||||
auto emotes = this->global_.get();
|
||||
auto it = emotes->find(name);
|
||||
|
@ -122,7 +123,7 @@ boost::optional<EmotePtr> FfzEmotes::global(const EmoteName &name) const
|
|||
return boost::none;
|
||||
}
|
||||
|
||||
void FfzEmotes::loadGlobal()
|
||||
void FfzEmotes::loadEmotes()
|
||||
{
|
||||
QString url("https://api.frankerfacez.com/v1/set/global");
|
||||
|
||||
|
@ -131,7 +132,7 @@ void FfzEmotes::loadGlobal()
|
|||
request.setTimeout(30000);
|
||||
|
||||
request.onSuccess([this](auto result) -> Outcome {
|
||||
auto emotes = this->global();
|
||||
auto emotes = this->emotes();
|
||||
auto pair = parseGlobalEmotes(result.parseJson(), *emotes);
|
||||
if (pair.first)
|
||||
this->global_.set(
|
||||
|
|
|
@ -1,24 +1,27 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "boost/optional.hpp"
|
||||
#include "common/Aliases.hpp"
|
||||
#include "common/Atomic.hpp"
|
||||
#include "messages/Emote.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
struct Emote;
|
||||
using EmotePtr = std::shared_ptr<const Emote>;
|
||||
class EmoteMap;
|
||||
|
||||
class FfzEmotes final
|
||||
{
|
||||
static constexpr const char *globalEmoteApiUrl =
|
||||
"https://api.frankerfacez.com/v1/set/global";
|
||||
static constexpr const char *channelEmoteApiUrl =
|
||||
"https://api.betterttv.net/2/channels/";
|
||||
|
||||
public:
|
||||
FfzEmotes();
|
||||
|
||||
std::shared_ptr<const EmoteMap> global() const;
|
||||
boost::optional<EmotePtr> global(const EmoteName &name) const;
|
||||
void loadGlobal();
|
||||
std::shared_ptr<const EmoteMap> emotes() const;
|
||||
boost::optional<EmotePtr> emote(const EmoteName &name) const;
|
||||
void loadEmotes();
|
||||
static void loadChannel(const QString &channelName,
|
||||
std::function<void(EmoteMap &&)> callback);
|
||||
|
||||
|
|
|
@ -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_;
|
||||
};
|
||||
|
|
|
@ -15,8 +15,6 @@ void Emotes::initialize(Settings &settings, Paths &paths)
|
|||
[] { getApp()->accounts->twitch.getCurrent()->loadEmotes(); });
|
||||
|
||||
this->emojis.load();
|
||||
this->bttv.loadGlobal();
|
||||
this->ffz.loadGlobal();
|
||||
|
||||
this->gifTimer.initialize();
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ public:
|
|||
bool isIgnoredEmote(const QString &emote);
|
||||
|
||||
TwitchEmotes twitch;
|
||||
BttvEmotes bttv;
|
||||
FfzEmotes ffz;
|
||||
Emojis emojis;
|
||||
|
||||
GIFTimer gifTimer;
|
||||
|
|
|
@ -125,8 +125,10 @@ void EmotePopup::loadChannel(ChannelPtr _channel)
|
|||
*globalChannel, *subChannel);
|
||||
|
||||
// global
|
||||
addEmotes(*globalChannel, *getApp()->emotes->bttv.global(), "BetterTTV");
|
||||
addEmotes(*globalChannel, *getApp()->emotes->ffz.global(), "FrankerFaceZ");
|
||||
addEmotes(*globalChannel, *twitchChannel->globalBttv().emotes(),
|
||||
"BetterTTV");
|
||||
addEmotes(*globalChannel, *twitchChannel->globalBttv().emotes(),
|
||||
"FrankerFaceZ");
|
||||
|
||||
// channel
|
||||
addEmotes(*channelChannel, *twitchChannel->bttvEmotes(), "BetterTTV");
|
||||
|
|
Loading…
Reference in a new issue