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 &&
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);
}
}

View file

@ -179,6 +179,9 @@ public:
LimitedQueueSnapshot<MessageLayoutPtr> &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<QMouseEvent *> mouseDown;
pajlada::Signals::NoArgSignal selectionChanged;
pajlada::Signals::Signal<HighlightState> tabHighlightRequested;
pajlada::Signals::Signal<HighlightState, MessagePtr> tabHighlightRequested;
pajlada::Signals::NoArgSignal liveStatusChanged;
pajlada::Signals::Signal<const Link &> linkClicked;
pajlada::Signals::Signal<QString, FromTwitchLinkOpenChannelIn>
@ -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;

View file

@ -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 <boost/bind/bind.hpp>
@ -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<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
{
return this->highlightState_;

View file

@ -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);

View file

@ -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);
}
});