From f1e843a67275cd8e9d5a3c738a504d54b7743c42 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sun, 6 Jun 2021 15:51:57 +0000 Subject: [PATCH] Make deletions show like timeouts/bans. (#2841) Co-authored-by: pajlada --- CHANGELOG.md | 1 + src/common/Channel.cpp | 12 +++++-- src/common/Channel.hpp | 1 + src/providers/twitch/IrcMessageHandler.cpp | 12 ++++++- src/providers/twitch/TwitchMessageBuilder.cpp | 31 +++++++++++++++++++ src/providers/twitch/TwitchMessageBuilder.hpp | 2 ++ src/singletons/Settings.hpp | 2 ++ src/widgets/settingspages/GeneralPage.cpp | 2 ++ 8 files changed, 60 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ffcb8a9f..5bc5e9d6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Minor: Limit the number of recent chatters to improve memory usage and reduce freezes. (#2796, #2814) - Minor: Added `/popout` command. Usage: `/popout [channel]`. It opens browser chat for the provided channel. Can also be used without arguments to open current channels browser chat. (#2556, #2812) - Minor: Improved matching of game names when using `/setgame` command (#2636) +- Minor: Now shows deletions of messages like timeouts (#1155, #2841) - Minor: Added a link to accounts page in settings to "You need to be logged in to send messages" message. (#2862) - Minor: Switch to Twitch v2 emote API for animated emote support. (#2863) - Bugfix: Fixed FFZ emote links for global emotes (#2807, #2808) diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index 887beb2a1..63c5ba720 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -239,6 +239,14 @@ void Channel::replaceMessage(size_t index, MessagePtr replacement) } void Channel::deleteMessage(QString messageID) +{ + auto msg = this->findMessage(messageID); + if (msg != nullptr) + { + msg->flags.set(MessageFlag::Disabled); + } +} +MessagePtr Channel::findMessage(QString messageID) { LimitedQueueSnapshot snapshot = this->getMessageSnapshot(); int snapshotLength = snapshot.size(); @@ -251,10 +259,10 @@ void Channel::deleteMessage(QString messageID) if (s->id == messageID) { - s->flags.set(MessageFlag::Disabled); - break; + return s; } } + return nullptr; } bool Channel::canSendMessage() const diff --git a/src/common/Channel.hpp b/src/common/Channel.hpp index 0c3241736..81d28f928 100644 --- a/src/common/Channel.hpp +++ b/src/common/Channel.hpp @@ -78,6 +78,7 @@ public: void replaceMessage(MessagePtr message, MessagePtr replacement); void replaceMessage(size_t index, MessagePtr replacement); void deleteMessage(QString messageID); + MessagePtr findMessage(QString messageID); bool hasMessages() const; diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index acdb8d86a..c7b27fc0f 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -479,7 +479,17 @@ void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message) QString targetID = tags.value("target-msg-id").toString(); - chan->deleteMessage(targetID); + auto msg = chan->findMessage(targetID); + if (msg != nullptr) + { + msg->flags.set(MessageFlag::Disabled); + if (!getSettings()->hideDeletionActions) + { + MessageBuilder builder; + TwitchMessageBuilder::deletionMessage(msg, &builder); + chan->addMessage(builder.release()); + } + } } void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message) diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 923df4dbb..f1c05e1af 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -1356,5 +1356,36 @@ void TwitchMessageBuilder::hostingSystemMessage(const QString &channelName, MessageColor::System, FontStyle::ChatMediumBold) ->setLink({Link::UserInfo, channelName}); } +void TwitchMessageBuilder::deletionMessage(const MessagePtr originalMessage, + MessageBuilder *builder) +{ + builder->emplace(); + builder->message().flags.set(MessageFlag::System); + builder->message().flags.set(MessageFlag::DoNotTriggerNotification); + builder->message().flags.set(MessageFlag::Timeout); + // TODO(mm2pl): If or when jumping to a single message gets implemented a link, + // add a link to the originalMessage + builder->emplace("A message from", MessageElementFlag::Text, + MessageColor::System); + builder + ->emplace(originalMessage->displayName, + MessageElementFlag::Username, + MessageColor::System, FontStyle::ChatMediumBold) + ->setLink({Link::UserInfo, originalMessage->loginName}); + builder->emplace("was deleted:", MessageElementFlag::Text, + MessageColor::System); + if (originalMessage->messageText.length() > 50) + { + builder->emplace( + originalMessage->messageText.left(50) + "...", + MessageElementFlag::Text, MessageColor::Text); + } + else + { + builder->emplace(originalMessage->messageText, + MessageElementFlag::Text, + MessageColor::Text); + } +} } // namespace chatterino diff --git a/src/providers/twitch/TwitchMessageBuilder.hpp b/src/providers/twitch/TwitchMessageBuilder.hpp index ee780c4a6..f0b53d98c 100644 --- a/src/providers/twitch/TwitchMessageBuilder.hpp +++ b/src/providers/twitch/TwitchMessageBuilder.hpp @@ -64,6 +64,8 @@ public: MessageBuilder *builder); static void hostingSystemMessage(const QString &channelName, MessageBuilder *builder); + static void deletionMessage(const MessagePtr originalMessage, + MessageBuilder *builder); private: void parseUsernameColor() override; diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index e53599d38..23e032458 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -84,6 +84,8 @@ public: BoolSetting hideModerated = {"/appearance/messages/hideModerated", false}; BoolSetting hideModerationActions = { "/appearance/messages/hideModerationActions", false}; + BoolSetting hideDeletionActions = { + "/appearance/messages/hideDeletionActions", false}; BoolSetting colorizeNicknames = {"/appearance/messages/colorizeNicknames", true}; diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 573dfaa74..fcb199c67 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -597,6 +597,8 @@ void GeneralPage::initLayout(GeneralPageView &layout) layout.addCheckbox("Show moderation messages", s.hideModerationActions, true); + layout.addCheckbox("Show deletions of single messages", + s.hideDeletionActions, true); layout.addCheckbox("Colorize users without color set (gray names)", s.colorizeNicknames); layout.addCheckbox("Mention users with a comma (User,)",