Allow addMessage to override message flags

This commit is contained in:
Rasmus Karlsson 2018-10-05 21:33:01 +00:00
parent ad949dc1f6
commit c6bca8e97b
4 changed files with 32 additions and 12 deletions

View file

@ -58,7 +58,8 @@ LimitedQueueSnapshot<MessagePtr> Channel::getMessageSnapshot()
return this->messages_.getSnapshot();
}
void Channel::addMessage(MessagePtr message)
void Channel::addMessage(MessagePtr message,
boost::optional<MessageFlags> 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)

View file

@ -1,10 +1,12 @@
#pragma once
#include "common/CompletionModel.hpp"
#include "common/FlagsEnum.hpp"
#include "messages/LimitedQueue.hpp"
#include <QString>
#include <QTimer>
#include <boost/optional.hpp>
#include <pajlada/signals/signal.hpp>
#include <memory>
@ -13,6 +15,8 @@ namespace chatterino {
struct Message;
using MessagePtr = std::shared_ptr<const Message>;
enum class MessageFlag : uint16_t;
using MessageFlags = FlagsEnum<MessageFlag>;
class Channel : public std::enable_shared_from_this<Channel>
{
@ -35,7 +39,8 @@ public:
sendMessageSignal;
pajlada::Signals::Signal<MessagePtr &> messageRemovedFromStart;
pajlada::Signals::Signal<MessagePtr &> messageAppended;
pajlada::Signals::Signal<MessagePtr &, boost::optional<MessageFlags>>
messageAppended;
pajlada::Signals::Signal<std::vector<MessagePtr> &> messagesAddedAtStart;
pajlada::Signals::Signal<size_t, MessagePtr &> messageReplaced;
pajlada::Signals::NoArgSignal destroyed;
@ -46,7 +51,12 @@ public:
virtual bool isEmpty() const;
LimitedQueueSnapshot<MessagePtr> 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<MessageFlags> overridingFlags = boost::none);
void addMessagesAtStart(std::vector<MessagePtr> &messages_);
void addOrReplaceTimeout(MessagePtr message);
void disableAllMessages();

View file

@ -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<MessageFlags>(_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); //
});
}
}
}

View file

@ -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<MessageFlags> 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 {