mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Allow addMessage to override message flags
This commit is contained in:
parent
ad949dc1f6
commit
c6bca8e97b
4 changed files with 32 additions and 12 deletions
|
@ -58,7 +58,8 @@ LimitedQueueSnapshot<MessagePtr> Channel::getMessageSnapshot()
|
||||||
return this->messages_.getSnapshot();
|
return this->messages_.getSnapshot();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Channel::addMessage(MessagePtr message)
|
void Channel::addMessage(MessagePtr message,
|
||||||
|
boost::optional<MessageFlags> overridingFlags)
|
||||||
{
|
{
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
MessagePtr deleted;
|
MessagePtr deleted;
|
||||||
|
@ -78,7 +79,7 @@ void Channel::addMessage(MessagePtr message)
|
||||||
this->messageRemovedFromStart.invoke(deleted);
|
this->messageRemovedFromStart.invoke(deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->messageAppended.invoke(message);
|
this->messageAppended.invoke(message, overridingFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Channel::addOrReplaceTimeout(MessagePtr message)
|
void Channel::addOrReplaceTimeout(MessagePtr message)
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/CompletionModel.hpp"
|
#include "common/CompletionModel.hpp"
|
||||||
|
#include "common/FlagsEnum.hpp"
|
||||||
#include "messages/LimitedQueue.hpp"
|
#include "messages/LimitedQueue.hpp"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <boost/optional.hpp>
|
||||||
#include <pajlada/signals/signal.hpp>
|
#include <pajlada/signals/signal.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -13,6 +15,8 @@ namespace chatterino {
|
||||||
|
|
||||||
struct Message;
|
struct Message;
|
||||||
using MessagePtr = std::shared_ptr<const 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>
|
class Channel : public std::enable_shared_from_this<Channel>
|
||||||
{
|
{
|
||||||
|
@ -35,7 +39,8 @@ public:
|
||||||
sendMessageSignal;
|
sendMessageSignal;
|
||||||
|
|
||||||
pajlada::Signals::Signal<MessagePtr &> messageRemovedFromStart;
|
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<std::vector<MessagePtr> &> messagesAddedAtStart;
|
||||||
pajlada::Signals::Signal<size_t, MessagePtr &> messageReplaced;
|
pajlada::Signals::Signal<size_t, MessagePtr &> messageReplaced;
|
||||||
pajlada::Signals::NoArgSignal destroyed;
|
pajlada::Signals::NoArgSignal destroyed;
|
||||||
|
@ -46,7 +51,12 @@ public:
|
||||||
virtual bool isEmpty() const;
|
virtual bool isEmpty() const;
|
||||||
LimitedQueueSnapshot<MessagePtr> getMessageSnapshot();
|
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 addMessagesAtStart(std::vector<MessagePtr> &messages_);
|
||||||
void addOrReplaceTimeout(MessagePtr message);
|
void addOrReplaceTimeout(MessagePtr message);
|
||||||
void disableAllMessages();
|
void disableAllMessages();
|
||||||
|
|
|
@ -229,12 +229,15 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message)
|
||||||
app->twitch.server->mentionsChannel->addMessage(_message);
|
app->twitch.server->mentionsChannel->addMessage(_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
_message->flags.set(MessageFlag::DoNotTriggerNotification);
|
|
||||||
c->addMessage(_message);
|
c->addMessage(_message);
|
||||||
|
|
||||||
|
auto overrideFlags = boost::optional<MessageFlags>(_message->flags);
|
||||||
|
overrideFlags->set(MessageFlag::DoNotTriggerNotification);
|
||||||
|
|
||||||
if (getSettings()->inlineWhispers) {
|
if (getSettings()->inlineWhispers) {
|
||||||
app->twitch.server->forEachChannel([_message](ChannelPtr channel) {
|
app->twitch.server->forEachChannel(
|
||||||
channel->addMessage(_message); //
|
[_message, overrideFlags](ChannelPtr channel) {
|
||||||
|
channel->addMessage(_message, overrideFlags); //
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -400,10 +400,16 @@ void ChannelView::setChannel(ChannelPtr newChannel)
|
||||||
this->clearMessages();
|
this->clearMessages();
|
||||||
|
|
||||||
// on new message
|
// on new message
|
||||||
this->channelConnections_.push_back(
|
this->channelConnections_.push_back(newChannel->messageAppended.connect(
|
||||||
newChannel->messageAppended.connect([this](MessagePtr &message) {
|
[this](MessagePtr &message,
|
||||||
|
boost::optional<MessageFlags> overridingFlags) {
|
||||||
MessageLayoutPtr deleted;
|
MessageLayoutPtr deleted;
|
||||||
|
|
||||||
|
auto *messageFlags = &message->flags;
|
||||||
|
if (overridingFlags) {
|
||||||
|
messageFlags = overridingFlags.get_ptr();
|
||||||
|
}
|
||||||
|
|
||||||
auto messageRef = new MessageLayout(message);
|
auto messageRef = new MessageLayout(message);
|
||||||
|
|
||||||
if (this->lastMessageHasAlternateBackground_) {
|
if (this->lastMessageHasAlternateBackground_) {
|
||||||
|
@ -427,8 +433,8 @@ void ChannelView::setChannel(ChannelPtr newChannel)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!message->flags.has(MessageFlag::DoNotTriggerNotification)) {
|
if (!messageFlags->has(MessageFlag::DoNotTriggerNotification)) {
|
||||||
if (message->flags.has(MessageFlag::Highlighted)) {
|
if (messageFlags->has(MessageFlag::Highlighted)) {
|
||||||
this->tabHighlightRequested.invoke(
|
this->tabHighlightRequested.invoke(
|
||||||
HighlightState::Highlighted);
|
HighlightState::Highlighted);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue