From fa344deaf0258693e104f62c85bff0257d65ede1 Mon Sep 17 00:00:00 2001 From: fourtf Date: Tue, 23 Jan 2018 23:28:06 +0100 Subject: [PATCH] fixed #237 /mentions --- src/messages/message.hpp | 6 ++---- src/messages/messageparseargs.hpp | 1 - src/singletons/ircmanager.cpp | 7 ++++++- src/twitch/twitchchannel.cpp | 4 +++- src/twitch/twitchmessagebuilder.cpp | 30 ++++++++++++----------------- src/twitch/twitchmessagebuilder.hpp | 8 ++++---- src/widgets/helper/channelview.cpp | 3 +++ src/widgets/notebook.cpp | 3 +++ 8 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/messages/message.hpp b/src/messages/message.hpp index 1fa4b3ea0..ce6a6b691 100644 --- a/src/messages/message.hpp +++ b/src/messages/message.hpp @@ -11,10 +11,9 @@ namespace chatterino { namespace messages { -class Message; - -typedef std::shared_ptr MessagePtr; typedef uint16_t MessageFlagsType; +class Message; +typedef std::shared_ptr MessagePtr; class Message { @@ -86,6 +85,5 @@ private: std::vector> elements; }; - } // namespace messages } // namespace chatterino diff --git a/src/messages/messageparseargs.hpp b/src/messages/messageparseargs.hpp index f02f64415..d0d355d74 100644 --- a/src/messages/messageparseargs.hpp +++ b/src/messages/messageparseargs.hpp @@ -8,7 +8,6 @@ public: bool disablePingSoungs = false; bool isReceivedWhisper = false; bool isSentWhisper = false; - bool includeChannelName = false; }; } // namespace messages diff --git a/src/singletons/ircmanager.cpp b/src/singletons/ircmanager.cpp index a82f5e586..43f615632 100644 --- a/src/singletons/ircmanager.cpp +++ b/src/singletons/ircmanager.cpp @@ -256,7 +256,12 @@ void IrcManager::privateMessageReceived(Communi::IrcPrivateMessage *message) twitch::TwitchMessageBuilder builder(c.get(), message, args); if (!builder.isIgnored()) { - c->addMessage(builder.parse()); + messages::MessagePtr message = builder.build(); + if (message->hasFlags(messages::Message::Highlighted)) { + singletons::ChannelManager::getInstance().mentionsChannel->addMessage(message); + } + + c->addMessage(message); } } diff --git a/src/twitch/twitchchannel.cpp b/src/twitch/twitchchannel.cpp index ef998b88b..4377ed5d4 100644 --- a/src/twitch/twitchchannel.cpp +++ b/src/twitch/twitchchannel.cpp @@ -1,5 +1,7 @@ #include "twitchchannel.hpp" #include "debug/log.hpp" +#include "messages/message.hpp" +#include "singletons/channelmanager.hpp" #include "singletons/emotemanager.hpp" #include "singletons/ircmanager.hpp" #include "singletons/settingsmanager.hpp" @@ -239,7 +241,7 @@ void TwitchChannel::fetchRecentMessages() messages::MessageParseArgs args; twitch::TwitchMessageBuilder builder(channel, privMsg, args); if (!builder.isIgnored()) { - messages.push_back(builder.parse()); + messages.push_back(builder.build()); } } channel->addMessagesAtStart(messages); diff --git a/src/twitch/twitchmessagebuilder.cpp b/src/twitch/twitchmessagebuilder.cpp index e7474ab50..1c841ac5d 100644 --- a/src/twitch/twitchmessagebuilder.cpp +++ b/src/twitch/twitchmessagebuilder.cpp @@ -44,7 +44,7 @@ bool TwitchMessageBuilder::isIgnored() const return false; } -MessagePtr TwitchMessageBuilder::parse() +MessagePtr TwitchMessageBuilder::build() { singletons::SettingManager &settings = singletons::SettingManager::getInstance(); singletons::EmoteManager &emoteManager = singletons::EmoteManager::getInstance(); @@ -56,11 +56,14 @@ MessagePtr TwitchMessageBuilder::parse() // this->appendWord(Word(Resources::getInstance().badgeCollapsed, Word::Collapsed, QString(), // QString())); - // The timestamp is always appended to the builder - // Whether or not will be rendered is decided/checked later + // PARSING + this->parseMessageID(); - // Appends the correct timestamp if the message is a past message + this->parseRoomID(); + this->appendChannelName(); + + // timestamp bool isPastMsg = this->tags.contains("historical"); if (isPastMsg) { // This may be architecture dependent(datatype) @@ -71,20 +74,11 @@ MessagePtr TwitchMessageBuilder::parse() this->emplace(); } - this->parseMessageID(); - - this->parseRoomID(); - - // TIMESTAMP this->emplace(); - this->parseTwitchBadges(); + this->appendTwitchBadges(); - this->addChatterinoBadges(); - - if (this->args.includeChannelName) { - this->parseChannelName(); - } + this->appendChatterinoBadges(); this->appendUsername(); @@ -232,7 +226,7 @@ void TwitchMessageBuilder::parseRoomID() } } -void TwitchMessageBuilder::parseChannelName() +void TwitchMessageBuilder::appendChannelName() { QString channelName("#" + this->channel->name); Link link(Link::Url, this->channel->name + "\n" + this->messageID); @@ -492,7 +486,7 @@ bool TwitchMessageBuilder::tryAppendEmote(QString &emoteString) // fourtf: this is ugly // maybe put the individual badges into a map instead of this mess -void TwitchMessageBuilder::parseTwitchBadges() +void TwitchMessageBuilder::appendTwitchBadges() { singletons::ResourceManager &resourceManager = singletons::ResourceManager::getInstance(); const auto &channelResources = resourceManager.channels[this->roomID]; @@ -649,7 +643,7 @@ void TwitchMessageBuilder::parseTwitchBadges() } } -void TwitchMessageBuilder::addChatterinoBadges() +void TwitchMessageBuilder::appendChatterinoBadges() { auto &badges = singletons::ResourceManager::getInstance().chatterinoBadges; auto it = badges.find(this->userName.toStdString()); diff --git a/src/twitch/twitchmessagebuilder.hpp b/src/twitch/twitchmessagebuilder.hpp index 180130297..7b6ecde8f 100644 --- a/src/twitch/twitchmessagebuilder.hpp +++ b/src/twitch/twitchmessagebuilder.hpp @@ -39,7 +39,7 @@ public: QString userName; bool isIgnored() const; - messages::MessagePtr parse(); + messages::MessagePtr build(); private: QString roomID; @@ -48,7 +48,7 @@ private: void parseMessageID(); void parseRoomID(); - void parseChannelName(); + void appendChannelName(); void parseUsername(); void appendUsername(); void parseHighlights(); @@ -57,8 +57,8 @@ private: std::vector> &vec); bool tryAppendEmote(QString &emoteString); - void parseTwitchBadges(); - void addChatterinoBadges(); + void appendTwitchBadges(); + void appendChatterinoBadges(); bool tryParseCheermote(const QString &string); }; diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 85fa42069..866c2a51c 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -456,6 +456,9 @@ messages::MessageElement::Flags ChannelView::getFlags() const if (split->getModerationMode()) { flags = (MessageElement::Flags)(flags | MessageElement::ModeratorTools); } + if (this->channel == singletons::ChannelManager::getInstance().mentionsChannel) { + flags = (MessageElement::Flags)(flags | MessageElement::ChannelName); + } } return flags; diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index 0f026a15a..e9b2248f1 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -130,6 +130,9 @@ void Notebook::select(SplitContainer *page) if (this->selectedPage != nullptr) { this->selectedPage->setHidden(true); this->selectedPage->getTab()->setSelected(false); + for (auto split : this->selectedPage->getSplits()) { + split->updateLastReadMessage(); + } } this->selectedPage = page;