diff --git a/src/Application.cpp b/src/Application.cpp index 23d983fd5..6c7efabf9 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -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); }); diff --git a/src/messages/Link.hpp b/src/messages/Link.hpp index 38000982f..52a52444b 100644 --- a/src/messages/Link.hpp +++ b/src/messages/Link.hpp @@ -17,6 +17,8 @@ public: InsertText, ShowMessage, UserAction, + AutoModAllow, + AutoModDeny, }; Link(); diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index f2e8bae86..9df5fc279 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -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 -//#include +#include namespace chatterino { @@ -30,18 +30,30 @@ std::pair makeAutomodMessage( builder.emplace(); builder.message().flags.set(MessageFlag::PubSub); - // Crashes the program atm - // builder.emplace( - // Image::fromPixmap(getApp()->resources->twitch.automod), - // MessageElementFlag::BadgeChannelAuthority) - // ->setTooltip("AutoMod"); + builder + .emplace( + Image::fromPixmap(getApp()->resources->twitch.automod), + MessageElementFlag::BadgeChannelAuthority) + ->setTooltip("AutoMod"); builder.emplace( "AutoMod:", MessageElementFlag::NonBoldUsername, - MessageColor(QColor("green"))); + MessageColor(QColor("blue"))); builder.emplace( ("Held a message for reason: " + action.reason + ". Allow will post it in chat."), MessageElementFlag::Text, MessageColor::Text); + builder + .emplace(" Allow", MessageElementFlag::Text, + MessageColor(QColor("green")), + FontStyle::ChatMediumBold) + ->setLink({Link::AutoModAllow, action.msgID}); + builder + .emplace(" Deny", MessageElementFlag::Text, + MessageColor(QColor("red")), + FontStyle::ChatMediumBold) + ->setLink({Link::AutoModDeny, action.msgID}); + builder.emplace(action.msgID, MessageElementFlag::Text, + MessageColor::Text); builder.message().flags.set(MessageFlag::AutoMod); auto message1 = builder.release(); diff --git a/src/messages/layouts/MessageLayout.cpp b/src/messages/layouts/MessageLayout.cpp index 7137c9666..06af7c790 100644 --- a/src/messages/layouts/MessageLayout.cpp +++ b/src/messages/layouts/MessageLayout.cpp @@ -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); diff --git a/src/providers/twitch/PubsubActions.hpp b/src/providers/twitch/PubsubActions.hpp index bb116d937..03013ff4c 100644 --- a/src/providers/twitch/PubsubActions.hpp +++ b/src/providers/twitch/PubsubActions.hpp @@ -113,6 +113,8 @@ struct AutomodAction : PubSubAction { QString message; QString reason; + + QString msgID; }; } // namespace chatterino diff --git a/src/providers/twitch/PubsubClient.cpp b/src/providers/twitch/PubsubClient.cpp index 50e7b0396..c60665882 100644 --- a/src/providers/twitch/PubsubClient.cpp +++ b/src/providers/twitch/PubsubClient.cpp @@ -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() { diff --git a/src/providers/twitch/PubsubHelpers.cpp b/src/providers/twitch/PubsubHelpers.cpp index cda4b8788..b30c47c0f 100644 --- a/src/providers/twitch/PubsubHelpers.cpp +++ b/src/providers/twitch/PubsubHelpers.cpp @@ -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) && diff --git a/src/providers/twitch/PubsubHelpers.hpp b/src/providers/twitch/PubsubHelpers.hpp index 7ea540ad8..ad8c52130 100644 --- a/src/providers/twitch/PubsubHelpers.hpp +++ b/src/providers/twitch/PubsubHelpers.hpp @@ -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); diff --git a/src/providers/twitch/TwitchAccount.cpp b/src/providers/twitch/TwitchAccount.cpp index f6337d0c6..2b2e62498 100644 --- a/src/providers/twitch/TwitchAccount.cpp +++ b/src/providers/twitch/TwitchAccount.cpp @@ -413,6 +413,8 @@ AccessGuard return this->emotes_.accessConst(); } +// AutoModActions + void TwitchAccount::parseEmotes(const rapidjson::Document &root) { auto emoteData = this->emotes_.access(); diff --git a/src/providers/twitch/TwitchAccount.hpp b/src/providers/twitch/TwitchAccount.hpp index 1ea718b73..bc53e0b24 100644 --- a/src/providers/twitch/TwitchAccount.hpp +++ b/src/providers/twitch/TwitchAccount.hpp @@ -108,6 +108,12 @@ public: void loadEmotes(); AccessGuard accessEmotes() const; + // Automod actions + void autoModAllow(const QString msgID, + std::function successCallback); + void autoModDeny(const QString msgID, + std::function successCallback); + private: void parseEmotes(const rapidjson::Document &document); void loadEmoteSetData(std::shared_ptr emoteSet); diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 91bfed93b..135c9cc44 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1671,6 +1671,13 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link, } break; + case Link::AutoModAllow: + { + } + case Link::AutoModDeny: + { + } + default:; } }