Skip to content

Commit

Permalink
Make deletions show like timeouts/bans. (#2841)
Browse files Browse the repository at this point in the history
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
  • Loading branch information
Mm2PL and pajlada authored Jun 6, 2021
1 parent 8639f45 commit f1e843a
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions src/common/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MessagePtr> snapshot = this->getMessageSnapshot();
int snapshotLength = snapshot.size();
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/common/Channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Channel : public std::enable_shared_from_this<Channel>
void replaceMessage(MessagePtr message, MessagePtr replacement);
void replaceMessage(size_t index, MessagePtr replacement);
void deleteMessage(QString messageID);
MessagePtr findMessage(QString messageID);

bool hasMessages() const;

Expand Down
12 changes: 11 additions & 1 deletion src/providers/twitch/IrcMessageHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimestampElement>();
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<TextElement>("A message from", MessageElementFlag::Text,
MessageColor::System);
builder
->emplace<TextElement>(originalMessage->displayName,
MessageElementFlag::Username,
MessageColor::System, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, originalMessage->loginName});
builder->emplace<TextElement>("was deleted:", MessageElementFlag::Text,
MessageColor::System);
if (originalMessage->messageText.length() > 50)
{
builder->emplace<TextElement>(
originalMessage->messageText.left(50) + "...",
MessageElementFlag::Text, MessageColor::Text);
}
else
{
builder->emplace<TextElement>(originalMessage->messageText,
MessageElementFlag::Text,
MessageColor::Text);
}
}

} // namespace chatterino
2 changes: 2 additions & 0 deletions src/providers/twitch/TwitchMessageBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class TwitchMessageBuilder : public SharedMessageBuilder
MessageBuilder *builder);
static void hostingSystemMessage(const QString &channelName,
MessageBuilder *builder);
static void deletionMessage(const MessagePtr originalMessage,
MessageBuilder *builder);

private:
void parseUsernameColor() override;
Expand Down
2 changes: 2 additions & 0 deletions src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class Settings : public ABSettings, public ConcurrentSettings
BoolSetting hideModerated = {"/appearance/messages/hideModerated", false};
BoolSetting hideModerationActions = {
"/appearance/messages/hideModerationActions", false};
BoolSetting hideDeletionActions = {
"/appearance/messages/hideDeletionActions", false};
BoolSetting colorizeNicknames = {"/appearance/messages/colorizeNicknames",
true};

Expand Down
2 changes: 2 additions & 0 deletions src/widgets/settingspages/GeneralPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,)",
Expand Down

0 comments on commit f1e843a

Please sign in to comment.