mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Added more functionality and clickable deny and accept buttons that don't do anything, this also fixes the issue with the background not working properly
This commit is contained in:
parent
0b2480d715
commit
7067b0503d
|
@ -244,9 +244,8 @@ void Application::initPubsub()
|
|||
return;
|
||||
}
|
||||
|
||||
auto p = makeAutomodMessage(action);
|
||||
|
||||
postToThread([chan, p] {
|
||||
postToThread([chan, action] {
|
||||
auto p = makeAutomodMessage(action);
|
||||
chan->addMessage(p.first);
|
||||
chan->addMessage(p.second);
|
||||
});
|
||||
|
|
|
@ -17,6 +17,8 @@ public:
|
|||
InsertText,
|
||||
ShowMessage,
|
||||
UserAction,
|
||||
AutoModAllow,
|
||||
AutoModDeny,
|
||||
};
|
||||
|
||||
Link();
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "MessageBuilder.hpp"
|
||||
|
||||
//#include "Application.hpp"
|
||||
#include "Application.hpp"
|
||||
#include "common/LinkParser.hpp"
|
||||
//#include "messages/Image.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageElement.hpp"
|
||||
#include "providers/twitch/PubsubActions.hpp"
|
||||
|
@ -13,7 +13,7 @@
|
|||
#include "util/IrcHelpers.hpp"
|
||||
|
||||
#include <QDateTime>
|
||||
//#include <QImageReader>
|
||||
#include <QImageReader>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
|
@ -30,18 +30,30 @@ std::pair<MessagePtr, MessagePtr> makeAutomodMessage(
|
|||
builder.emplace<TimestampElement>();
|
||||
builder.message().flags.set(MessageFlag::PubSub);
|
||||
|
||||
// Crashes the program atm
|
||||
// builder.emplace<ImageElement>(
|
||||
// Image::fromPixmap(getApp()->resources->twitch.automod),
|
||||
// MessageElementFlag::BadgeChannelAuthority)
|
||||
// ->setTooltip("AutoMod");
|
||||
builder
|
||||
.emplace<ImageElement>(
|
||||
Image::fromPixmap(getApp()->resources->twitch.automod),
|
||||
MessageElementFlag::BadgeChannelAuthority)
|
||||
->setTooltip("AutoMod");
|
||||
builder.emplace<TextElement>(
|
||||
"AutoMod:", MessageElementFlag::NonBoldUsername,
|
||||
MessageColor(QColor("green")));
|
||||
MessageColor(QColor("blue")));
|
||||
builder.emplace<TextElement>(
|
||||
("Held a message for reason: " + action.reason +
|
||||
". Allow will post it in chat."),
|
||||
MessageElementFlag::Text, MessageColor::Text);
|
||||
builder
|
||||
.emplace<TextElement>(" Allow", MessageElementFlag::Text,
|
||||
MessageColor(QColor("green")),
|
||||
FontStyle::ChatMediumBold)
|
||||
->setLink({Link::AutoModAllow, action.msgID});
|
||||
builder
|
||||
.emplace<TextElement>(" Deny", MessageElementFlag::Text,
|
||||
MessageColor(QColor("red")),
|
||||
FontStyle::ChatMediumBold)
|
||||
->setLink({Link::AutoModDeny, action.msgID});
|
||||
builder.emplace<TextElement>(action.msgID, MessageElementFlag::Text,
|
||||
MessageColor::Text);
|
||||
builder.message().flags.set(MessageFlag::AutoMod);
|
||||
|
||||
auto message1 = builder.release();
|
||||
|
|
|
@ -270,7 +270,7 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/,
|
|||
}
|
||||
else if (this->message_->flags.has(MessageFlag::AutoMod))
|
||||
{
|
||||
backgroundColor = app->themes->messages.backgrounds.automod;
|
||||
backgroundColor = QColor("#404040");
|
||||
}
|
||||
|
||||
painter.fillRect(buffer->rect(), backgroundColor);
|
||||
|
|
|
@ -113,6 +113,8 @@ struct AutomodAction : PubSubAction {
|
|||
QString message;
|
||||
|
||||
QString reason;
|
||||
|
||||
QString msgID;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -532,6 +532,8 @@ PubSub::PubSub()
|
|||
try
|
||||
{
|
||||
const auto &args = getArgs(data);
|
||||
const auto &msgID = getMsgID(data);
|
||||
// qDebug() << QString::fromStdString(rj::stringify(data));
|
||||
|
||||
if (args.Size() < 1)
|
||||
{
|
||||
|
@ -559,6 +561,11 @@ PubSub::PubSub()
|
|||
}
|
||||
}
|
||||
|
||||
if (!rj::getSafe(msgID, action.msgID))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->signals_.moderation.automodMessage.invoke(action);
|
||||
}
|
||||
catch (const std::runtime_error &ex)
|
||||
|
@ -624,7 +631,7 @@ PubSub::PubSub()
|
|||
|
||||
// Add an initial client
|
||||
this->addClient();
|
||||
}
|
||||
} // namespace chatterino
|
||||
|
||||
void PubSub::addClient()
|
||||
{
|
||||
|
|
|
@ -23,6 +23,18 @@ const rapidjson::Value &getArgs(const rapidjson::Value &data)
|
|||
return args;
|
||||
}
|
||||
|
||||
const rapidjson::Value &getMsgID(const rapidjson::Value &data)
|
||||
{
|
||||
if (!data.HasMember("msg_id"))
|
||||
{
|
||||
throw std::runtime_error("Missing member msg_id");
|
||||
}
|
||||
|
||||
const auto &msgID = data["msg_id"];
|
||||
|
||||
return msgID;
|
||||
}
|
||||
|
||||
bool getCreatedByUser(const rapidjson::Value &data, ActionUser &user)
|
||||
{
|
||||
return rj::getSafe(data, "created_by", user.name) &&
|
||||
|
|
|
@ -12,6 +12,7 @@ class TwitchAccount;
|
|||
struct ActionUser;
|
||||
|
||||
const rapidjson::Value &getArgs(const rapidjson::Value &data);
|
||||
const rapidjson::Value &getMsgID(const rapidjson::Value &data);
|
||||
|
||||
bool getCreatedByUser(const rapidjson::Value &data, ActionUser &user);
|
||||
|
||||
|
|
|
@ -413,6 +413,8 @@ AccessGuard<const TwitchAccount::TwitchAccountEmoteData>
|
|||
return this->emotes_.accessConst();
|
||||
}
|
||||
|
||||
// AutoModActions
|
||||
|
||||
void TwitchAccount::parseEmotes(const rapidjson::Document &root)
|
||||
{
|
||||
auto emoteData = this->emotes_.access();
|
||||
|
|
|
@ -108,6 +108,12 @@ public:
|
|||
void loadEmotes();
|
||||
AccessGuard<const TwitchAccountEmoteData> accessEmotes() const;
|
||||
|
||||
// Automod actions
|
||||
void autoModAllow(const QString msgID,
|
||||
std::function<void()> successCallback);
|
||||
void autoModDeny(const QString msgID,
|
||||
std::function<void()> successCallback);
|
||||
|
||||
private:
|
||||
void parseEmotes(const rapidjson::Document &document);
|
||||
void loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet);
|
||||
|
|
|
@ -1671,6 +1671,13 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
|
|||
}
|
||||
break;
|
||||
|
||||
case Link::AutoModAllow:
|
||||
{
|
||||
}
|
||||
case Link::AutoModDeny:
|
||||
{
|
||||
}
|
||||
|
||||
default:;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue