cache channel view id

This commit is contained in:
unknown 2024-10-23 01:29:37 +02:00
parent 0e4897969b
commit 1bdb118391
4 changed files with 41 additions and 29 deletions

View file

@ -1063,6 +1063,8 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)
this->underlyingChannel_ = underlyingChannel; this->underlyingChannel_ = underlyingChannel;
this->updateID();
this->performLayout(); this->performLayout();
this->queueUpdate(); this->queueUpdate();
@ -1081,6 +1083,8 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)
void ChannelView::setFilters(const QList<QUuid> &ids) void ChannelView::setFilters(const QList<QUuid> &ids)
{ {
this->channelFilters_ = std::make_shared<FilterSet>(ids); this->channelFilters_ = std::make_shared<FilterSet>(ids);
this->updateID();
} }
QList<QUuid> ChannelView::getFilterIds() const QList<QUuid> ChannelView::getFilterIds() const
@ -3237,4 +3241,27 @@ void ChannelView::pendingLinkInfoStateChanged()
this->tooltipWidget_->applyLastBoundsCheck(); 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 } // namespace chatterino

View file

@ -215,6 +215,9 @@ public:
Scrollbar *scrollbar(); Scrollbar *scrollbar();
using ChannelViewID = std::size_t;
ChannelViewID getID() const;
pajlada::Signals::Signal<QMouseEvent *> mouseDown; pajlada::Signals::Signal<QMouseEvent *> mouseDown;
pajlada::Signals::NoArgSignal selectionChanged; pajlada::Signals::NoArgSignal selectionChanged;
pajlada::Signals::Signal<HighlightState, const MessagePtr &> pajlada::Signals::Signal<HighlightState, const MessagePtr &>
@ -318,6 +321,9 @@ private:
void showReplyThreadPopup(const MessagePtr &message); void showReplyThreadPopup(const MessagePtr &message);
bool canReplyToMessages() const; bool canReplyToMessages() const;
void updateID();
ChannelViewID id_{};
bool layoutQueued_ = false; bool layoutQueued_ = false;
bool bufferInvalidationQueued_ = false; bool bufferInvalidationQueued_ = false;

View file

@ -306,13 +306,13 @@ bool NotebookTab::isSelected() const
} }
void NotebookTab::removeNewMessageSource( void NotebookTab::removeNewMessageSource(
const HighlightSources::ChannelViewId &source) const ChannelView::ChannelViewID &source)
{ {
this->highlightSources_.newMessageSource.erase(source); this->highlightSources_.newMessageSource.erase(source);
} }
void NotebookTab::removeHighlightedSource( void NotebookTab::removeHighlightedSource(
const HighlightSources::ChannelViewId &source) const ChannelView::ChannelViewID &source)
{ {
this->highlightSources_.highlightedSource.erase(source); this->highlightSources_.highlightedSource.erase(source);
} }
@ -333,10 +333,7 @@ void NotebookTab::removeHighlightStateChangeSources(
void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource) void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
{ {
const auto &channelName = channelViewSource.underlyingChannel()->getName(); auto channelViewId = channelViewSource.getID();
const auto &channelFilterIds = channelViewSource.getFilterIds();
auto channelViewId =
HighlightSources::GetChannelViewId(channelName, channelFilterIds);
this->removeHighlightedSource(channelViewId); this->removeHighlightedSource(channelViewId);
this->removeNewMessageSource(channelViewId); this->removeNewMessageSource(channelViewId);
this->updateHighlightStateDueSourcesChange(); this->updateHighlightStateDueSourcesChange();
@ -556,10 +553,7 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,
// message is highlighting unvisible tab // message is highlighting unvisible tab
const auto &channelName = channelViewSource.underlyingChannel()->getName(); auto channelViewId = channelViewSource.getID();
const auto &channelFilterIds = channelViewSource.getFilterIds();
auto channelViewId =
HighlightSources::GetChannelViewId(channelName, channelFilterIds);
switch (newHighlightStyle) switch (newHighlightStyle)
{ {

View file

@ -126,23 +126,8 @@ private:
const MessagePtr &message) const; const MessagePtr &message) const;
struct HighlightSources { struct HighlightSources {
using ChannelViewId = std::size_t; std::unordered_set<ChannelView::ChannelViewID> newMessageSource;
std::unordered_set<ChannelView::ChannelViewID> highlightedSource;
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;
void clear() void clear()
{ {
@ -152,8 +137,8 @@ private:
} highlightSources_; } highlightSources_;
void removeHighlightStateChangeSources(const HighlightSources &toRemove); void removeHighlightStateChangeSources(const HighlightSources &toRemove);
void removeNewMessageSource(const HighlightSources::ChannelViewId &source); void removeNewMessageSource(const ChannelView::ChannelViewID &source);
void removeHighlightedSource(const HighlightSources::ChannelViewId &source); void removeHighlightedSource(const ChannelView::ChannelViewID &source);
void updateHighlightStateDueSourcesChange(); void updateHighlightStateDueSourcesChange();
QPropertyAnimation positionChangedAnimation_; QPropertyAnimation positionChangedAnimation_;