Skip to content

Commit

Permalink
cache channel view id
Browse files Browse the repository at this point in the history
  • Loading branch information
hemirt committed Oct 22, 2024
1 parent 0e48979 commit 1bdb118
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
27 changes: 27 additions & 0 deletions src/widgets/helper/ChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,8 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)

this->underlyingChannel_ = underlyingChannel;

this->updateID();

this->performLayout();
this->queueUpdate();

Expand All @@ -1081,6 +1083,8 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)
void ChannelView::setFilters(const QList<QUuid> &ids)
{
this->channelFilters_ = std::make_shared<FilterSet>(ids);

this->updateID();
}

QList<QUuid> ChannelView::getFilterIds() const
Expand Down Expand Up @@ -3237,4 +3241,27 @@ void ChannelView::pendingLinkInfoStateChanged()
this->tooltipWidget_->applyLastBoundsCheck();
}

void ChannelView::updateID()
{
if (!this->underlyingChannel_)
{
// cannot update
return;
}

std::size_t seed = 0;
auto first = qHash(this->underlyingChannel_->getName());
auto second = qHash(this->getFilterIds());

boost::hash_combine(seed, first);
boost::hash_combine(seed, second);

this->id_ = seed;
}

ChannelView::ChannelViewID ChannelView::getID() const
{
return this->id_;
}

} // namespace chatterino
6 changes: 6 additions & 0 deletions src/widgets/helper/ChannelView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ class ChannelView final : public BaseWidget

Scrollbar *scrollbar();

using ChannelViewID = std::size_t;
ChannelViewID getID() const;

pajlada::Signals::Signal<QMouseEvent *> mouseDown;
pajlada::Signals::NoArgSignal selectionChanged;
pajlada::Signals::Signal<HighlightState, const MessagePtr &>
Expand Down Expand Up @@ -318,6 +321,9 @@ class ChannelView final : public BaseWidget
void showReplyThreadPopup(const MessagePtr &message);
bool canReplyToMessages() const;

void updateID();
ChannelViewID id_{};

bool layoutQueued_ = false;
bool bufferInvalidationQueued_ = false;

Expand Down
14 changes: 4 additions & 10 deletions src/widgets/helper/NotebookTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ bool NotebookTab::isSelected() const
}

void NotebookTab::removeNewMessageSource(
const HighlightSources::ChannelViewId &source)
const ChannelView::ChannelViewID &source)
{
this->highlightSources_.newMessageSource.erase(source);
}

void NotebookTab::removeHighlightedSource(
const HighlightSources::ChannelViewId &source)
const ChannelView::ChannelViewID &source)
{
this->highlightSources_.highlightedSource.erase(source);
}
Expand All @@ -333,10 +333,7 @@ void NotebookTab::removeHighlightStateChangeSources(

void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
{
const auto &channelName = channelViewSource.underlyingChannel()->getName();
const auto &channelFilterIds = channelViewSource.getFilterIds();
auto channelViewId =
HighlightSources::GetChannelViewId(channelName, channelFilterIds);
auto channelViewId = channelViewSource.getID();
this->removeHighlightedSource(channelViewId);
this->removeNewMessageSource(channelViewId);
this->updateHighlightStateDueSourcesChange();
Expand Down Expand Up @@ -556,10 +553,7 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,

// message is highlighting unvisible tab

const auto &channelName = channelViewSource.underlyingChannel()->getName();
const auto &channelFilterIds = channelViewSource.getFilterIds();
auto channelViewId =
HighlightSources::GetChannelViewId(channelName, channelFilterIds);
auto channelViewId = channelViewSource.getID();

switch (newHighlightStyle)
{
Expand Down
23 changes: 4 additions & 19 deletions src/widgets/helper/NotebookTab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,8 @@ class NotebookTab : public Button
const MessagePtr &message) const;

struct HighlightSources {
using ChannelViewId = std::size_t;

static ChannelViewId GetChannelViewId(
const QString &channelName, const QList<QUuid> &channelFilterIds)
{
std::size_t seed = 0;
auto first = qHash(channelName);
auto second = qHash(channelFilterIds);

boost::hash_combine(seed, first);
boost::hash_combine(seed, second);

return seed;
}

std::unordered_set<ChannelViewId> newMessageSource;
std::unordered_set<ChannelViewId> highlightedSource;
std::unordered_set<ChannelView::ChannelViewID> newMessageSource;
std::unordered_set<ChannelView::ChannelViewID> highlightedSource;

void clear()
{
Expand All @@ -152,8 +137,8 @@ class NotebookTab : public Button
} highlightSources_;

void removeHighlightStateChangeSources(const HighlightSources &toRemove);
void removeNewMessageSource(const HighlightSources::ChannelViewId &source);
void removeHighlightedSource(const HighlightSources::ChannelViewId &source);
void removeNewMessageSource(const ChannelView::ChannelViewID &source);
void removeHighlightedSource(const ChannelView::ChannelViewID &source);
void updateHighlightStateDueSourcesChange();

QPropertyAnimation positionChangedAnimation_;
Expand Down

0 comments on commit 1bdb118

Please sign in to comment.