Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlight tabs only on unviewed messages #5649

Merged
merged 33 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f7dd6de
highlight tabs only on unviewed messages
hemirt Oct 14, 2024
e827097
fix suggestions
hemirt Oct 14, 2024
3b64f14
commit suggestions
hemirt Oct 15, 2024
70f497d
Update src/widgets/helper/NotebookTab.cpp
hemirt Oct 15, 2024
7728f01
name fixes
hemirt Oct 15, 2024
edaafac
initial state of selecting to unhiglight
hemirt Oct 17, 2024
806fa77
missing include
hemirt Oct 17, 2024
13d7692
add older version code
hemirt Oct 17, 2024
a2af8e7
switch from QHash to std::unordered_map
hemirt Oct 17, 2024
5f862c5
solve highlighted tabs
hemirt Oct 17, 2024
8745d07
fix duplicating tabs
hemirt Oct 17, 2024
39e0e00
add more highlight state functions
hemirt Oct 17, 2024
1ca5d38
add some asserts
hemirt Oct 17, 2024
e288742
more asserts
hemirt Oct 17, 2024
2884c82
update highlights of other tabs when adding new channel or changing
hemirt Oct 18, 2024
fe51ba8
hash based matching based on ChannelView name and filters
hemirt Oct 20, 2024
b0e3a41
message shown based inclusion
hemirt Oct 20, 2024
ef2647f
treat filters as special channels that should highlight always
hemirt Oct 20, 2024
49caab7
Merge branch 'Chatterino:master' into master
hemirt Oct 20, 2024
af3d46f
add boost hash include
hemirt Oct 20, 2024
79ee3dc
update changelog
hemirt Oct 21, 2024
9b31f61
Merge branch 'master' of https://github.com/chatterino/chatterino2
hemirt Oct 21, 2024
e5e5a79
do not higlight tabs that are marked as not highlight for new messages
hemirt Oct 22, 2024
374e0c5
remove leftovers
hemirt Oct 22, 2024
0e48979
replace ChannelViewProxy with ChannelViewId
hemirt Oct 22, 2024
1bdb118
cache channel view id
hemirt Oct 22, 2024
7844a3b
Merge branch 'master' into master
hemirt Oct 26, 2024
55c0e69
treat each channelView with its filter as its own
hemirt Oct 26, 2024
05ab3b2
switch from using two sets to one map
hemirt Oct 26, 2024
0e506fc
remove remnants of different strategy
hemirt Oct 28, 2024
21e1df0
Merge branch 'master' into master
pajlada Oct 28, 2024
de87f22
revert publicizing shouldIncludeMessage from channelview
hemirt Oct 28, 2024
fae4e5c
Merge branch 'master' into master
pajlada Nov 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/widgets/Notebook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "widgets/BaseWidget.hpp"

#include <ForwardDecl.hpp>
hemirt marked this conversation as resolved.
Show resolved Hide resolved
#include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp>
#include <QList>
Expand Down
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
9 changes: 5 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
hemirt marked this conversation as resolved.
Show resolved Hide resolved
bool shouldIncludeMessage(const MessagePtr &m) const;

hemirt marked this conversation as resolved.
Show resolved Hide resolved
void queueLayout();
void invalidateBuffers();

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

pajlada::Signals::Signal<QMouseEvent *> mouseDown;
pajlada::Signals::NoArgSignal selectionChanged;
pajlada::Signals::Signal<HighlightState> tabHighlightRequested;
pajlada::Signals::Signal<HighlightState, const MessagePtr &>
tabHighlightRequested;
pajlada::Signals::NoArgSignal liveStatusChanged;
pajlada::Signals::Signal<const Link &> linkClicked;
pajlada::Signals::Signal<QString, FromTwitchLinkOpenChannelIn>
Expand Down Expand Up @@ -374,9 +378,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
108 changes: 108 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 @@ -302,10 +304,49 @@ bool NotebookTab::isSelected() const
return this->selected_;
}

void NotebookTab::updateHighlightSources(
hemirt marked this conversation as resolved.
Show resolved Hide resolved
const QHash<ChannelPtr, HighlightEvent> &removedHighlightSources)
{
for (const auto &[otherChannel, otherEvent] :
removedHighlightSources.asKeyValueRange())
{
this->highlightSources_.remove(otherChannel);
}

if (this->highlightSources_.empty())
{
this->highlightState_ = HighlightState::None;
this->update();
}
}

void NotebookTab::setSelected(bool value)
{
this->selected_ = value;

if (value == true)
hemirt marked this conversation as resolved.
Show resolved Hide resolved
hemirt marked this conversation as resolved.
Show resolved Hide resolved
{
auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_);
if (splitNotebook)
{
for (int i = 0; i < splitNotebook->getPageCount(); ++i)
{
auto *splitContainer =
dynamic_cast<SplitContainer *>(splitNotebook->getPageAt(i));
if (splitContainer)
{
auto *tab = splitContainer->getTab();
if (tab && tab != this)
{
tab->updateHighlightSources(this->highlightSources_);
}
}
}
}
}

this->highlightSources_.clear();

this->highlightState_ = HighlightState::None;

this->update();
Expand Down Expand Up @@ -359,12 +400,46 @@ bool NotebookTab::isLive() const
}

void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
{
// change this to "copy" highlight state, its used by duplicating a tab
if (this->isSelected())
{
return;
}

if (!this->highlightEnabled_ &&
newHighlightStyle == HighlightState::NewMessage)
{
return;
}

if (this->highlightState_ == newHighlightStyle ||
this->highlightState_ == HighlightState::Highlighted)
{
return;
}

this->highlightState_ = newHighlightStyle;
this->update();
}

void NotebookTab::setHighlightState(HighlightState newHighlightStyle,
const ChannelView &channelViewSource,
const MessagePtr &message)
{
if (this->isSelected())
{
return;
}

if (!this->shouldMessageHighlight(channelViewSource, message))
{
return;
}

this->highlightSources_.insert(channelViewSource.underlyingChannel(),
HighlightEvent{});

if (!this->highlightEnabled_ &&
newHighlightStyle == HighlightState::NewMessage)
{
Expand All @@ -381,6 +456,39 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
this->update();
}

bool NotebookTab::shouldMessageHighlight(const ChannelView &channelViewSource,
const MessagePtr &message) const
pajlada marked this conversation as resolved.
Show resolved Hide resolved
{
auto *visibleSplitContainer =
dynamic_cast<SplitContainer *>(this->notebook_->getSelectedPage());
if (visibleSplitContainer != nullptr)
{
const auto &visibleSplits = visibleSplitContainer->getSplits();
for (const auto &visibleSplit : visibleSplits)
{
hemirt marked this conversation as resolved.
Show resolved Hide resolved
auto filterIdsSource = channelViewSource.getFilterIds();
auto filterIdsSplit = visibleSplit->getChannelView().getFilterIds();

auto isSubset = []<typename T>(const QList<T> &sub,
const QList<T> &super) {
return std::ranges::all_of(sub, [&super](const auto &subItem) {
return super.contains(subItem);
});
};

if (channelViewSource.underlyingChannel() ==
visibleSplit->getChannel() &&
visibleSplit->getChannelView().shouldIncludeMessage(message) &&
isSubset(filterIdsSource, filterIdsSplit))
{
return false;
}
}
}

return true;
}
hemirt marked this conversation as resolved.
Show resolved Hide resolved

HighlightState NotebookTab::highlightState() const
{
return this->highlightState_;
Expand Down
15 changes: 15 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,9 @@ class NotebookTab : public Button
bool isLive() const;

void setHighlightState(HighlightState style);
hemirt marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like setHighlightState is unused now (except for in unit tests) - should be removed then imo.
If you'd like, you can wait with this for a bit as I'd like to try to see if we can get ChannelView unit tests going

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

void setHighlightsEnabled(const bool &newVal);
Expand Down Expand Up @@ -107,6 +111,15 @@ class NotebookTab : public Button

int normalTabWidthForHeight(int height) const;

bool shouldMessageHighlight(const ChannelView &channelViewSource,
const MessagePtr &message) const;

struct HighlightEvent {
};

void updateHighlightSources(
const QHash<ChannelPtr, HighlightEvent> &removedHighlightSources);
hemirt marked this conversation as resolved.
Show resolved Hide resolved

QPropertyAnimation positionChangedAnimation_;
QPoint positionAnimationDesiredPoint_;

Expand Down Expand Up @@ -135,6 +148,8 @@ class NotebookTab : public Button

QMenu menu_;

QHash<ChannelPtr, HighlightEvent> highlightSources_;
hemirt marked this conversation as resolved.
Show resolved Hide resolved

pajlada::Signals::SignalHolder managedConnections_;
};

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, const MessagePtr &message) {
if (this->tab_ != nullptr)
{
this->tab_->setHighlightState(state);
this->tab_->setHighlightState(
state, channelView, message);
hemirt marked this conversation as resolved.
Show resolved Hide resolved
}
});

Expand Down
Loading