Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show restricted chats and suspicious treatment updates #5056

Merged
merged 18 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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)
- 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 Expand Up @@ -59,6 +60,7 @@
- Bugfix: Fixes to section deletion in text input fields. (#5013)
- Bugfix: Show user text input within watch streak notices. (#5029)
- Bugfix: Fixed avatar in usercard and moderation button triggering when releasing the mouse outside their area. (#5052)
- Bugfix: Fixed moderator-only topics being subscribed to for non-moderators. (#5056)
- Dev: Run miniaudio in a separate thread, and simplify it to not manage the device ourselves. There's a chance the simplification is a bad idea. (#4978)
- Dev: Change clang-format from v14 to v16. (#4929)
- Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791)
Expand Down
83 changes: 83 additions & 0 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "providers/twitch/PubSubActions.hpp"
#include "providers/twitch/PubSubManager.hpp"
#include "providers/twitch/PubSubMessages.hpp"
#include "providers/twitch/pubsubmessages/LowTrustUsers.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "providers/twitch/TwitchMessageBuilder.hpp"
Expand Down Expand Up @@ -473,6 +474,87 @@ void Application::initPubSub()
});
});

std::ignore =
this->twitch->pubsub->signals_.moderation.suspiciousMessageReceived
.connect([&](const auto &action) {
if (action.treatment ==
PubSubLowTrustUsersMessage::Treatment::INVALID)
{
qCWarning(chatterinoTwitch)
<< "Received suspicious message with unknown "
"treatment:"
<< action.treatmentString;
return;
}

// monitored chats are received over irc; in the future, we will use pubsub instead
if (action.treatment !=
PubSubLowTrustUsersMessage::Treatment::Restricted)
{
return;
pajlada marked this conversation as resolved.
Show resolved Hide resolved
}

if (getSettings()->streamerModeHideModActions &&
isInStreamerMode())
{
return;
}

auto chan =
this->twitch->getChannelOrEmptyByID(action.channelID);

if (chan->isEmpty())
{
return;
}

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

std::ignore =
this->twitch->pubsub->signals_.moderation.suspiciousTreatmentUpdated
.connect([&](const auto &action) {
if (action.treatment ==
PubSubLowTrustUsersMessage::Treatment::INVALID)
{
qCWarning(chatterinoTwitch)
<< "Received suspicious user update with unknown "
"treatment:"
<< action.treatmentString;
return;
}

if (action.updatedByUserLogin.isEmpty())
{
return;
iProdigy marked this conversation as resolved.
Show resolved Hide resolved
}

if (getSettings()->streamerModeHideModActions &&
isInStreamerMode())
{
return;
}

auto chan =
this->twitch->getChannelOrEmptyByID(action.channelID);
if (chan->isEmpty())
{
return;
}

postToThread([chan, action] {
auto msg =
TwitchMessageBuilder::makeLowTrustUpdateMessage(action);
chan->addMessage(msg);
});
});

std::ignore =
this->twitch->pubsub->signals_.moderation.autoModMessageCaught.connect(
[&](const auto &msg, const QString &channelID) {
Expand Down Expand Up @@ -672,6 +754,7 @@ void Application::initPubSub()
[this] {
this->twitch->pubsub->unlistenAllModerationActions();
this->twitch->pubsub->unlistenAutomod();
this->twitch->pubsub->unlistenLowTrustUsers();
this->twitch->pubsub->unlistenWhispers();
},
boost::signals2::at_front);
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ set(SOURCE_FILES
providers/twitch/pubsubmessages/ChatModeratorAction.hpp
providers/twitch/pubsubmessages/Listen.cpp
providers/twitch/pubsubmessages/Listen.hpp
providers/twitch/pubsubmessages/LowTrustUsers.cpp
providers/twitch/pubsubmessages/LowTrustUsers.hpp
providers/twitch/pubsubmessages/Message.hpp
providers/twitch/pubsubmessages/Unlisten.cpp
providers/twitch/pubsubmessages/Unlisten.hpp
Expand Down
1 change: 0 additions & 1 deletion src/common/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ bool Channel::isBroadcaster() const

bool Channel::hasModRights() const
{
// fourtf: check if staff
return this->isMod() || this->isBroadcaster();
}

Expand Down
1 change: 1 addition & 0 deletions src/messages/Message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum class MessageFlag : int64_t {
LiveUpdatesUpdate = (1LL << 30),
/// The message caught by AutoMod containing the user who sent the message & its contents
AutoModOffendingMessage = (1LL << 31),
LowTrustUsers = (1LL << 32),
};
using MessageFlags = FlagsEnum<MessageFlag>;

Expand Down
3 changes: 2 additions & 1 deletion src/messages/layouts/MessageLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ void MessageLayout::updateBuffer(QPixmap *buffer,
blendColors(backgroundColor,
*ctx.colorProvider.color(ColorType::RedeemedHighlight));
}
else if (this->message_->flags.has(MessageFlag::AutoMod))
else if (this->message_->flags.has(MessageFlag::AutoMod) ||
this->message_->flags.has(MessageFlag::LowTrustUsers))
{
backgroundColor = QColor("#404040");
}
Expand Down
76 changes: 76 additions & 0 deletions src/providers/twitch/PubSubManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "providers/twitch/PubSubHelpers.hpp"
#include "providers/twitch/PubSubMessages.hpp"
#include "providers/twitch/TwitchAccount.hpp"
#include "pubsubmessages/LowTrustUsers.hpp"
#include "util/DebugCount.hpp"
#include "util/Helpers.hpp"
#include "util/RapidjsonHelpers.hpp"
Expand Down Expand Up @@ -585,6 +586,25 @@ void PubSub::unlistenAutomod()
}
}

void PubSub::unlistenLowTrustUsers()
{
for (const auto &p : this->clients)
{
const auto &client = p.second;
if (const auto &[topics, nonce] =
client->unlistenPrefix("low-trust-users.");
!topics.empty())
{
this->registerNonce(nonce, {
client,
"UNLISTEN",
topics,
topics.size(),
});
}
}
}

void PubSub::unlistenWhispers()
{
for (const auto &p : this->clients)
Expand Down Expand Up @@ -670,6 +690,30 @@ void PubSub::listenToAutomod(const QString &channelID)
this->listenToTopic(topic);
}

void PubSub::listenToLowTrustUsers(const QString &channelID)
{
if (this->userID_.isEmpty())
{
qCDebug(chatterinoPubSub)
<< "Unable to listen to low trust users topic, no user logged in";
return;
}

static const QString topicFormat("low-trust-users.%1.%2");
assert(!channelID.isEmpty());

auto topic = topicFormat.arg(this->userID_, channelID);

if (this->isListeningToTopic(topic))
{
return;
}

qCDebug(chatterinoPubSub) << "Listen to topic" << topic;

this->listenToTopic(topic);
}

void PubSub::listenToChannelPointRewards(const QString &channelID)
{
static const QString topicFormat("community-points-channel-v1.%1");
Expand Down Expand Up @@ -1169,6 +1213,38 @@ void PubSub::handleMessageResponse(const PubSubMessageMessage &message)
this->signals_.moderation.autoModMessageCaught.invoke(innerMessage,
channelID);
}
else if (topic.startsWith("low-trust-users."))
{
auto oInnerMessage = message.toInner<PubSubLowTrustUsersMessage>();
if (!oInnerMessage)
{
return;
}

auto innerMessage = *oInnerMessage;

switch (innerMessage.type)
{
case PubSubLowTrustUsersMessage::Type::UserMessage: {
this->signals_.moderation.suspiciousMessageReceived.invoke(
innerMessage);
}
break;

case PubSubLowTrustUsersMessage::Type::TreatmentUpdate: {
this->signals_.moderation.suspiciousTreatmentUpdated.invoke(
innerMessage);
}
break;

case PubSubLowTrustUsersMessage::Type::INVALID: {
qCWarning(chatterinoPubSub)
<< "Invalid low trust users event type:"
<< innerMessage.typeString;
}
break;
}
}
else
{
qCDebug(chatterinoPubSub) << "Unknown topic:" << topic;
Expand Down
51 changes: 48 additions & 3 deletions src/providers/twitch/PubSubManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct PubSubAutoModQueueMessage;
struct AutomodAction;
struct AutomodUserAction;
struct AutomodInfoAction;
struct PubSubLowTrustUsersMessage;
struct PubSubWhisperMessage;

struct PubSubListenMessage;
Expand Down Expand Up @@ -67,9 +68,6 @@ class PubSub
QString userID_;

public:
// The max amount of connections we may open
static constexpr int maxConnections = 10;

PubSub(const QString &host,
std::chrono::seconds pingInterval = std::chrono::seconds(15));

Expand Down Expand Up @@ -100,6 +98,9 @@ class PubSub
Signal<BanAction> userBanned;
Signal<UnbanAction> userUnbanned;

Signal<PubSubLowTrustUsersMessage> suspiciousMessageReceived;
Signal<PubSubLowTrustUsersMessage> suspiciousTreatmentUpdated;

// Message caught by automod
// channelID
pajlada::Signals::Signal<PubSubAutoModQueueMessage, QString>
Expand All @@ -126,12 +127,56 @@ class PubSub

void unlistenAllModerationActions();
void unlistenAutomod();
void unlistenLowTrustUsers();
void unlistenWhispers();

/**
* Listen to incoming whispers for the currently logged in user.
* This topic is relevant for everyone.
*
* PubSub topic: whispers.{currentUserID}
*/
bool listenToWhispers();

/**
* Listen to moderation actions in the given channel.
* This topic is relevant for everyone.
* For moderators, this topic includes blocked/permitted terms updates,
* roomstate changes, general mod/vip updates, all bans/timeouts/deletions.
* For normal users, this topic includes moderation actions that are targetted at the local user:
* automod catching a user's sent message, a moderator approving or denying their caught messages,
* the user gaining/losing mod/vip, the user receiving a ban/timeout/deletion.
*
* PubSub topic: chat_moderator_actions.{currentUserID}.{channelID}
*/
void listenToChannelModerationActions(const QString &channelID);

/**
* Listen to Automod events in the given channel.
* This topic is only relevant for moderators.
* This will send events about incoming messages that
* are caught by Automod.
*
* PubSub topic: automod-queue.{currentUserID}.{channelID}
*/
void listenToAutomod(const QString &channelID);

/**
* Listen to Low Trust events in the given channel.
* This topic is only relevant for moderators.
* This will fire events about suspicious treatment updates
* and messages sent by restricted/monitored users.
*
iProdigy marked this conversation as resolved.
Show resolved Hide resolved
* PubSub topic: low-trust-users.{currentUserID}.{channelID}
*/
void listenToLowTrustUsers(const QString &channelID);

/**
* Listen to incoming channel point redemptions in the given channel.
* This topic is relevant for everyone.
*
* PubSub topic: community-points-channel-v1.{channelID}
*/
void listenToChannelPointRewards(const QString &channelID);

std::vector<QString> requests;
Expand Down
6 changes: 5 additions & 1 deletion src/providers/twitch/TwitchChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,11 @@ void TwitchChannel::refreshPubSub()
getApp()->twitch->pubsub->setAccount(currentAccount);

getApp()->twitch->pubsub->listenToChannelModerationActions(roomId);
getApp()->twitch->pubsub->listenToAutomod(roomId);
if (this->hasModRights())
{
getApp()->twitch->pubsub->listenToAutomod(roomId);
getApp()->twitch->pubsub->listenToLowTrustUsers(roomId);
}
pajlada marked this conversation as resolved.
Show resolved Hide resolved
getApp()->twitch->pubsub->listenToChannelPointRewards(roomId);
}

Expand Down
7 changes: 2 additions & 5 deletions src/providers/twitch/TwitchIrcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@

#include <cassert>

// using namespace Communi;
using namespace std::chrono_literals;

#define TWITCH_PUBSUB_URL "wss://pubsub-edge.twitch.tv"

namespace {

const QString TWITCH_PUBSUB_URL = "wss://pubsub-edge.twitch.tv";
const QString BTTV_LIVE_UPDATES_URL = "wss://sockets.betterttv.net/ws";
const QString SEVENTV_EVENTAPI_URL = "wss://events.7tv.io/v3";

Expand All @@ -45,11 +43,10 @@ TwitchIrcServer::TwitchIrcServer()
, liveChannel(new Channel("/live", Channel::Type::TwitchLive))
, automodChannel(new Channel("/automod", Channel::Type::TwitchAutomod))
, watchingChannel(Channel::getEmpty(), Channel::Type::TwitchWatching)
, pubsub(new PubSub(TWITCH_PUBSUB_URL))
pajlada marked this conversation as resolved.
Show resolved Hide resolved
{
this->initializeIrc();

this->pubsub = new PubSub(TWITCH_PUBSUB_URL);

if (getSettings()->enableBTTVLiveUpdates &&
getSettings()->enableBTTVChannelEmotes)
{
Expand Down
1 change: 1 addition & 0 deletions src/providers/twitch/TwitchIrcServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class TwitchIrcServer final : public AbstractIrcServer,
const ChannelPtr automodChannel;
IndirectChannel watchingChannel;

// NOTE: We currently leak this
PubSub *pubsub;
std::unique_ptr<BttvLiveUpdates> bttvLiveUpdates;
std::unique_ptr<SeventvEventAPI> seventvEventAPI;
Expand Down
Loading
Loading