diff --git a/src/Application.cpp b/src/Application.cpp index 2870c6ed6..d92e6e896 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -264,6 +264,7 @@ void Application::initPubsub() auto msg = MessageBuilder(action).release(); postToThread([chan, msg] { chan->addMessage(msg); }); + chan->deleteMessage(msg->id); }); this->twitch.pubsub->start(); diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index 905bd1b6c..82432db44 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -212,6 +212,31 @@ void Channel::replaceMessage(MessagePtr message, MessagePtr replacement) } } +void Channel::deleteMessage(QString messageID) +{ + LimitedQueueSnapshot snapshot = this->getMessageSnapshot(); + int snapshotLength = snapshot.size(); + + int end = std::max(0, snapshotLength - 20); + + QTime minimumTime = QTime::currentTime().addSecs(-5); + for (int i = snapshotLength - 1; i >= end; --i) + { + auto &s = snapshot[i]; + + if (s->parseTime < minimumTime) + { + break; + } + + if (s->id == messageID) + { + s->flags.set(MessageFlag::Disabled); + break; + } + } +} + void Channel::addRecentChatter(const MessagePtr &message) { } diff --git a/src/common/Channel.hpp b/src/common/Channel.hpp index c45d9c973..9abc668ea 100644 --- a/src/common/Channel.hpp +++ b/src/common/Channel.hpp @@ -62,6 +62,7 @@ public: void addOrReplaceTimeout(MessagePtr message); void disableAllMessages(); void replaceMessage(MessagePtr message, MessagePtr replacement); + void deleteMessage(QString messageID); QStringList modList; diff --git a/src/controllers/moderationactions/ModerationAction.cpp b/src/controllers/moderationactions/ModerationAction.cpp index 0b6418a57..8683f2c4e 100644 --- a/src/controllers/moderationactions/ModerationAction.cpp +++ b/src/controllers/moderationactions/ModerationAction.cpp @@ -73,6 +73,10 @@ ModerationAction::ModerationAction(const QString &action) { this->image_ = Image::fromPixmap(getApp()->resources->buttons.ban); } + else if (action.startsWith("/delete")) + { + this->image_ = Image::fromPixmap(getApp()->resources->pajaDank); + } else { QString xD = action; diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index 6c9d9b592..26766b1c0 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -267,6 +267,41 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) } } +void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message) +{ + // check parameter count + if (message->parameters().length() < 1) + { + return; + } + + QString chanName; + if (!trimChannelName(message->parameter(0), chanName)) + { + return; + } + + auto app = getApp(); + + // get channel + auto chan = app->twitch.server->getChannelOrEmpty(chanName); + + if (chan->isEmpty()) + { + log("[IrcMessageHandler:handleClearMessageMessage] Twitch channel {} " + "not " + "found", + chanName); + return; + } + + auto tags = message->tags(); + + QString targetID = tags.value("target-msg-id").toString(); + + chan->deleteMessage(targetID); +} + void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message) { auto app = getApp(); diff --git a/src/providers/twitch/IrcMessageHandler.hpp b/src/providers/twitch/IrcMessageHandler.hpp index 0474f097b..861ee734e 100644 --- a/src/providers/twitch/IrcMessageHandler.hpp +++ b/src/providers/twitch/IrcMessageHandler.hpp @@ -27,6 +27,7 @@ public: void handleRoomStateMessage(Communi::IrcMessage *message); void handleClearChatMessage(Communi::IrcMessage *message); + void handleClearMessageMessage(Communi::IrcMessage *message); void handleUserStateMessage(Communi::IrcMessage *message); void handleWhisperMessage(Communi::IrcMessage *message); diff --git a/src/providers/twitch/PubsubClient.cpp b/src/providers/twitch/PubsubClient.cpp index 0a8976618..5108c5ad4 100644 --- a/src/providers/twitch/PubsubClient.cpp +++ b/src/providers/twitch/PubsubClient.cpp @@ -710,6 +710,9 @@ PubSub::PubSub() // qDebug() << QString::fromStdString(rj::stringify(data)); }; + this->moderationActionHandlers["delete"] = + [this](const auto &data, const auto &roomID) { qDebug() << "xd"; }; + this->websocketClient.set_access_channels(websocketpp::log::alevel::all); this->websocketClient.clear_access_channels( websocketpp::log::alevel::frame_payload); diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 204cf6c04..6073e6449 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -582,6 +582,7 @@ void TwitchMessageBuilder::parseMessageID() { this->messageID = iterator.value().toString(); } + this->message().id = this->messageID; } void TwitchMessageBuilder::parseRoomID() diff --git a/src/providers/twitch/TwitchServer.cpp b/src/providers/twitch/TwitchServer.cpp index 349e40357..eaf90026e 100644 --- a/src/providers/twitch/TwitchServer.cpp +++ b/src/providers/twitch/TwitchServer.cpp @@ -156,6 +156,10 @@ void TwitchServer::messageReceived(Communi::IrcMessage *message) { handler.handleClearChatMessage(message); } + else if (command == "CLEARMSG") + { + handler.handleClearMessageMessage(message); + } else if (command == "USERSTATE") { handler.handleUserStateMessage(message); diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 9578c352a..a1fdf645f 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1667,7 +1667,9 @@ void ChannelView::handleLinkClick(QMouseEvent *event, const Link &link, case Link::UserAction: { QString value = link.value; - value.replace("{user}", layout->getMessage()->loginName).replace("{channel}", this->channel_->getName()); + value.replace("{user}", layout->getMessage()->loginName) + .replace("{channel}", this->channel_->getName()) + .replace("{msg-id}", layout->getMessage()->id); this->channel_->sendMessage(value); } break;