diff --git a/src/messages/MessageSimilarity.cpp b/src/messages/MessageSimilarity.cpp index 3019aea67..2f8157d6b 100644 --- a/src/messages/MessageSimilarity.cpp +++ b/src/messages/MessageSimilarity.cpp @@ -1,9 +1,17 @@ #include "messages/MessageSimilarity.hpp" +#include "Application.hpp" +#include "controllers/accounts/AccountController.hpp" +#include "messages/LimitedQueueSnapshot.hpp" // IWYU pragma: keep +#include "providers/twitch/TwitchAccount.hpp" +#include "singletons/Settings.hpp" + #include #include -namespace chatterino::similarity::detail { +namespace { + +using namespace chatterino; float relativeSimilarity(QStringView str1, QStringView str2) { @@ -48,4 +56,66 @@ float relativeSimilarity(QStringView str1, QStringView str2) return float(z) / float(div); } -} // namespace chatterino::similarity::detail +template +float inMessages(const MessagePtr &msg, const T &messages) +{ + float similarityPercent = 0.0F; + + for (const auto &prevMsg : + messages | std::views::reverse | + std::views::take(getSettings()->hideSimilarMaxMessagesToCheck)) + { + if (prevMsg->parseTime.secsTo(QTime::currentTime()) >= + getSettings()->hideSimilarMaxDelay) + { + break; + } + if (getSettings()->hideSimilarBySameUser && + msg->loginName != prevMsg->loginName) + { + continue; + } + similarityPercent = std::max( + similarityPercent, + relativeSimilarity(msg->messageText, prevMsg->messageText)); + } + + return similarityPercent; +} + +} // namespace + +namespace chatterino { + +template +void setSimilarityFlags(const MessagePtr &message, const T &messages) +{ + if (getSettings()->similarityEnabled) + { + bool isMyself = + message->loginName == + getApp()->getAccounts()->twitch.getCurrent()->getUserName(); + bool hideMyself = getSettings()->hideSimilarMyself; + + if (isMyself && !hideMyself) + { + return; + } + + if (inMessages(message, messages) > getSettings()->similarityPercentage) + { + message->flags.set(MessageFlag::Similar); + if (getSettings()->colorSimilarDisabled) + { + message->flags.set(MessageFlag::Disabled); + } + } + } +} + +template void setSimilarityFlags>( + const MessagePtr &msg, const std::vector &messages); +template void setSimilarityFlags>( + const MessagePtr &msg, const LimitedQueueSnapshot &messages); + +} // namespace chatterino diff --git a/src/messages/MessageSimilarity.hpp b/src/messages/MessageSimilarity.hpp index 562e574ad..54d0214d7 100644 --- a/src/messages/MessageSimilarity.hpp +++ b/src/messages/MessageSimilarity.hpp @@ -1,73 +1,11 @@ #pragma once -#include "Application.hpp" -#include "controllers/accounts/AccountController.hpp" #include "messages/Message.hpp" -#include "providers/twitch/TwitchAccount.hpp" -#include "singletons/Settings.hpp" #include - -namespace chatterino::similarity::detail { - -float relativeSimilarity(QStringView str1, QStringView str2); - -float inMessages(const MessagePtr &msg, - const std::ranges::bidirectional_range auto &messages) -{ - float similarityPercent = 0.0F; - - for (const auto &prevMsg : - messages | std::views::reverse | - std::views::take(getSettings()->hideSimilarMaxMessagesToCheck)) - { - if (prevMsg->parseTime.secsTo(QTime::currentTime()) >= - getSettings()->hideSimilarMaxDelay) - { - break; - } - if (getSettings()->hideSimilarBySameUser && - msg->loginName != prevMsg->loginName) - { - continue; - } - similarityPercent = std::max( - similarityPercent, - relativeSimilarity(msg->messageText, prevMsg->messageText)); - } - - return similarityPercent; -} - -} // namespace chatterino::similarity::detail - namespace chatterino { -void setSimilarityFlags(const MessagePtr &message, - const std::ranges::bidirectional_range auto &messages) -{ - if (getSettings()->similarityEnabled) - { - bool isMyself = - message->loginName == - getApp()->getAccounts()->twitch.getCurrent()->getUserName(); - bool hideMyself = getSettings()->hideSimilarMyself; - - if (isMyself && !hideMyself) - { - return; - } - - if (similarity::detail::inMessages(message, messages) > - getSettings()->similarityPercentage) - { - message->flags.set(MessageFlag::Similar); - if (getSettings()->colorSimilarDisabled) - { - message->flags.set(MessageFlag::Disabled); - } - } - } -} +template +void setSimilarityFlags(const MessagePtr &message, const T &messages); } // namespace chatterino diff --git a/src/messages/MessageSink.hpp b/src/messages/MessageSink.hpp index 07e7101a5..b44690ead 100644 --- a/src/messages/MessageSink.hpp +++ b/src/messages/MessageSink.hpp @@ -1,6 +1,7 @@ #pragma once #include "common/enums/MessageContext.hpp" +#include "common/FlagsEnum.hpp" #include "messages/MessageFlag.hpp" #include @@ -15,7 +16,14 @@ using MessagePtr = std::shared_ptr; enum class MessageSinkTrait : uint8_t { None = 0, + + /// Messages with the `Highlighted` and `ShowInMentions` flags should be + /// added to the global mentions channel when encountered. AddMentionsToGlobalChannel = 1 << 0, + + /// A channel-point redemption whose reward is not yet known should not be + /// added to this sink, but queued in the corresponding TwitchChannel + /// (`addQueuedRedemption`). RequiresKnownChannelPointReward = 1 << 1, }; using MessageSinkTraits = FlagsEnum; @@ -51,7 +59,7 @@ public: /// If there is no message found, an empty shared-pointer is returned. virtual MessagePtr findMessageByID(QStringView id) = 0; - /// + /// Behaviour to be exercised when parsing/building messages for this sink. virtual MessageSinkTraits sinkTraits() const = 0; }; diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 86d26c249..00bd8c117 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -1356,8 +1356,6 @@ void TwitchChannel::loadRecentMessages() { msgs.push_back(msg); } - - tc->addRecentChatter(msg->displayName); } getApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages(