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

View file

@ -225,6 +225,8 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selectio
QColor backgroundColor; QColor backgroundColor;
if (this->message_->flags & Message::Highlighted) { if (this->message_->flags & Message::Highlighted) {
backgroundColor = app->themes->messages.backgrounds.highlighted; backgroundColor = app->themes->messages.backgrounds.highlighted;
} else if (this->message_->flags & Message::Subscription) {
backgroundColor = app->themes->messages.backgrounds.subscription;
} else if (app->settings->alternateMessageBackground.getValue() && } else if (app->settings->alternateMessageBackground.getValue() &&
this->flags & MessageLayout::AlternateBackground) { this->flags & MessageLayout::AlternateBackground) {
backgroundColor = app->themes->messages.backgrounds.alternate; backgroundColor = app->themes->messages.backgrounds.alternate;

View file

@ -21,6 +21,8 @@ SBHighlight Message::getScrollBarHighlight() const
{ {
if (this->flags & Message::Highlighted) { if (this->flags & Message::Highlighted) {
return SBHighlight(SBHighlight::Highlight); return SBHighlight(SBHighlight::Highlight);
} else if (this->flags & Message::Subscription) {
return SBHighlight(SBHighlight::Subscription);
} }
return SBHighlight(); return SBHighlight();
} }
@ -39,6 +41,17 @@ MessagePtr Message::createSystemMessage(const QString &text)
return message; return message;
} }
MessagePtr Message::createMessage(const QString &text)
{
MessagePtr message(new Message);
message->addElement(new TimestampElement(QTime::currentTime()));
message->addElement(new TextElement(text, MessageElement::Text, MessageColor::Text));
message->searchText = text;
return message;
}
MessagePtr Message::createTimeoutMessage(const QString &username, const QString &durationInSeconds, MessagePtr Message::createTimeoutMessage(const QString &username, const QString &durationInSeconds,
const QString &reason, bool multipleTimes) const QString &reason, bool multipleTimes)
{ {
@ -64,7 +77,7 @@ MessagePtr Message::createTimeoutMessage(const QString &username, const QString
if (reason.length() > 0) { if (reason.length() > 0) {
text.append(": \""); text.append(": \"");
text.append(util::ParseTagString(reason)); text.append(util::parseTagString(reason));
text.append("\""); text.append("\"");
} }
text.append("."); text.append(".");

View file

@ -41,6 +41,7 @@ struct Message {
DisconnectedMessage = (1 << 8), DisconnectedMessage = (1 << 8),
Untimeout = (1 << 9), Untimeout = (1 << 9),
PubSub = (1 << 10), PubSub = (1 << 10),
Subscription = (1 << 11),
}; };
util::FlagsEnum<MessageFlags> flags; util::FlagsEnum<MessageFlags> flags;
@ -66,6 +67,7 @@ private:
public: public:
static std::shared_ptr<Message> createSystemMessage(const QString &text); static std::shared_ptr<Message> createSystemMessage(const QString &text);
static std::shared_ptr<Message> createMessage(const QString &text);
static std::shared_ptr<Message> createTimeoutMessage(const QString &username, static std::shared_ptr<Message> createTimeoutMessage(const QString &username,
const QString &durationInSeconds, const QString &durationInSeconds,

View file

@ -7,6 +7,7 @@ struct MessageParseArgs {
bool disablePingSounds = false; bool disablePingSounds = false;
bool isReceivedWhisper = false; bool isReceivedWhisper = false;
bool isSentWhisper = false; bool isSentWhisper = false;
bool trimSubscriberUsername = false;
}; };
} // namespace messages } // namespace messages

View file

@ -33,7 +33,7 @@ public:
// signals // signals
pajlada::Signals::NoArgSignal connected; pajlada::Signals::NoArgSignal connected;
pajlada::Signals::NoArgSignal disconnected; pajlada::Signals::NoArgSignal disconnected;
pajlada::Signals::Signal<Communi::IrcPrivateMessage *> onPrivateMessage; // pajlada::Signals::Signal<Communi::IrcPrivateMessage *> onPrivateMessage;
void addFakeMessage(const QString &data); void addFakeMessage(const QString &data);

View file

@ -1,6 +1,7 @@
#include "ircmessagehandler.hpp" #include "ircmessagehandler.hpp"
#include "application.hpp" #include "application.hpp"
#include "controllers/highlights/highlightcontroller.hpp"
#include "debug/log.hpp" #include "debug/log.hpp"
#include "messages/limitedqueue.hpp" #include "messages/limitedqueue.hpp"
#include "messages/message.hpp" #include "messages/message.hpp"
@ -10,6 +11,9 @@
#include "providers/twitch/twitchserver.hpp" #include "providers/twitch/twitchserver.hpp"
#include "singletons/resourcemanager.hpp" #include "singletons/resourcemanager.hpp"
#include "singletons/windowmanager.hpp" #include "singletons/windowmanager.hpp"
#include "util/irchelpers.hpp"
#include <IrcMessage>
using namespace chatterino::singletons; using namespace chatterino::singletons;
using namespace chatterino::messages; using namespace chatterino::messages;
@ -24,6 +28,49 @@ IrcMessageHandler &IrcMessageHandler::getInstance()
return instance; 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) void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
{ {
const auto &tags = message->tags(); 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) void IrcMessageHandler::handleModeMessage(Communi::IrcMessage *message)

View file

@ -6,6 +6,8 @@ namespace chatterino {
namespace providers { namespace providers {
namespace twitch { namespace twitch {
class TwitchServer;
class IrcMessageHandler class IrcMessageHandler
{ {
IrcMessageHandler() = default; IrcMessageHandler() = default;
@ -13,17 +15,23 @@ class IrcMessageHandler
public: public:
static IrcMessageHandler &getInstance(); static IrcMessageHandler &getInstance();
void handlePrivMessage(Communi::IrcPrivateMessage *message, TwitchServer &server);
void handleRoomStateMessage(Communi::IrcMessage *message); void handleRoomStateMessage(Communi::IrcMessage *message);
void handleClearChatMessage(Communi::IrcMessage *message); void handleClearChatMessage(Communi::IrcMessage *message);
void handleUserStateMessage(Communi::IrcMessage *message); void handleUserStateMessage(Communi::IrcMessage *message);
void handleWhisperMessage(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 handleModeMessage(Communi::IrcMessage *message);
void handleNoticeMessage(Communi::IrcNoticeMessage *message); void handleNoticeMessage(Communi::IrcNoticeMessage *message);
void handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message); void handleWriteConnectionNoticeMessage(Communi::IrcNoticeMessage *message);
void handleJoinMessage(Communi::IrcMessage *message); void handleJoinMessage(Communi::IrcMessage *message);
void handlePartMessage(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 } // namespace twitch

View file

@ -292,6 +292,21 @@ void TwitchMessageBuilder::parseUsername()
this->userName = this->tags.value(QLatin1String("login")).toString(); 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; this->message->loginName = this->userName;
} }

View file

@ -77,31 +77,7 @@ std::shared_ptr<Channel> TwitchServer::createChannel(const QString &channelName)
void TwitchServer::privateMessageReceived(IrcPrivateMessage *message) void TwitchServer::privateMessageReceived(IrcPrivateMessage *message)
{ {
QString channelName; IrcMessageHandler::getInstance().handlePrivMessage(message, *this);
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);
}
} }
void TwitchServer::messageReceived(IrcMessage *message) void TwitchServer::messageReceived(IrcMessage *message)
@ -125,7 +101,7 @@ void TwitchServer::messageReceived(IrcMessage *message)
} else if (command == "WHISPER") { } else if (command == "WHISPER") {
handler.handleWhisperMessage(message); handler.handleWhisperMessage(message);
} else if (command == "USERNOTICE") { } else if (command == "USERNOTICE") {
handler.handleUserNoticeMessage(message); handler.handleUserNoticeMessage(message, *this);
} else if (command == "MODE") { } else if (command == "MODE") {
handler.handleModeMessage(message); handler.handleModeMessage(message);
} else if (command == "NOTICE") { } else if (command == "NOTICE") {

View file

@ -117,6 +117,7 @@ void ThemeManager::actuallyUpdate(double hue, double multiplier)
// scrollbar // scrollbar
this->scrollbars.highlights.highlight = QColor("#ee6166"); this->scrollbars.highlights.highlight = QColor("#ee6166");
this->scrollbars.highlights.subscription = QColor("#C466FF");
// this->tabs.newMessage = { // this->tabs.newMessage = {
// fg, // fg,
@ -171,7 +172,10 @@ void ThemeManager::actuallyUpdate(double hue, double multiplier)
this->messages.backgrounds.regular = splits.background; this->messages.backgrounds.regular = splits.background;
this->messages.backgrounds.alternate = getColor(0, sat, 0.93); this->messages.backgrounds.alternate = getColor(0, sat, 0.93);
this->messages.backgrounds.highlighted = this->messages.backgrounds.highlighted =
blendColors(themeColor, this->messages.backgrounds.regular, 0.8); blendColors(themeColor, this->messages.backgrounds.regular, 0.6);
this->messages.backgrounds.subscription =
blendColors(QColor("#C466FF"), this->messages.backgrounds.regular, 0.7);
// this->messages.backgrounds.resub // this->messages.backgrounds.resub
// this->messages.backgrounds.whisper // this->messages.backgrounds.whisper
this->messages.disabled = getColor(0, sat, 1, 0.6); this->messages.disabled = getColor(0, sat, 1, 0.6);
@ -180,7 +184,7 @@ void ThemeManager::actuallyUpdate(double hue, double multiplier)
// Scrollbar // Scrollbar
this->scrollbars.background = splits.background; this->scrollbars.background = splits.background;
this->scrollbars.background.setAlphaF(qreal(0.4)); this->scrollbars.background.setAlphaF(qreal(0.2));
this->scrollbars.thumb = getColor(0, sat, 0.80); this->scrollbars.thumb = getColor(0, sat, 0.80);
this->scrollbars.thumbSelected = getColor(0, sat, 0.7); this->scrollbars.thumbSelected = getColor(0, sat, 0.7);

View file

@ -98,7 +98,7 @@ public:
QColor regular; QColor regular;
QColor alternate; QColor alternate;
QColor highlighted; QColor highlighted;
// QColor resub; QColor subscription;
// QColor whisper; // QColor whisper;
} backgrounds; } backgrounds;
@ -115,6 +115,7 @@ public:
QColor thumbSelected; QColor thumbSelected;
struct { struct {
QColor highlight; QColor highlight;
QColor subscription;
} highlights; } highlights;
} scrollbars; } scrollbars;

View file

@ -5,7 +5,7 @@
namespace chatterino { namespace chatterino {
namespace util { namespace util {
inline QString ParseTagString(const QString &input) inline QString parseTagString(const QString &input)
{ {
QString output = input; QString output = input;
output.detach(); output.detach();

View file

@ -9,7 +9,7 @@ class ScrollbarHighlight
{ {
public: public:
enum Style : char { None, Default, Line }; enum Style : char { None, Default, Line };
enum Color : char { Highlight }; enum Color : char { Highlight, Subscription };
ScrollbarHighlight(); ScrollbarHighlight();
ScrollbarHighlight(Color _color, Style _style = Default); ScrollbarHighlight(Color _color, Style _style = Default);

View file

@ -242,6 +242,8 @@ void Scrollbar::paintEvent(QPaintEvent *)
switch (highlight.getColor()) { switch (highlight.getColor()) {
case ScrollbarHighlight::Highlight: case ScrollbarHighlight::Highlight:
return app->themes->scrollbars.highlights.highlight; return app->themes->scrollbars.highlights.highlight;
case ScrollbarHighlight::Subscription:
return app->themes->scrollbars.highlights.subscription;
} }
return QColor(); return QColor();
}(); }();