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:
apa420
2019-01-20 14:45:59 +01:00
parent 0b2480d715
commit 7067b0503d
11 changed files with 64 additions and 14 deletions
+2 -3
View File
@@ -244,9 +244,8 @@ void Application::initPubsub()
return; return;
} }
auto p = makeAutomodMessage(action); postToThread([chan, action] {
auto p = makeAutomodMessage(action);
postToThread([chan, p] {
chan->addMessage(p.first); chan->addMessage(p.first);
chan->addMessage(p.second); chan->addMessage(p.second);
}); });
+2
View File
@@ -17,6 +17,8 @@ public:
InsertText, InsertText,
ShowMessage, ShowMessage,
UserAction, UserAction,
AutoModAllow,
AutoModDeny,
}; };
Link(); Link();
+21 -9
View File
@@ -1,8 +1,8 @@
#include "MessageBuilder.hpp" #include "MessageBuilder.hpp"
//#include "Application.hpp" #include "Application.hpp"
#include "common/LinkParser.hpp" #include "common/LinkParser.hpp"
//#include "messages/Image.hpp" #include "messages/Image.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"
#include "messages/MessageElement.hpp" #include "messages/MessageElement.hpp"
#include "providers/twitch/PubsubActions.hpp" #include "providers/twitch/PubsubActions.hpp"
@@ -13,7 +13,7 @@
#include "util/IrcHelpers.hpp" #include "util/IrcHelpers.hpp"
#include <QDateTime> #include <QDateTime>
//#include <QImageReader> #include <QImageReader>
namespace chatterino { namespace chatterino {
@@ -30,18 +30,30 @@ std::pair<MessagePtr, MessagePtr> makeAutomodMessage(
builder.emplace<TimestampElement>(); builder.emplace<TimestampElement>();
builder.message().flags.set(MessageFlag::PubSub); builder.message().flags.set(MessageFlag::PubSub);
// Crashes the program atm builder
// builder.emplace<ImageElement>( .emplace<ImageElement>(
// Image::fromPixmap(getApp()->resources->twitch.automod), Image::fromPixmap(getApp()->resources->twitch.automod),
// MessageElementFlag::BadgeChannelAuthority) MessageElementFlag::BadgeChannelAuthority)
// ->setTooltip("AutoMod"); ->setTooltip("AutoMod");
builder.emplace<TextElement>( builder.emplace<TextElement>(
"AutoMod:", MessageElementFlag::NonBoldUsername, "AutoMod:", MessageElementFlag::NonBoldUsername,
MessageColor(QColor("green"))); MessageColor(QColor("blue")));
builder.emplace<TextElement>( builder.emplace<TextElement>(
("Held a message for reason: " + action.reason + ("Held a message for reason: " + action.reason +
". Allow will post it in chat."), ". Allow will post it in chat."),
MessageElementFlag::Text, MessageColor::Text); 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); builder.message().flags.set(MessageFlag::AutoMod);
auto message1 = builder.release(); auto message1 = builder.release();
+1 -1
View File
@@ -270,7 +270,7 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/,
} }
else if (this->message_->flags.has(MessageFlag::AutoMod)) else if (this->message_->flags.has(MessageFlag::AutoMod))
{ {
backgroundColor = app->themes->messages.backgrounds.automod; backgroundColor = QColor("#404040");
} }
painter.fillRect(buffer->rect(), backgroundColor); painter.fillRect(buffer->rect(), backgroundColor);
+2
View File
@@ -113,6 +113,8 @@ struct AutomodAction : PubSubAction {
QString message; QString message;
QString reason; QString reason;
QString msgID;
}; };
} // namespace chatterino } // namespace chatterino
+8 -1
View File
@@ -532,6 +532,8 @@ PubSub::PubSub()
try try
{ {
const auto &args = getArgs(data); const auto &args = getArgs(data);
const auto &msgID = getMsgID(data);
// qDebug() << QString::fromStdString(rj::stringify(data));
if (args.Size() < 1) if (args.Size() < 1)
{ {
@@ -559,6 +561,11 @@ PubSub::PubSub()
} }
} }
if (!rj::getSafe(msgID, action.msgID))
{
return;
}
this->signals_.moderation.automodMessage.invoke(action); this->signals_.moderation.automodMessage.invoke(action);
} }
catch (const std::runtime_error &ex) catch (const std::runtime_error &ex)
@@ -624,7 +631,7 @@ PubSub::PubSub()
// Add an initial client // Add an initial client
this->addClient(); this->addClient();
} } // namespace chatterino
void PubSub::addClient() void PubSub::addClient()
{ {
+12
View File
@@ -23,6 +23,18 @@ const rapidjson::Value &getArgs(const rapidjson::Value &data)
return args; 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) bool getCreatedByUser(const rapidjson::Value &data, ActionUser &user)
{ {
return rj::getSafe(data, "created_by", user.name) && return rj::getSafe(data, "created_by", user.name) &&
+1
View File
@@ -12,6 +12,7 @@ class TwitchAccount;
struct ActionUser; struct ActionUser;
const rapidjson::Value &getArgs(const rapidjson::Value &data); const rapidjson::Value &getArgs(const rapidjson::Value &data);
const rapidjson::Value &getMsgID(const rapidjson::Value &data);
bool getCreatedByUser(const rapidjson::Value &data, ActionUser &user); bool getCreatedByUser(const rapidjson::Value &data, ActionUser &user);
+2
View File
@@ -413,6 +413,8 @@ AccessGuard<const TwitchAccount::TwitchAccountEmoteData>
return this->emotes_.accessConst(); return this->emotes_.accessConst();
} }
// AutoModActions
void TwitchAccount::parseEmotes(const rapidjson::Document &root) void TwitchAccount::parseEmotes(const rapidjson::Document &root)
{ {
auto emoteData = this->emotes_.access(); auto emoteData = this->emotes_.access();
+6
View File
@@ -108,6 +108,12 @@ public:
void loadEmotes(); void loadEmotes();
AccessGuard<const TwitchAccountEmoteData> accessEmotes() const; 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: private:
void parseEmotes(const rapidjson::Document &document); void parseEmotes(const rapidjson::Document &document);
void loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet); void loadEmoteSetData(std::shared_ptr<EmoteSet> emoteSet);
+7
View File
@@ -1671,6 +1671,13 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link,
} }
break; break;
case Link::AutoModAllow:
{
}
case Link::AutoModDeny:
{
}
default:; default:;
} }
} }