From 6f926e7d77b7d9b7462e9b7bf6508e61cbb0ce29 Mon Sep 17 00:00:00 2001 From: pajlada Date: Mon, 13 Apr 2020 06:31:06 -0400 Subject: [PATCH] Get better timeout messages for self (#1629) * Don't require mod rights to listen to moderation actions topic * Format timeout messages directed at you differently e.g. "You were banned" or "You were timed out for 4h20m", also including reason if specified. --- src/messages/MessageBuilder.cpp | 81 ++++++++++++++++++-------- src/providers/twitch/TwitchChannel.cpp | 3 - 2 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index 6e4b8115..c215a60a 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -2,6 +2,7 @@ #include "Application.hpp" #include "common/LinkParser.hpp" +#include "controllers/accounts/AccountController.hpp" #include "messages/Image.hpp" #include "messages/Message.hpp" #include "messages/MessageElement.hpp" @@ -170,9 +171,12 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username, this->message().searchText = text; } +// XXX: This does not belong in the MessageBuilder, this should be part of the TwitchMessageBuilder MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count) : MessageBuilder() { + auto current = getApp()->accounts->twitch.getCurrent(); + this->emplace(); this->message().flags.set(MessageFlag::System); this->message().flags.set(MessageFlag::Timeout); @@ -181,43 +185,74 @@ MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count) QString text; - if (action.isBan()) + if (action.target.id == current->getUserId()) { - if (action.reason.isEmpty()) + text.append("You were "); + if (action.isBan()) { - text = QString("%1 banned %2.") // - .arg(action.source.name) - .arg(action.target.name); + text.append("banned"); } else { - text = QString("%1 banned %2: \"%3\".") // - .arg(action.source.name) - .arg(action.target.name) - .arg(action.reason); + text.append( + QString("timed out for %1").arg(formatTime(action.duration))); + } + + if (!action.source.name.isEmpty()) + { + text.append(" by "); + text.append(action.source.name); + } + + if (action.reason.isEmpty()) + { + text.append("."); + } + else + { + text.append(QString(": \"%1\".").arg(action.reason)); } } else { - if (action.reason.isEmpty()) + if (action.isBan()) { - text = QString("%1 timed out %2 for %3.") // - .arg(action.source.name) - .arg(action.target.name) - .arg(formatTime(action.duration)); + if (action.reason.isEmpty()) + { + text = QString("%1 banned %2.") // + .arg(action.source.name) + .arg(action.target.name); + } + else + { + text = QString("%1 banned %2: \"%3\".") // + .arg(action.source.name) + .arg(action.target.name) + .arg(action.reason); + } } else { - text = QString("%1 timed out %2 for %3: \"%4\".") // - .arg(action.source.name) - .arg(action.target.name) - .arg(formatTime(action.duration)) - .arg(action.reason); - } + if (action.reason.isEmpty()) + { + text = QString("%1 timed out %2 for %3.") // + .arg(action.source.name) + .arg(action.target.name) + .arg(formatTime(action.duration)); + } + else + { + text = QString("%1 timed out %2 for %3: \"%4\".") // + .arg(action.source.name) + .arg(action.target.name) + .arg(formatTime(action.duration)) + .arg(action.reason); + } - if (count > 1) - { - text.append(QString(" (%1 times)").arg(count)); + if (count > 1) + { + text.append(QString(" (%1 times)").arg(count)); + } } } diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index c009f5f6..ac448b30 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -600,9 +600,6 @@ void TwitchChannel::loadRecentMessages() void TwitchChannel::refreshPubsub() { - // listen to moderation actions - if (!this->hasModRights()) - return; auto roomId = this->roomId(); if (roomId.isEmpty()) return;