highlight tabs only on unviewed messages

This commit is contained in:
unknown 2024-10-14 17:28:16 +02:00 committed by hemirt
parent 6d139af553
commit f7dd6de872
5 changed files with 76 additions and 8 deletions

View file

@ -1190,11 +1190,13 @@ void ChannelView::messageAppended(MessagePtr &message,
(this->channel_->getType() == Channel::Type::TwitchAutomod && (this->channel_->getType() == Channel::Type::TwitchAutomod &&
getSettings()->enableAutomodHighlight)) getSettings()->enableAutomodHighlight))
{ {
this->tabHighlightRequested.invoke(HighlightState::Highlighted); this->tabHighlightRequested.invoke(HighlightState::Highlighted,
message);
} }
else else
{ {
this->tabHighlightRequested.invoke(HighlightState::NewMessage); this->tabHighlightRequested.invoke(HighlightState::NewMessage,
message);
} }
} }

View file

@ -179,6 +179,9 @@ public:
LimitedQueueSnapshot<MessageLayoutPtr> &getMessagesSnapshot(); LimitedQueueSnapshot<MessageLayoutPtr> &getMessagesSnapshot();
// Returns true if message should be included
bool shouldIncludeMessage(const MessagePtr &m) const;
void queueLayout(); void queueLayout();
void invalidateBuffers(); void invalidateBuffers();
@ -214,7 +217,7 @@ public:
pajlada::Signals::Signal<QMouseEvent *> mouseDown; pajlada::Signals::Signal<QMouseEvent *> mouseDown;
pajlada::Signals::NoArgSignal selectionChanged; pajlada::Signals::NoArgSignal selectionChanged;
pajlada::Signals::Signal<HighlightState> tabHighlightRequested; pajlada::Signals::Signal<HighlightState, MessagePtr> tabHighlightRequested;
pajlada::Signals::NoArgSignal liveStatusChanged; pajlada::Signals::NoArgSignal liveStatusChanged;
pajlada::Signals::Signal<const Link &> linkClicked; pajlada::Signals::Signal<const Link &> linkClicked;
pajlada::Signals::Signal<QString, FromTwitchLinkOpenChannelIn> pajlada::Signals::Signal<QString, FromTwitchLinkOpenChannelIn>
@ -374,9 +377,6 @@ private:
FilterSetPtr channelFilters_; FilterSetPtr channelFilters_;
// Returns true if message should be included
bool shouldIncludeMessage(const MessagePtr &m) const;
// Returns whether the scrollbar should have highlights // Returns whether the scrollbar should have highlights
bool showScrollbarHighlights() const; bool showScrollbarHighlights() const;

View file

@ -10,8 +10,10 @@
#include "singletons/WindowManager.hpp" #include "singletons/WindowManager.hpp"
#include "util/Helpers.hpp" #include "util/Helpers.hpp"
#include "widgets/dialogs/SettingsDialog.hpp" #include "widgets/dialogs/SettingsDialog.hpp"
#include "widgets/helper/ChannelView.hpp"
#include "widgets/Notebook.hpp" #include "widgets/Notebook.hpp"
#include "widgets/splits/DraggedSplit.hpp" #include "widgets/splits/DraggedSplit.hpp"
#include "widgets/splits/Split.hpp"
#include "widgets/splits/SplitContainer.hpp" #include "widgets/splits/SplitContainer.hpp"
#include <boost/bind/bind.hpp> #include <boost/bind/bind.hpp>
@ -381,6 +383,65 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
this->update(); 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<SplitContainer *>(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 = []<typename T>(QSet<T> sub, QSet<T> 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 HighlightState NotebookTab::highlightState() const
{ {
return this->highlightState_; return this->highlightState_;

View file

@ -14,6 +14,7 @@ namespace chatterino {
inline constexpr int NOTEBOOK_TAB_HEIGHT = 28; inline constexpr int NOTEBOOK_TAB_HEIGHT = 28;
class SplitContainer; class SplitContainer;
class ChannelView;
class NotebookTab : public Button class NotebookTab : public Button
{ {
@ -60,6 +61,8 @@ public:
bool isLive() const; bool isLive() const;
void setHighlightState(HighlightState style); void setHighlightState(HighlightState style);
void setHighlightState(HighlightState style, ChannelView &channelViewSource,
MessagePtr message);
HighlightState highlightState() const; HighlightState highlightState() const;
void setHighlightsEnabled(const bool &newVal); void setHighlightsEnabled(const bool &newVal);

View file

@ -214,10 +214,12 @@ void SplitContainer::addSplit(Split *split)
auto &&conns = this->connectionsPerSplit_[split]; auto &&conns = this->connectionsPerSplit_[split];
conns.managedConnect(split->getChannelView().tabHighlightRequested, conns.managedConnect(split->getChannelView().tabHighlightRequested,
[this](HighlightState state) { [this, &channelView = split->getChannelView()](
HighlightState state, MessagePtr message) {
if (this->tab_ != nullptr) if (this->tab_ != nullptr)
{ {
this->tab_->setHighlightState(state); this->tab_->setHighlightState(
state, channelView, message);
} }
}); });