Make deletions show like timeouts/bans. (#2841)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Mm2PL 2021-06-06 15:51:57 +00:00 committed by GitHub
parent 8639f450f2
commit f1e843a672
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 60 additions and 3 deletions

View file

@ -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)

View file

@ -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();
@ -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

View file

@ -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;

View file

@ -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)

View file

@ -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

View file

@ -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;

View file

@ -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};

View file

@ -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,)",