Skip to content

Commit

Permalink
highlight tabs only on unviewed messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hemirt committed Oct 14, 2024
1 parent c0a5a3e commit e0da76c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/widgets/helper/ChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/widgets/helper/ChannelView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class ChannelView final : public BaseWidget

LimitedQueueSnapshot<MessageLayoutPtr> &getMessagesSnapshot();

// Returns true if message should be included
bool shouldIncludeMessage(const MessagePtr &m) const;

void queueLayout();
void invalidateBuffers();

Expand Down Expand Up @@ -214,7 +217,7 @@ class ChannelView final : public BaseWidget

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>
Expand Down Expand Up @@ -374,9 +377,6 @@ class ChannelView final : public BaseWidget

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;

Expand Down
61 changes: 61 additions & 0 deletions src/widgets/helper/NotebookTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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_;
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/helper/NotebookTab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace chatterino {
inline constexpr int NOTEBOOK_TAB_HEIGHT = 28;

class SplitContainer;
class ChannelView;

class NotebookTab : public Button
{
Expand Down Expand Up @@ -60,6 +61,8 @@ class NotebookTab : public Button
bool isLive() const;

void setHighlightState(HighlightState style);
void setHighlightState(HighlightState style, ChannelView &channelViewSource,
MessagePtr message);
HighlightState highlightState() const;

void setHighlightsEnabled(const bool &newVal);
Expand Down
6 changes: 4 additions & 2 deletions src/widgets/splits/SplitContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down

0 comments on commit e0da76c

Please sign in to comment.