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.
This commit is contained in:
pajlada 2020-04-13 06:31:06 -04:00 committed by GitHub
parent 2ac0b60952
commit 6f926e7d77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 26 deletions

View file

@ -2,6 +2,7 @@
#include "Application.hpp" #include "Application.hpp"
#include "common/LinkParser.hpp" #include "common/LinkParser.hpp"
#include "controllers/accounts/AccountController.hpp"
#include "messages/Image.hpp" #include "messages/Image.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"
#include "messages/MessageElement.hpp" #include "messages/MessageElement.hpp"
@ -170,9 +171,12 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username,
this->message().searchText = text; 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::MessageBuilder(const BanAction &action, uint32_t count)
: MessageBuilder() : MessageBuilder()
{ {
auto current = getApp()->accounts->twitch.getCurrent();
this->emplace<TimestampElement>(); this->emplace<TimestampElement>();
this->message().flags.set(MessageFlag::System); this->message().flags.set(MessageFlag::System);
this->message().flags.set(MessageFlag::Timeout); this->message().flags.set(MessageFlag::Timeout);
@ -181,6 +185,36 @@ MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count)
QString text; QString text;
if (action.target.id == current->getUserId())
{
text.append("You were ");
if (action.isBan())
{
text.append("banned");
}
else
{
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.isBan()) if (action.isBan())
{ {
if (action.reason.isEmpty()) if (action.reason.isEmpty())
@ -220,6 +254,7 @@ MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count)
text.append(QString(" (%1 times)").arg(count)); text.append(QString(" (%1 times)").arg(count));
} }
} }
}
this->emplace<TextElement>(text, MessageElementFlag::Text, this->emplace<TextElement>(text, MessageElementFlag::Text,
MessageColor::System); MessageColor::System);

View file

@ -600,9 +600,6 @@ void TwitchChannel::loadRecentMessages()
void TwitchChannel::refreshPubsub() void TwitchChannel::refreshPubsub()
{ {
// listen to moderation actions
if (!this->hasModRights())
return;
auto roomId = this->roomId(); auto roomId = this->roomId();
if (roomId.isEmpty()) if (roomId.isEmpty())
return; return;