From c6bca8e97b85c31705910b82467988cfe96de0e6 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Fri, 5 Oct 2018 21:33:01 +0000 Subject: [PATCH] Allow addMessage to override message flags --- src/common/Channel.cpp | 5 +++-- src/common/Channel.hpp | 14 ++++++++++++-- src/providers/twitch/IrcMessageHandler.cpp | 11 +++++++---- src/widgets/helper/ChannelView.cpp | 14 ++++++++++---- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index ac1d6ea56..d73213954 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -58,7 +58,8 @@ LimitedQueueSnapshot Channel::getMessageSnapshot() return this->messages_.getSnapshot(); } -void Channel::addMessage(MessagePtr message) +void Channel::addMessage(MessagePtr message, + boost::optional overridingFlags) { auto app = getApp(); MessagePtr deleted; @@ -78,7 +79,7 @@ void Channel::addMessage(MessagePtr message) this->messageRemovedFromStart.invoke(deleted); } - this->messageAppended.invoke(message); + this->messageAppended.invoke(message, overridingFlags); } void Channel::addOrReplaceTimeout(MessagePtr message) diff --git a/src/common/Channel.hpp b/src/common/Channel.hpp index f265f4b70..12382561f 100644 --- a/src/common/Channel.hpp +++ b/src/common/Channel.hpp @@ -1,10 +1,12 @@ #pragma once #include "common/CompletionModel.hpp" +#include "common/FlagsEnum.hpp" #include "messages/LimitedQueue.hpp" #include #include +#include #include #include @@ -13,6 +15,8 @@ namespace chatterino { struct Message; using MessagePtr = std::shared_ptr; +enum class MessageFlag : uint16_t; +using MessageFlags = FlagsEnum; class Channel : public std::enable_shared_from_this { @@ -35,7 +39,8 @@ public: sendMessageSignal; pajlada::Signals::Signal messageRemovedFromStart; - pajlada::Signals::Signal messageAppended; + pajlada::Signals::Signal> + messageAppended; pajlada::Signals::Signal &> messagesAddedAtStart; pajlada::Signals::Signal messageReplaced; pajlada::Signals::NoArgSignal destroyed; @@ -46,7 +51,12 @@ public: virtual bool isEmpty() const; LimitedQueueSnapshot getMessageSnapshot(); - void addMessage(MessagePtr message); + // overridingFlags can be filled in with flags that should be used instead + // of the message's flags. This is useful in case a flag is specific to a + // type of split + void addMessage( + MessagePtr message, + boost::optional overridingFlags = boost::none); void addMessagesAtStart(std::vector &messages_); void addOrReplaceTimeout(MessagePtr message); void disableAllMessages(); diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index adbc3c717..3497d930a 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -229,13 +229,16 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message) app->twitch.server->mentionsChannel->addMessage(_message); } - _message->flags.set(MessageFlag::DoNotTriggerNotification); c->addMessage(_message); + auto overrideFlags = boost::optional(_message->flags); + overrideFlags->set(MessageFlag::DoNotTriggerNotification); + if (getSettings()->inlineWhispers) { - app->twitch.server->forEachChannel([_message](ChannelPtr channel) { - channel->addMessage(_message); // - }); + app->twitch.server->forEachChannel( + [_message, overrideFlags](ChannelPtr channel) { + channel->addMessage(_message, overrideFlags); // + }); } } } diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 398ef7ee8..8c63358ea 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -400,10 +400,16 @@ void ChannelView::setChannel(ChannelPtr newChannel) this->clearMessages(); // on new message - this->channelConnections_.push_back( - newChannel->messageAppended.connect([this](MessagePtr &message) { + this->channelConnections_.push_back(newChannel->messageAppended.connect( + [this](MessagePtr &message, + boost::optional overridingFlags) { MessageLayoutPtr deleted; + auto *messageFlags = &message->flags; + if (overridingFlags) { + messageFlags = overridingFlags.get_ptr(); + } + auto messageRef = new MessageLayout(message); if (this->lastMessageHasAlternateBackground_) { @@ -427,8 +433,8 @@ void ChannelView::setChannel(ChannelPtr newChannel) // } } - if (!message->flags.has(MessageFlag::DoNotTriggerNotification)) { - if (message->flags.has(MessageFlag::Highlighted)) { + if (!messageFlags->has(MessageFlag::DoNotTriggerNotification)) { + if (messageFlags->has(MessageFlag::Highlighted)) { this->tabHighlightRequested.invoke( HighlightState::Highlighted); } else {