mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
We now handle some write-connection messages like if users have been banned/timed out successfully by the user, or unbanned etc
This commit is contained in:
parent
357515ab39
commit
3cfb00d61f
|
@ -45,6 +45,9 @@ IrcManager::IrcManager(ChannelManager &_channelManager, Resources &_resources,
|
|||
this->writeConnection.reset(new Communi::IrcConnection);
|
||||
this->writeConnection->moveToThread(QCoreApplication::instance()->thread());
|
||||
|
||||
QObject::connect(this->writeConnection.get(), &Communi::IrcConnection::messageReceived, this,
|
||||
&IrcManager::writeConnectionMessageReceived);
|
||||
|
||||
this->readConnection.reset(new Communi::IrcConnection);
|
||||
this->readConnection->moveToThread(QCoreApplication::instance()->thread());
|
||||
|
||||
|
@ -106,6 +109,12 @@ void IrcManager::initializeConnection(const std::unique_ptr<Communi::IrcConnecti
|
|||
Communi::IrcCommand::createCapability("REQ", "twitch.tv/membership"));
|
||||
connection->sendCommand(Communi::IrcCommand::createCapability("REQ", "twitch.tv/commands"));
|
||||
connection->sendCommand(Communi::IrcCommand::createCapability("REQ", "twitch.tv/tags"));
|
||||
} else {
|
||||
connection->sendCommand(Communi::IrcCommand::createCapability("REQ", "twitch.tv/tags"));
|
||||
|
||||
connection->sendCommand(
|
||||
Communi::IrcCommand::createCapability("REQ", "twitch.tv/membership"));
|
||||
connection->sendCommand(Communi::IrcCommand::createCapability("REQ", "twitch.tv/commands"));
|
||||
}
|
||||
|
||||
connection->setHost("irc.chat.twitch.tv");
|
||||
|
@ -247,6 +256,16 @@ void IrcManager::messageReceived(Communi::IrcMessage *message)
|
|||
}
|
||||
}
|
||||
|
||||
void IrcManager::writeConnectionMessageReceived(Communi::IrcMessage *message)
|
||||
{
|
||||
switch (message->type()) {
|
||||
case Communi::IrcMessage::Type::Notice: {
|
||||
this->handleWriteConnectionNoticeMessage(
|
||||
static_cast<Communi::IrcNoticeMessage *>(message));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void IrcManager::handleRoomStateMessage(Communi::IrcMessage *message)
|
||||
{
|
||||
const auto &tags = message->tags();
|
||||
|
@ -440,6 +459,40 @@ void IrcManager::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
|||
c->addMessage(msg);
|
||||
}
|
||||
|
||||
void IrcManager::handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message)
|
||||
{
|
||||
auto rawChannelName = message->target();
|
||||
|
||||
assert(rawChannelName.length() >= 2);
|
||||
|
||||
auto trimmedChannelName = rawChannelName.mid(1);
|
||||
|
||||
auto c = this->channelManager.getTwitchChannel(trimmedChannelName);
|
||||
|
||||
if (!c) {
|
||||
debug::Log("[IrcManager:handleNoticeMessage] Channel {} not found in channel manager",
|
||||
trimmedChannelName);
|
||||
return;
|
||||
}
|
||||
|
||||
QVariant v = message->tag("msg-id");
|
||||
if (!v.isValid()) {
|
||||
return;
|
||||
}
|
||||
QString msg_id = v.toString();
|
||||
|
||||
static QList<QString> idsToSkip = {"timeout_success", "ban_success"};
|
||||
|
||||
if (idsToSkip.contains(msg_id)) {
|
||||
// Already handled in the read-connection
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<Message> msg(Message::createSystemMessage(message->content()));
|
||||
|
||||
c->addMessage(msg);
|
||||
}
|
||||
|
||||
void IrcManager::onConnected()
|
||||
{
|
||||
std::shared_ptr<Message> msg(Message::createSystemMessage("connected to chat"));
|
||||
|
|
|
@ -79,6 +79,8 @@ private:
|
|||
void privateMessageReceived(Communi::IrcPrivateMessage *message);
|
||||
void messageReceived(Communi::IrcMessage *message);
|
||||
|
||||
void writeConnectionMessageReceived(Communi::IrcMessage *message);
|
||||
|
||||
void handleRoomStateMessage(Communi::IrcMessage *message);
|
||||
void handleClearChatMessage(Communi::IrcMessage *message);
|
||||
void handleUserStateMessage(Communi::IrcMessage *message);
|
||||
|
@ -86,6 +88,7 @@ private:
|
|||
void handleUserNoticeMessage(Communi::IrcMessage *message);
|
||||
void handleModeMessage(Communi::IrcMessage *message);
|
||||
void handleNoticeMessage(Communi::IrcNoticeMessage *message);
|
||||
void handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message);
|
||||
|
||||
void onConnected();
|
||||
void onDisconnected();
|
||||
|
|
Loading…
Reference in a new issue