fixed resub messages

This commit is contained in:
fourtf
2018-06-04 12:23:23 +02:00
parent 04b7cc5ce8
commit 4a2709cbc3
14 changed files with 141 additions and 36 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ public:
// signals
pajlada::Signals::NoArgSignal connected;
pajlada::Signals::NoArgSignal disconnected;
pajlada::Signals::Signal<Communi::IrcPrivateMessage *> onPrivateMessage;
// pajlada::Signals::Signal<Communi::IrcPrivateMessage *> onPrivateMessage;
void addFakeMessage(const QString &data);
+83 -2
View File
@@ -1,6 +1,7 @@
#include "ircmessagehandler.hpp"
#include "application.hpp"
#include "controllers/highlights/highlightcontroller.hpp"
#include "debug/log.hpp"
#include "messages/limitedqueue.hpp"
#include "messages/message.hpp"
@@ -10,6 +11,9 @@
#include "providers/twitch/twitchserver.hpp"
#include "singletons/resourcemanager.hpp"
#include "singletons/windowmanager.hpp"
#include "util/irchelpers.hpp"
#include <IrcMessage>
using namespace chatterino::singletons;
using namespace chatterino::messages;
@@ -24,6 +28,49 @@ IrcMessageHandler &IrcMessageHandler::getInstance()
return instance;
}
void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message, TwitchServer &server)
{
this->addMessage(message, message->target(), message->content(), server, false);
}
void IrcMessageHandler::addMessage(Communi::IrcMessage *message, const QString &target,
const QString &content, TwitchServer &server, bool isSub)
{
QString channelName;
if (!trimChannelName(target, channelName)) {
return;
}
auto chan = server.getChannelOrEmpty(channelName);
if (chan->isEmpty()) {
return;
}
messages::MessageParseArgs args;
if (isSub) {
args.trimSubscriberUsername = true;
}
TwitchMessageBuilder builder(chan.get(), message, content, args);
if (isSub || !builder.isIgnored()) {
messages::MessagePtr msg = builder.build();
if (isSub) {
msg->flags |= messages::Message::Subscription;
msg->flags &= ~messages::Message::Highlighted;
} else {
if (msg->flags & messages::Message::Subscription) {
server.mentionsChannel->addMessage(msg);
getApp()->highlights->addHighlight(msg);
}
}
chan->addMessage(msg);
}
}
void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
{
const auto &tags = message->tags();
@@ -178,9 +225,43 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message)
}
}
void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message)
void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message, TwitchServer &server)
{
// do nothing
auto data = message->toData();
static QRegularExpression findMessage(" USERNOTICE (#\\w+) :(.+)$");
auto match = findMessage.match(data);
auto target = match.captured(1);
if (match.hasMatch()) {
this->addMessage(message, target, match.captured(2), server, true);
}
auto tags = message->tags();
auto it = tags.find("system-msg");
if (it != tags.end()) {
auto newMessage =
messages::Message::createSystemMessage(util::parseTagString(it.value().toString()));
newMessage->flags |= messages::Message::Subscription;
QString channelName;
if (message->parameters().size() < 1) {
return;
}
if (!trimChannelName(message->parameter(0), channelName)) {
return;
}
auto chan = server.getChannelOrEmpty(channelName);
if (!chan->isEmpty()) {
chan->addMessage(newMessage);
}
}
}
void IrcMessageHandler::handleModeMessage(Communi::IrcMessage *message)
+9 -1
View File
@@ -6,6 +6,8 @@ namespace chatterino {
namespace providers {
namespace twitch {
class TwitchServer;
class IrcMessageHandler
{
IrcMessageHandler() = default;
@@ -13,17 +15,23 @@ class IrcMessageHandler
public:
static IrcMessageHandler &getInstance();
void handlePrivMessage(Communi::IrcPrivateMessage *message, TwitchServer &server);
void handleRoomStateMessage(Communi::IrcMessage *message);
void handleClearChatMessage(Communi::IrcMessage *message);
void handleUserStateMessage(Communi::IrcMessage *message);
void handleWhisperMessage(Communi::IrcMessage *message);
void handleUserNoticeMessage(Communi::IrcMessage *message);
void handleUserNoticeMessage(Communi::IrcMessage *message, TwitchServer &server);
void handleModeMessage(Communi::IrcMessage *message);
void handleNoticeMessage(Communi::IrcNoticeMessage *message);
void handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message);
void handleJoinMessage(Communi::IrcMessage *message);
void handlePartMessage(Communi::IrcMessage *message);
private:
void addMessage(Communi::IrcMessage *message, const QString &target, const QString &content,
TwitchServer &server, bool isResub);
};
} // namespace twitch
@@ -292,6 +292,21 @@ void TwitchMessageBuilder::parseUsername()
this->userName = this->tags.value(QLatin1String("login")).toString();
}
if (this->args.trimSubscriberUsername) {
static QRegularExpression fixName("^tmi.twitch.tv\\((\\w+)\\)$");
auto match = fixName.match(this->userName);
if (match.hasMatch()) {
this->userName = match.captured(1);
}
}
// display name
// auto displayNameVariant = this->tags.value("display-name");
// if (displayNameVariant.isValid()) {
// this->userName = displayNameVariant.toString() + " (" + this->userName + ")";
// }
this->message->loginName = this->userName;
}
+2 -26
View File
@@ -77,31 +77,7 @@ std::shared_ptr<Channel> TwitchServer::createChannel(const QString &channelName)
void TwitchServer::privateMessageReceived(IrcPrivateMessage *message)
{
QString channelName;
if (!trimChannelName(message->target(), channelName)) {
return;
}
this->onPrivateMessage.invoke(message);
auto chan = this->getChannelOrEmpty(channelName);
if (chan->isEmpty()) {
return;
}
messages::MessageParseArgs args;
TwitchMessageBuilder builder(chan.get(), message, args);
if (!builder.isIgnored()) {
messages::MessagePtr msg = builder.build();
if (msg->flags & messages::Message::Highlighted) {
this->mentionsChannel->addMessage(msg);
getApp()->highlights->addHighlight(msg);
}
chan->addMessage(msg);
}
IrcMessageHandler::getInstance().handlePrivMessage(message, *this);
}
void TwitchServer::messageReceived(IrcMessage *message)
@@ -125,7 +101,7 @@ void TwitchServer::messageReceived(IrcMessage *message)
} else if (command == "WHISPER") {
handler.handleWhisperMessage(message);
} else if (command == "USERNOTICE") {
handler.handleUserNoticeMessage(message);
handler.handleUserNoticeMessage(message, *this);
} else if (command == "MODE") {
handler.handleModeMessage(message);
} else if (command == "NOTICE") {