Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/common/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ LimitedQueueSnapshot<MessagePtr> Channel::getMessageSnapshot()
void Channel::addMessage(MessagePtr message, MessageContext context,
std::optional<MessageFlags> overridingFlags)
{
message->freeze();

MessagePtr deleted;

if (context == MessageContext::Original && this->getType() != Type::None)
Expand Down Expand Up @@ -157,6 +159,11 @@ void Channel::disableAllMessages()

void Channel::addMessagesAtStart(const std::vector<MessagePtr> &_messages)
{
for (const auto &msg : _messages)
{
msg->freeze();
}

std::vector<MessagePtr> addedMessages =
this->messages_.pushFront(_messages);

Expand All @@ -172,6 +179,10 @@ void Channel::fillInMissingMessages(const std::vector<MessagePtr> &messages)
{
return;
}
for (const auto &msg : messages)
{
msg->freeze();
}

auto snapshot = this->getMessageSnapshot();
if (snapshot.size() == 0)
Expand Down Expand Up @@ -256,6 +267,7 @@ void Channel::fillInMissingMessages(const std::vector<MessagePtr> &messages)
void Channel::replaceMessage(const MessagePtr &message,
const MessagePtr &replacement)
{
replacement->freeze();
int index = this->messages_.replaceItem(message, replacement);

if (index >= 0)
Expand All @@ -266,6 +278,8 @@ void Channel::replaceMessage(const MessagePtr &message,

void Channel::replaceMessage(size_t index, const MessagePtr &replacement)
{
replacement->freeze();

MessagePtr prev;
if (this->messages_.replaceItem(index, replacement, &prev))
{
Expand All @@ -276,6 +290,8 @@ void Channel::replaceMessage(size_t index, const MessagePtr &replacement)
void Channel::replaceMessage(size_t hint, const MessagePtr &message,
const MessagePtr &replacement)
{
replacement->freeze();

auto index = this->messages_.replaceItem(hint, message, replacement);
if (index >= 0)
{
Expand Down
1 change: 1 addition & 0 deletions src/messages/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ QJsonObject Message::toJson() const
{"count"_L1, static_cast<qint64>(this->count)},
{"serverReceivedTime"_L1,
this->serverReceivedTime.toString(Qt::ISODate)},
{"frozen"_L1, this->frozen},
};

QJsonArray badges;
Expand Down
12 changes: 12 additions & 0 deletions src/messages/Message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,25 @@ struct Message {
};
ReplyStatus isReplyable() const;
uint32_t count = 1;

/// Can this message be modified?
Comment thread
Mm2PL marked this conversation as resolved.
///
/// This is only used for plugins right now. This value is only ever set to
/// true.
mutable bool frozen = false;

std::vector<std::unique_ptr<MessageElement>> elements;

ScrollbarHighlight getScrollBarHighlight() const;

std::shared_ptr<ChannelPointReward> reward = nullptr;

QJsonObject toJson() const;

void freeze() const
{
this->frozen = true;
}
};

} // namespace chatterino
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessageHeader|EventSub|ModerationAction",
"frozen": true,
"id": "automod_19d067ff-89b5-4790-a720-97599894eb6b",
"localizedName": "",
"loginName": "automod",
Expand Down Expand Up @@ -243,6 +244,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessage|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessageHeader|AutoModBlockedTerm|EventSub|ModerationAction",
"frozen": true,
"id": "automod_0cbb6e48-1606-46c6-b1ac-c97626e1c5cb",
"localizedName": "",
"loginName": "automod",
Expand Down Expand Up @@ -257,6 +258,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessage|AutoModBlockedTerm|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessageHeader|AutoModBlockedTerm|EventSub|ModerationAction",
"frozen": true,
"id": "automod_c0fac418-25a9-41b8-adf3-5bd637fca1e1",
"localizedName": "",
"loginName": "automod",
Expand Down Expand Up @@ -249,6 +250,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessage|AutoModBlockedTerm|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessageHeader|AutoModBlockedTerm|EventSub|ModerationAction",
"frozen": true,
"id": "automod_45a63ca1-1b0c-46ef-9075-d112f9a9f376",
"localizedName": "",
"loginName": "automod",
Expand Down Expand Up @@ -307,6 +308,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessage|AutoModBlockedTerm|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessageHeader|EventSub|ModerationAction",
"frozen": true,
"id": "automod_19d067ff-89b5-4790-a720-97599894eb6b",
"localizedName": "",
"loginName": "automod",
Expand Down Expand Up @@ -243,6 +244,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessage|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "testaccount_420",
Expand Down
2 changes: 2 additions & 0 deletions tests/snapshots/EventSub/automod-message-update/approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
}
],
"flags": "Disabled|PubSub|AutoMod|AutoModOffendingMessageHeader|EventSub|ModerationAction",
"frozen": true,
"id": "automod_19d067ff-89b5-4790-a720-97599894eb6b",
"localizedName": "",
"loginName": "automod",
Expand Down Expand Up @@ -283,6 +284,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessage|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
2 changes: 2 additions & 0 deletions tests/snapshots/EventSub/automod-message-update/denied.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
}
],
"flags": "Disabled|PubSub|AutoMod|AutoModOffendingMessageHeader|EventSub|ModerationAction",
"frozen": true,
"id": "automod_19d067ff-89b5-4790-a720-97599894eb6b",
"localizedName": "",
"loginName": "automod",
Expand Down Expand Up @@ -283,6 +284,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessage|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
2 changes: 2 additions & 0 deletions tests/snapshots/EventSub/automod-message-update/expired.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
}
],
"flags": "Disabled|PubSub|AutoMod|AutoModOffendingMessageHeader|EventSub|ModerationAction",
"frozen": true,
"id": "automod_19d067ff-89b5-4790-a720-97599894eb6b",
"localizedName": "",
"loginName": "automod",
Expand Down Expand Up @@ -283,6 +284,7 @@
}
],
"flags": "PubSub|AutoMod|AutoModOffendingMessage|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
}
],
"flags": "PubSub|AutoMod|EventSub",
"frozen": true,
"id": "automod_e39e3c58-3d25-49fd-8c94-e776ef57a7f8",
"localizedName": "",
"loginName": "automod",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
}
],
"flags": "PubSub|AutoMod|EventSub",
"frozen": true,
"id": "automod_5686ec52-e02c-4042-ac21-1dfd8cab0f9f",
"localizedName": "",
"loginName": "automod",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
}
],
"flags": "PubSub|AutoMod|EventSub",
"frozen": true,
"id": "automod_fc90dc3b-0634-41c3-8365-f40719f076ab",
"localizedName": "",
"loginName": "automod",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
}
],
"flags": "System|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
}
],
"flags": "System|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
}
],
"flags": "System|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
}
],
"flags": "System|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/EventSub/channel-moderate/ban-reason.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
}
],
"flags": "System|Timeout|PubSub|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
}
],
"flags": "System|Timeout|PubSub|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "",
Expand Down Expand Up @@ -351,6 +352,7 @@
}
],
"flags": "System|Timeout|PubSub|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
2 changes: 2 additions & 0 deletions tests/snapshots/EventSub/channel-moderate/ban-stacking.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
}
],
"flags": "System|Timeout|PubSub|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "",
Expand Down Expand Up @@ -333,6 +334,7 @@
}
],
"flags": "System|Timeout|PubSub|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/EventSub/channel-moderate/ban.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
}
],
"flags": "System|Timeout|PubSub|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/EventSub/channel-moderate/clear.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
}
],
"flags": "System|DoNotTriggerNotification|PubSub|ClearChat|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "",
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/EventSub/channel-moderate/delete-long.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
}
],
"flags": "System|DoNotTriggerNotification|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "testaccount_420",
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/EventSub/channel-moderate/delete.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
}
],
"flags": "System|DoNotTriggerNotification|EventSub|ModerationAction",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "testaccount_420",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
}
],
"flags": "System|EventSub",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/EventSub/channel-moderate/emoteonly.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
}
],
"flags": "System|EventSub",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
}
],
"flags": "System|EventSub",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
}
],
"flags": "System|EventSub",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/EventSub/channel-moderate/followers.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
}
],
"flags": "System|EventSub",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "nerixyz",
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/EventSub/channel-moderate/mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
}
],
"flags": "System|EventSub",
"frozen": true,
"id": "",
"localizedName": "",
"loginName": "uint128",
Expand Down
Loading
Loading