diff --git a/CHANGELOG.md b/CHANGELOG.md index 92363681e..5c3817acb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unversioned +- Minor: Messages held by automod are now shown to the user. (#2626) - Bugfix: Automod messages now work properly again. (#2682) - Bugfix: `Login expired` message no longer highlights all tabs. (#2735) diff --git a/src/Application.cpp b/src/Application.cpp index 71575702a..6ab75d976 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -314,7 +314,7 @@ void Application::initPubsub() } postToThread([chan, action] { - auto p = makeAutomodMessage(action); + const auto p = makeAutomodMessage(action); chan->addMessage(p.first); chan->addMessage(p.second); }); @@ -338,6 +338,22 @@ void Application::initPubsub() chan->deleteMessage(msg->id); }); + this->twitch.pubsub->signals_.moderation.automodInfoMessage.connect( + [&](const auto &action) { + auto chan = + this->twitch.server->getChannelOrEmptyByID(action.roomID); + + if (chan->isEmpty()) + { + return; + } + + postToThread([chan, action] { + const auto p = makeAutomodInfoMessage(action); + chan->addMessage(p); + }); + }); + this->twitch.pubsub->signals_.pointReward.redeemed.connect([&](auto &data) { QString channelId; if (rj::getSafe(data, "channel_id", channelId)) diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index b49e4413c..c943ecaf6 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -29,6 +29,53 @@ MessagePtr makeSystemMessage(const QString &text, const QTime &time) return MessageBuilder(systemMessage, text, time).release(); } +MessagePtr makeAutomodInfoMessage(const AutomodInfoAction &action) +{ + auto builder = MessageBuilder(); + + builder.emplace(); + builder.message().flags.set(MessageFlag::PubSub); + + builder + .emplace(Image::fromPixmap(getResources().twitch.automod), + MessageElementFlag::BadgeChannelAuthority) + ->setTooltip("AutoMod"); + builder.emplace("AutoMod:", MessageElementFlag::BoldUsername, + MessageColor(QColor("blue")), + FontStyle::ChatMediumBold); + builder.emplace( + "AutoMod:", MessageElementFlag::NonBoldUsername, + MessageColor(QColor("blue"))); + switch (action.type) + { + case AutomodInfoAction::OnHold: { + builder.emplace(("Hey! Your message is being checked " + "by mods and has not been sent."), + MessageElementFlag::Text, + MessageColor::Text); + } + break; + case AutomodInfoAction::Denied: { + builder.emplace(("Mods have removed your message."), + MessageElementFlag::Text, + MessageColor::Text); + } + break; + case AutomodInfoAction::Approved: { + builder.emplace(("Mods have accepted your message."), + MessageElementFlag::Text, + MessageColor::Text); + } + break; + } + + builder.message().flags.set(MessageFlag::AutoMod); + + auto message = builder.release(); + + return message; +} + std::pair makeAutomodMessage( const AutomodAction &action) { diff --git a/src/messages/MessageBuilder.hpp b/src/messages/MessageBuilder.hpp index e7a5d453d..82c76f052 100644 --- a/src/messages/MessageBuilder.hpp +++ b/src/messages/MessageBuilder.hpp @@ -11,6 +11,7 @@ struct BanAction; struct UnbanAction; struct AutomodAction; struct AutomodUserAction; +struct AutomodInfoAction; struct Message; using MessagePtr = std::shared_ptr; @@ -25,6 +26,7 @@ MessagePtr makeSystemMessage(const QString &text); MessagePtr makeSystemMessage(const QString &text, const QTime &time); std::pair makeAutomodMessage( const AutomodAction &action); +MessagePtr makeAutomodInfoMessage(const AutomodInfoAction &action); struct MessageParseArgs { bool disablePingSounds = false; diff --git a/src/providers/twitch/PubsubActions.hpp b/src/providers/twitch/PubsubActions.hpp index 1356aac69..f6cfa2cf8 100644 --- a/src/providers/twitch/PubsubActions.hpp +++ b/src/providers/twitch/PubsubActions.hpp @@ -133,4 +133,13 @@ struct AutomodUserAction : PubSubAction { QString message; }; +struct AutomodInfoAction : PubSubAction { + using PubSubAction::PubSubAction; + enum { + OnHold, + Denied, + Approved, + } type; +}; + } // namespace chatterino diff --git a/src/providers/twitch/PubsubClient.cpp b/src/providers/twitch/PubsubClient.cpp index 14a10372c..518a96b24 100644 --- a/src/providers/twitch/PubsubClient.cpp +++ b/src/providers/twitch/PubsubClient.cpp @@ -583,6 +583,27 @@ PubSub::PubSub() } }; + this->moderationActionHandlers["automod_message_rejected"] = + [this](const auto &data, const auto &roomID) { + AutomodInfoAction action(data, roomID); + action.type = AutomodInfoAction::OnHold; + this->signals_.moderation.automodInfoMessage.invoke(action); + }; + + this->moderationActionHandlers["automod_message_denied"] = + [this](const auto &data, const auto &roomID) { + AutomodInfoAction action(data, roomID); + action.type = AutomodInfoAction::Denied; + this->signals_.moderation.automodInfoMessage.invoke(action); + }; + + this->moderationActionHandlers["automod_message_approved"] = + [this](const auto &data, const auto &roomID) { + AutomodInfoAction action(data, roomID); + action.type = AutomodInfoAction::Approved; + this->signals_.moderation.automodInfoMessage.invoke(action); + }; + this->channelTermsActionHandlers["add_permitted_term"] = [this](const auto &data, const auto &roomID) { // This term got a pass through automod diff --git a/src/providers/twitch/PubsubClient.hpp b/src/providers/twitch/PubsubClient.hpp index f64dd078d..4e0eccddc 100644 --- a/src/providers/twitch/PubsubClient.hpp +++ b/src/providers/twitch/PubsubClient.hpp @@ -132,6 +132,7 @@ public: Signal automodMessage; Signal automodUserMessage; + Signal automodInfoMessage; } moderation; struct {