feat(eventsub): implement (shared-chat) timeout (#5995)

This commit is contained in:
nerix
2025-02-26 22:00:53 +01:00
committed by GitHub
parent e59defb864
commit a89c1910ba
9 changed files with 522 additions and 31 deletions
@@ -3,9 +3,11 @@
#include "Application.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "providers/twitch/eventsub/MessageBuilder.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "singletons/Settings.hpp"
#include "singletons/WindowManager.hpp"
#include "util/FormatTime.hpp"
#include "util/PostToThread.hpp"
namespace chatterino::eventsub {
@@ -27,18 +29,59 @@ void handleModerateMessage(
});
}
void addModerateMessage(
TwitchChannel *channel, MessagePtr message, const QDateTime &time,
const lib::payload::channel_moderate::v2::Ban & /*action*/)
void handleModerateMessage(
TwitchChannel *chan, const QDateTime &time,
const lib::payload::channel_moderate::v2::Event &event,
const lib::payload::channel_moderate::v2::Timeout &action)
{
runInGuiThread([channel, msg{std::move(message)}, time] {
channel->addOrReplaceTimeout(msg, time);
if (getSettings()->hideModerated)
{
// XXX: This is expensive. We could use a layout request if the layout
// would store the previous message flags.
getApp()->getWindows()->forceLayoutChannelViews();
}
// Not all compilers support QDateTime::toStdSysMilliseconds
std::chrono::system_clock::time_point chronoTime{
std::chrono::milliseconds{time.toMSecsSinceEpoch()}};
auto duration =
std::chrono::round<std::chrono::seconds>(action.expiresAt - chronoTime);
EventSubMessageBuilder builder(chan, time);
builder->loginName = event.moderatorUserLogin.qt();
QString text;
bool isShared = event.isFromSharedChat();
builder.appendUser(event.moderatorUserName, event.moderatorUserLogin, text);
builder.emplaceSystemTextAndUpdate("timed out", text);
builder.appendUser(action.userName, action.userLogin, text);
builder.emplaceSystemTextAndUpdate("for", text);
builder
.emplaceSystemTextAndUpdate(
formatTime(static_cast<int>(duration.count())), text)
->setTrailingSpace(isShared);
if (isShared)
{
builder.emplaceSystemTextAndUpdate("in", text);
builder.appendUser(*event.sourceBroadcasterUserName,
*event.sourceBroadcasterUserLogin, text, false);
}
if (action.reason.view().empty())
{
builder.emplaceSystemTextAndUpdate(".", text);
}
else
{
builder.emplaceSystemTextAndUpdate(":", text);
builder.emplaceSystemTextAndUpdate(action.reason.qt(), text);
}
builder->messageText = text;
builder->searchText = text;
builder->timeoutUser = action.userLogin.qt();
auto msg = builder.release();
runInGuiThread([chan, msg] {
// TODO: addOrReplaceTimeout (doesn't work with shared chat yet)
chan->addMessage(msg, MessageContext::Original);
});
}
@@ -22,4 +22,9 @@ void handleModerateMessage(
const lib::payload::channel_moderate::v2::Event &event,
const lib::payload::channel_moderate::v2::Clear &action);
void handleModerateMessage(
TwitchChannel *chan, const QDateTime &time,
const lib::payload::channel_moderate::v2::Event &event,
const lib::payload::channel_moderate::v2::Timeout &action);
} // namespace chatterino::eventsub
+5
View File
@@ -52,6 +52,11 @@ void addOrReplaceChannelTimeout(const Buf &buffer, MessagePtr message,
break;
}
if (s->flags.has(MessageFlag::EventSub))
{
continue; // TODO: implement stacking for eventsub
}
if (timeoutStackStyle == TimeoutStackStyle::DontStackBeyondUserMessage)
{
if (s->loginName == message->timeoutUser &&