refactor: remove unused ReplyContext.highlight (#5669)

This commit is contained in:
pajlada 2024-10-21 19:22:23 +02:00 committed by GitHub
parent 45d2c292d0
commit 2ec8fa8723
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -123,47 +123,34 @@ int stripLeadingReplyMention(const QVariantMap &tags, QString &content)
return 0; return 0;
} }
[[nodiscard]] bool shouldHighlightReplyThread( void checkThreadSubscription(const QVariantMap &tags,
const QVariantMap &tags, const QString &senderLogin, const QString &senderLogin,
std::shared_ptr<MessageThread> &thread, bool isNew) std::shared_ptr<MessageThread> &thread)
{ {
const auto &currentLogin = if (thread->subscribed() || thread->unsubscribed())
getApp()->getAccounts()->twitch.getCurrent()->getUserName();
if (thread->subscribed())
{ {
return true; return;
}
if (thread->unsubscribed())
{
return false;
} }
if (getSettings()->autoSubToParticipatedThreads) if (getSettings()->autoSubToParticipatedThreads)
{ {
if (isNew) const auto &currentLogin =
getApp()->getAccounts()->twitch.getCurrent()->getUserName();
if (senderLogin == currentLogin)
{ {
if (const auto it = tags.find("reply-parent-user-login"); thread->markSubscribed();
}
else if (const auto it = tags.find("reply-parent-user-login");
it != tags.end()) it != tags.end())
{ {
auto name = it.value().toString(); auto name = it.value().toString();
if (name == currentLogin) if (name == currentLogin)
{ {
thread->markSubscribed(); thread->markSubscribed();
return true; // already marked as participated
} }
} }
} }
if (senderLogin == currentLogin)
{
thread->markSubscribed();
// don't set the highlight here
}
}
return false;
} }
ChannelPtr channelOrEmptyByTarget(const QString &target, ChannelPtr channelOrEmptyByTarget(const QString &target,
@ -243,7 +230,6 @@ QMap<QString, QString> parseBadges(const QString &badgesString)
struct ReplyContext { struct ReplyContext {
std::shared_ptr<MessageThread> thread; std::shared_ptr<MessageThread> thread;
MessagePtr parent; MessagePtr parent;
bool highlight = false;
}; };
[[nodiscard]] ReplyContext getReplyContext( [[nodiscard]] ReplyContext getReplyContext(
@ -265,8 +251,7 @@ struct ReplyContext {
if (owned) if (owned)
{ {
// Thread already exists (has a reply) // Thread already exists (has a reply)
ctx.highlight = shouldHighlightReplyThread( checkThreadSubscription(tags, message->nick(), owned);
tags, message->nick(), owned, false);
ctx.thread = owned; ctx.thread = owned;
rootThread = owned; rootThread = owned;
} }
@ -301,8 +286,7 @@ struct ReplyContext {
{ {
std::shared_ptr<MessageThread> newThread = std::shared_ptr<MessageThread> newThread =
std::make_shared<MessageThread>(foundMessage); std::make_shared<MessageThread>(foundMessage);
ctx.highlight = shouldHighlightReplyThread( checkThreadSubscription(tags, message->nick(), newThread);
tags, message->nick(), newThread, true);
ctx.thread = newThread; ctx.thread = newThread;
rootThread = newThread; rootThread = newThread;
@ -724,10 +708,6 @@ std::vector<MessagePtr> IrcMessageHandler::parseMessageWithReply(
if (built) if (built)
{ {
if (replyCtx.highlight)
{
built->flags.set(MessageFlag::SubscribedThread);
}
builtMessages.emplace_back(built); builtMessages.emplace_back(built);
MessageBuilder::triggerHighlights(channel, alert); MessageBuilder::triggerHighlights(channel, alert);
} }
@ -1552,8 +1532,7 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
{ {
// Thread already exists (has a reply) // Thread already exists (has a reply)
auto thread = threadIt->second.lock(); auto thread = threadIt->second.lock();
replyCtx.highlight = shouldHighlightReplyThread( checkThreadSubscription(tags, message->nick(), thread);
tags, message->nick(), thread, false);
replyCtx.thread = thread; replyCtx.thread = thread;
rootThread = thread; rootThread = thread;
} }
@ -1565,8 +1544,7 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
{ {
// Found root reply message // Found root reply message
auto newThread = std::make_shared<MessageThread>(root); auto newThread = std::make_shared<MessageThread>(root);
replyCtx.highlight = shouldHighlightReplyThread( checkThreadSubscription(tags, message->nick(), newThread);
tags, message->nick(), newThread, true);
replyCtx.thread = newThread; replyCtx.thread = newThread;
rootThread = newThread; rootThread = newThread;
@ -1621,10 +1599,6 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
msg->flags.set(MessageFlag::Subscription); msg->flags.set(MessageFlag::Subscription);
msg->flags.unset(MessageFlag::Highlighted); msg->flags.unset(MessageFlag::Highlighted);
} }
if (replyCtx.highlight)
{
msg->flags.set(MessageFlag::SubscribedThread);
}
IrcMessageHandler::setSimilarityFlags(msg, chan); IrcMessageHandler::setSimilarityFlags(msg, chan);