Skip to content

Commit

Permalink
feat: add badges, emotes, and filters for suspicious messages (#5060)
Browse files Browse the repository at this point in the history
* feat: show chat badges on suspicious user messages

* feat: display emotes in suspicious user messages

* feat: add search filters for suspicious messages

* chore: update changelog

* refactor: resolve initial nits

* fix: finish adding new filter identifier

* Comment the new message flags

* Add a list of known issues to low trust update messages

* fix: Keep shared-pointerness of the channel

Without this change, we would have the possibility of using the
TwitchChannel after the Channel itself has gone out of scope, albeit not
realistically since we just post this to a thread and parse it - there's
no networking or big delays involved. but this shows the intent better

---------

Co-authored-by: Rasmus Karlsson <[email protected]>
  • Loading branch information
iProdigy and pajlada authored Jan 6, 2024
1 parent 416806b commit 693d4f4
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 133 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- Major: Allow use of Twitch follower emotes in other channels if subscribed. (#4922)
- Major: Add `/automod` split to track automod caught messages across all open channels the user moderates. (#4986, #5026)
- Major: Show restricted chat messages and suspicious treatment updates. (#5056)
- Major: Show restricted chat messages and suspicious treatment updates. (#5056, #5060)
- Minor: Migrate to the new Get Channel Followers Helix endpoint, fixing follower count not showing up in usercards. (#4809)
- Minor: The account switcher is now styled to match your theme. (#4817)
- Minor: Add an invisible resize handle to the bottom of frameless user info popups and reply thread popups. (#4795)
Expand Down
16 changes: 12 additions & 4 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,20 @@ void Application::initPubSub()
return;
}

postToThread([chan, action] {
auto twitchChannel =
std::dynamic_pointer_cast<TwitchChannel>(chan);
if (!twitchChannel)
{
return;
}

postToThread([twitchChannel, action] {
const auto p =
TwitchMessageBuilder::makeLowTrustUserMessage(
action, chan->getName());
chan->addMessage(p.first);
chan->addMessage(p.second);
action, twitchChannel->getName(),
twitchChannel.get());
twitchChannel->addMessage(p.first);
twitchChannel->addMessage(p.second);
});
});

Expand Down
4 changes: 4 additions & 0 deletions src/controllers/filters/lang/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel)
* flags.whisper
* flags.reply
* flags.automod
* flags.restricted
* flags.monitored
*
* message.content
* message.length
Expand Down Expand Up @@ -101,6 +103,8 @@ ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel)
{"flags.whisper", m->flags.has(MessageFlag::Whisper)},
{"flags.reply", m->flags.has(MessageFlag::ReplyMessage)},
{"flags.automod", m->flags.has(MessageFlag::AutoMod)},
{"flags.restricted", m->flags.has(MessageFlag::RestrictedMessage)},
{"flags.monitored", m->flags.has(MessageFlag::MonitoredMessage)},

{"message.content", m->messageText},
{"message.length", m->messageText.length()},
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/filters/lang/Filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ static const QMap<QString, Type> MESSAGE_TYPING_CONTEXT = {
{"flags.whisper", Type::Bool},
{"flags.reply", Type::Bool},
{"flags.automod", Type::Bool},
{"flags.restricted", Type::Bool},
{"flags.monitored", Type::Bool},
{"message.content", Type::String},
{"message.length", Type::Int},
};
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/filters/lang/Tokenizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ static const QMap<QString, QString> validIdentifiersMap = {
{"flags.whisper", "whisper message?"},
{"flags.reply", "reply message?"},
{"flags.automod", "automod message?"},
{"flags.restricted", "restricted message?"},
{"flags.monitored", "monitored message?"},
{"message.content", "message text"},
{"message.length", "message length"}};

Expand Down
4 changes: 4 additions & 0 deletions src/messages/Message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ enum class MessageFlag : int64_t {
/// The message caught by AutoMod containing the user who sent the message & its contents
AutoModOffendingMessage = (1LL << 31),
LowTrustUsers = (1LL << 32),
/// The message is sent by a user marked as restricted with Twitch's "Low Trust"/"Suspicious User" feature
RestrictedMessage = (1LL << 33),
/// The message is sent by a user marked as monitor with Twitch's "Low Trust"/"Suspicious User" feature
MonitoredMessage = (1LL << 34),
};
using MessageFlags = FlagsEnum<MessageFlag>;

Expand Down
8 changes: 8 additions & 0 deletions src/messages/search/MessageFlagsPredicate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ MessageFlagsPredicate::MessageFlagsPredicate(const QString &flags, bool negate)
{
this->flags_.set(MessageFlag::ReplyMessage);
}
else if (flag == "restricted")
{
this->flags_.set(MessageFlag::RestrictedMessage);
}
else if (flag == "monitored")
{
this->flags_.set(MessageFlag::MonitoredMessage);
}
}
}

Expand Down
Loading

0 comments on commit 693d4f4

Please sign in to comment.