mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
feedback
This commit is contained in:
parent
417cdbc009
commit
8eec1da317
|
@ -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 <algorithm>
|
||||
#include <vector>
|
||||
|
||||
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 <std::ranges::bidirectional_range T>
|
||||
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 <std::ranges::bidirectional_range T>
|
||||
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<std::vector<MessagePtr>>(
|
||||
const MessagePtr &msg, const std::vector<MessagePtr> &messages);
|
||||
template void setSimilarityFlags<LimitedQueueSnapshot<MessagePtr>>(
|
||||
const MessagePtr &msg, const LimitedQueueSnapshot<MessagePtr> &messages);
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -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 <ranges>
|
||||
|
||||
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 <std::ranges::bidirectional_range T>
|
||||
void setSimilarityFlags(const MessagePtr &message, const T &messages);
|
||||
|
||||
} // namespace chatterino
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/enums/MessageContext.hpp"
|
||||
#include "common/FlagsEnum.hpp"
|
||||
#include "messages/MessageFlag.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
@ -15,7 +16,14 @@ using MessagePtr = std::shared_ptr<const Message>;
|
|||
|
||||
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<MessageSinkTrait>;
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -1356,8 +1356,6 @@ void TwitchChannel::loadRecentMessages()
|
|||
{
|
||||
msgs.push_back(msg);
|
||||
}
|
||||
|
||||
tc->addRecentChatter(msg->displayName);
|
||||
}
|
||||
|
||||
getApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages(
|
||||
|
|
Loading…
Reference in a new issue