refactor: deduplicate IRC parsing (#5678)
This commit is contained in:
+23
-3
@@ -3,7 +3,9 @@
|
||||
#include "Application.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageBuilder.hpp"
|
||||
#include "messages/MessageSimilarity.hpp"
|
||||
#include "providers/twitch/IrcMessageHandler.hpp"
|
||||
#include "providers/twitch/TwitchIrcServer.hpp"
|
||||
#include "singletons/Emotes.hpp"
|
||||
#include "singletons/Logging.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
@@ -121,10 +123,10 @@ void Channel::addSystemMessage(const QString &contents)
|
||||
this->addMessage(msg, MessageContext::Original);
|
||||
}
|
||||
|
||||
void Channel::addOrReplaceTimeout(MessagePtr message)
|
||||
void Channel::addOrReplaceTimeout(MessagePtr message, QTime now)
|
||||
{
|
||||
addOrReplaceChannelTimeout(
|
||||
this->getMessageSnapshot(), std::move(message), QTime::currentTime(),
|
||||
this->getMessageSnapshot(), std::move(message), now,
|
||||
[this](auto /*idx*/, auto msg, auto replacement) {
|
||||
this->replaceMessage(msg, replacement);
|
||||
},
|
||||
@@ -299,10 +301,15 @@ void Channel::clearMessages()
|
||||
}
|
||||
|
||||
MessagePtr Channel::findMessage(QString messageID)
|
||||
{
|
||||
return this->findMessageByID(messageID);
|
||||
}
|
||||
|
||||
MessagePtr Channel::findMessageByID(QStringView messageID)
|
||||
{
|
||||
MessagePtr res;
|
||||
|
||||
if (auto msg = this->messages_.rfind([&messageID](const MessagePtr &msg) {
|
||||
if (auto msg = this->messages_.rfind([messageID](const MessagePtr &msg) {
|
||||
return msg->id == messageID;
|
||||
});
|
||||
msg)
|
||||
@@ -313,6 +320,19 @@ MessagePtr Channel::findMessage(QString messageID)
|
||||
return res;
|
||||
}
|
||||
|
||||
void Channel::applySimilarityFilters(const MessagePtr &message) const
|
||||
{
|
||||
setSimilarityFlags(message, this->messages_.getSnapshot());
|
||||
}
|
||||
|
||||
MessageSinkTraits Channel::sinkTraits() const
|
||||
{
|
||||
return {
|
||||
MessageSinkTrait::AddMentionsToGlobalChannel,
|
||||
MessageSinkTrait::RequiresKnownChannelPointReward,
|
||||
};
|
||||
}
|
||||
|
||||
bool Channel::canSendMessage() const
|
||||
{
|
||||
return false;
|
||||
|
||||
+16
-15
@@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/enums/MessageContext.hpp"
|
||||
#include "controllers/completion/TabCompletionModel.hpp"
|
||||
#include "messages/LimitedQueue.hpp"
|
||||
#include "messages/MessageFlag.hpp"
|
||||
#include "messages/MessageSink.hpp"
|
||||
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
#include <pajlada/signals/signal.hpp>
|
||||
@@ -26,15 +28,7 @@ enum class TimeoutStackStyle : int {
|
||||
Default = DontStackBeyondUserMessage,
|
||||
};
|
||||
|
||||
/// Context of the message being added to a channel
|
||||
enum class MessageContext {
|
||||
/// This message is the original
|
||||
Original,
|
||||
/// This message is a repost of a message that has already been added in a channel
|
||||
Repost,
|
||||
};
|
||||
|
||||
class Channel : public std::enable_shared_from_this<Channel>
|
||||
class Channel : public std::enable_shared_from_this<Channel>, public MessageSink
|
||||
{
|
||||
public:
|
||||
// This is for Lua. See scripts/make_luals_meta.py
|
||||
@@ -55,7 +49,7 @@ public:
|
||||
};
|
||||
|
||||
explicit Channel(const QString &name, Type type);
|
||||
virtual ~Channel();
|
||||
~Channel() override;
|
||||
|
||||
// SIGNALS
|
||||
pajlada::Signals::Signal<const QString &, const QString &, bool &>
|
||||
@@ -87,8 +81,9 @@ public:
|
||||
// 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, MessageContext context,
|
||||
std::optional<MessageFlags> overridingFlags = std::nullopt);
|
||||
void addMessage(
|
||||
MessagePtr message, MessageContext context,
|
||||
std::optional<MessageFlags> overridingFlags = std::nullopt) final;
|
||||
void addMessagesAtStart(const std::vector<MessagePtr> &messages_);
|
||||
|
||||
void addSystemMessage(const QString &contents);
|
||||
@@ -96,8 +91,8 @@ public:
|
||||
/// Inserts the given messages in order by Message::serverReceivedTime.
|
||||
void fillInMissingMessages(const std::vector<MessagePtr> &messages);
|
||||
|
||||
void addOrReplaceTimeout(MessagePtr message);
|
||||
void disableAllMessages();
|
||||
void addOrReplaceTimeout(MessagePtr message, QTime now) final;
|
||||
void disableAllMessages() final;
|
||||
void replaceMessage(const MessagePtr &message,
|
||||
const MessagePtr &replacement);
|
||||
void replaceMessage(size_t index, const MessagePtr &replacement);
|
||||
@@ -108,10 +103,16 @@ public:
|
||||
/// Removes all messages from this channel and invokes #messagesCleared
|
||||
void clearMessages();
|
||||
|
||||
MessagePtr findMessage(QString messageID);
|
||||
[[deprecated("Use findMessageByID instead")]] MessagePtr findMessage(
|
||||
QString messageID);
|
||||
MessagePtr findMessageByID(QStringView messageID) final;
|
||||
|
||||
bool hasMessages() const;
|
||||
|
||||
void applySimilarityFilters(const MessagePtr &message) const final;
|
||||
|
||||
MessageSinkTraits sinkTraits() const final;
|
||||
|
||||
// CHANNEL INFO
|
||||
virtual bool canSendMessage() const;
|
||||
virtual bool isWritable() const; // whether split input will be usable
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
/// Context of the message being added to a channel
|
||||
enum class MessageContext {
|
||||
/// This message is the original
|
||||
Original,
|
||||
/// This message is a repost of a message that has already been added in a channel
|
||||
Repost,
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
Reference in New Issue
Block a user