From f7dd6de8725a132242e7d3ce2389b52f72061138 Mon Sep 17 00:00:00 2001 From: unknown <1310440+hemirt@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:28:16 +0200 Subject: [PATCH] highlight tabs only on unviewed messages --- src/widgets/helper/ChannelView.cpp | 6 ++- src/widgets/helper/ChannelView.hpp | 8 ++-- src/widgets/helper/NotebookTab.cpp | 61 +++++++++++++++++++++++++++ src/widgets/helper/NotebookTab.hpp | 3 ++ src/widgets/splits/SplitContainer.cpp | 6 ++- 5 files changed, 76 insertions(+), 8 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 066085030..54d5dded5 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1190,11 +1190,13 @@ void ChannelView::messageAppended(MessagePtr &message, (this->channel_->getType() == Channel::Type::TwitchAutomod && getSettings()->enableAutomodHighlight)) { - this->tabHighlightRequested.invoke(HighlightState::Highlighted); + this->tabHighlightRequested.invoke(HighlightState::Highlighted, + message); } else { - this->tabHighlightRequested.invoke(HighlightState::NewMessage); + this->tabHighlightRequested.invoke(HighlightState::NewMessage, + message); } } diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 704210712..56dd15aa0 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -179,6 +179,9 @@ public: LimitedQueueSnapshot &getMessagesSnapshot(); + // Returns true if message should be included + bool shouldIncludeMessage(const MessagePtr &m) const; + void queueLayout(); void invalidateBuffers(); @@ -214,7 +217,7 @@ public: pajlada::Signals::Signal mouseDown; pajlada::Signals::NoArgSignal selectionChanged; - pajlada::Signals::Signal tabHighlightRequested; + pajlada::Signals::Signal tabHighlightRequested; pajlada::Signals::NoArgSignal liveStatusChanged; pajlada::Signals::Signal linkClicked; pajlada::Signals::Signal @@ -374,9 +377,6 @@ private: FilterSetPtr channelFilters_; - // Returns true if message should be included - bool shouldIncludeMessage(const MessagePtr &m) const; - // Returns whether the scrollbar should have highlights bool showScrollbarHighlights() const; diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index be2b371a3..72e28f5de 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -10,8 +10,10 @@ #include "singletons/WindowManager.hpp" #include "util/Helpers.hpp" #include "widgets/dialogs/SettingsDialog.hpp" +#include "widgets/helper/ChannelView.hpp" #include "widgets/Notebook.hpp" #include "widgets/splits/DraggedSplit.hpp" +#include "widgets/splits/Split.hpp" #include "widgets/splits/SplitContainer.hpp" #include @@ -381,6 +383,65 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle) this->update(); } +void NotebookTab::setHighlightState(HighlightState newHighlightStyle, + ChannelView &channelViewSource, + MessagePtr message) +{ + if (this->isSelected()) + { + return; + } + + if (!this->highlightEnabled_ && + newHighlightStyle == HighlightState::NewMessage) + { + return; + } + + if (this->highlightState_ == newHighlightStyle || + this->highlightState_ == HighlightState::Highlighted) + { + return; + } + + auto splitContainer = + dynamic_cast(this->notebook_->getSelectedPage()); + if (splitContainer != nullptr) + { + const auto &splits = splitContainer->getSplits(); + for (const auto &split : splits) + { + auto &&filterIdsSource = channelViewSource.getFilterIds(); + auto uniqueFilterIdsSource = + QSet(filterIdsSource.cbegin(), filterIdsSource.cend()); + auto &&filterIdsSplit = split->getChannelView().getFilterIds(); + auto uniqueFilterIdsSplit = + QSet(filterIdsSplit.cbegin(), filterIdsSplit.cend()); + + auto isSubset = [](QSet sub, QSet super) { + for (auto &&subItem : sub) + { + if (!super.contains(subItem)) + { + return false; + } + } + return true; + }; + + if (channelViewSource.underlyingChannel() == split->getChannel() && + split->getChannelView().shouldIncludeMessage(message) && + isSubset(uniqueFilterIdsSource, uniqueFilterIdsSplit)) + { + return; + } + } + } + + this->highlightState_ = newHighlightStyle; + this->update(); +} + HighlightState NotebookTab::highlightState() const { return this->highlightState_; diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index 6ae7802d0..601957803 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -14,6 +14,7 @@ namespace chatterino { inline constexpr int NOTEBOOK_TAB_HEIGHT = 28; class SplitContainer; +class ChannelView; class NotebookTab : public Button { @@ -60,6 +61,8 @@ public: bool isLive() const; void setHighlightState(HighlightState style); + void setHighlightState(HighlightState style, ChannelView &channelViewSource, + MessagePtr message); HighlightState highlightState() const; void setHighlightsEnabled(const bool &newVal); diff --git a/src/widgets/splits/SplitContainer.cpp b/src/widgets/splits/SplitContainer.cpp index c2ddc1160..6f2893265 100644 --- a/src/widgets/splits/SplitContainer.cpp +++ b/src/widgets/splits/SplitContainer.cpp @@ -214,10 +214,12 @@ void SplitContainer::addSplit(Split *split) auto &&conns = this->connectionsPerSplit_[split]; conns.managedConnect(split->getChannelView().tabHighlightRequested, - [this](HighlightState state) { + [this, &channelView = split->getChannelView()]( + HighlightState state, MessagePtr message) { if (this->tab_ != nullptr) { - this->tab_->setHighlightState(state); + this->tab_->setHighlightState( + state, channelView, message); } });