feat(eventsub): implement clearchat (#5981)
This commit is contained in:
@@ -502,8 +502,6 @@ Updates &Application::getUpdates()
|
||||
|
||||
ITwitchIrcServer *Application::getTwitch()
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
return this->twitch.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -434,6 +434,8 @@ set(SOURCE_FILES
|
||||
providers/twitch/eventsub/Controller.hpp
|
||||
providers/twitch/eventsub/MessageBuilder.cpp
|
||||
providers/twitch/eventsub/MessageBuilder.hpp
|
||||
providers/twitch/eventsub/MessageHandlers.cpp
|
||||
providers/twitch/eventsub/MessageHandlers.hpp
|
||||
providers/twitch/eventsub/SubscriptionHandle.cpp
|
||||
providers/twitch/eventsub/SubscriptionHandle.hpp
|
||||
providers/twitch/eventsub/SubscriptionRequest.cpp
|
||||
|
||||
@@ -1303,6 +1303,8 @@ const IndirectChannel &TwitchIrcServer::getWatchingChannel() const
|
||||
|
||||
void TwitchIrcServer::setWatchingChannel(ChannelPtr newWatchingChannel)
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
this->watchingChannel.reset(newWatchingChannel);
|
||||
}
|
||||
|
||||
@@ -1333,6 +1335,8 @@ QString TwitchIrcServer::getLastUserThatWhisperedMe() const
|
||||
|
||||
void TwitchIrcServer::setLastUserThatWhisperedMe(const QString &user)
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
this->lastUserThatWhisperedMe.set(user);
|
||||
}
|
||||
|
||||
@@ -1451,6 +1455,8 @@ void TwitchIrcServer::markChannelsConnected()
|
||||
|
||||
void TwitchIrcServer::addFakeMessage(const QString &data)
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
auto *fakeMessage = Communi::IrcMessage::fromData(
|
||||
data.toUtf8(), this->readConnection_.get());
|
||||
|
||||
@@ -1502,6 +1508,8 @@ void TwitchIrcServer::forEachChannel(std::function<void(ChannelPtr)> func)
|
||||
|
||||
void TwitchIrcServer::connect()
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
this->disconnect();
|
||||
|
||||
this->initializeConnection(this->writeConnection_.get(),
|
||||
|
||||
@@ -6,9 +6,12 @@
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/twitch/eventsub/MessageBuilder.hpp"
|
||||
#include "providers/twitch/eventsub/MessageHandlers.hpp"
|
||||
#include "providers/twitch/PubSubActions.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/PostToThread.hpp"
|
||||
|
||||
#include <boost/json.hpp>
|
||||
@@ -23,15 +26,24 @@ namespace {
|
||||
using namespace chatterino;
|
||||
using namespace chatterino::eventsub;
|
||||
|
||||
namespace channel_moderate = lib::payload::channel_moderate::v2;
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
const auto &LOG = chatterinoTwitchEventSub;
|
||||
|
||||
template <typename Action>
|
||||
concept CanMakeModMessage =
|
||||
requires(EventSubMessageBuilder &builder,
|
||||
const lib::payload::channel_moderate::v2::Event &event,
|
||||
concept CanMakeModMessage = requires(
|
||||
EventSubMessageBuilder &builder, const channel_moderate::Event &event,
|
||||
const std::remove_cvref_t<Action> &action) {
|
||||
makeModerateMessage(builder, event, action);
|
||||
};
|
||||
|
||||
template <typename Action>
|
||||
concept CanHandleModMessage =
|
||||
requires(TwitchChannel *channel, const QDateTime &time,
|
||||
const channel_moderate::Event &event,
|
||||
const std::remove_cvref_t<Action> &action) {
|
||||
makeModerateMessage(builder, event, action);
|
||||
handleModerateMessage(channel, time, event, action);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -199,6 +211,11 @@ void Connection::onChannelModerate(
|
||||
channel->addMessage(msg, MessageContext::Original);
|
||||
});
|
||||
}
|
||||
|
||||
if constexpr (CanHandleModMessage<Action>)
|
||||
{
|
||||
handleModerateMessage(channel, now, payload.event, action);
|
||||
}
|
||||
},
|
||||
payload.event.action);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "providers/twitch/eventsub/MessageHandlers.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "providers/twitch/TwitchChannel.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/PostToThread.hpp"
|
||||
|
||||
namespace chatterino::eventsub {
|
||||
|
||||
void handleModerateMessage(
|
||||
TwitchChannel *chan, const QDateTime &time,
|
||||
const lib::payload::channel_moderate::v2::Event &event,
|
||||
const lib::payload::channel_moderate::v2::Clear & /*action*/)
|
||||
{
|
||||
runInGuiThread([chan, actor{event.moderatorUserLogin.qt()}, time] {
|
||||
chan->addOrReplaceClearChat(
|
||||
MessageBuilder::makeClearChatMessage(time, actor), 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace chatterino::eventsub
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "twitch-eventsub-ws/payloads/channel-moderate-v2.hpp"
|
||||
|
||||
class QDateTime;
|
||||
|
||||
namespace chatterino {
|
||||
class TwitchChannel;
|
||||
} // namespace chatterino
|
||||
|
||||
namespace chatterino::eventsub {
|
||||
|
||||
void handleModerateMessage(
|
||||
TwitchChannel *chan, const QDateTime &time,
|
||||
const lib::payload::channel_moderate::v2::Event &event,
|
||||
const lib::payload::channel_moderate::v2::Clear &action);
|
||||
|
||||
} // namespace chatterino::eventsub
|
||||
Reference in New Issue
Block a user