mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
cache channel view id
This commit is contained in:
parent
0e4897969b
commit
1bdb118391
|
@ -1063,6 +1063,8 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel)
|
|||
|
||||
this->underlyingChannel_ = underlyingChannel;
|
||||
|
||||
this->updateID();
|
||||
|
||||
this->performLayout();
|
||||
this->queueUpdate();
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -215,6 +215,9 @@ public:
|
|||
|
||||
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 &>
|
||||
|
@ -318,6 +321,9 @@ private:
|
|||
void showReplyThreadPopup(const MessagePtr &message);
|
||||
bool canReplyToMessages() const;
|
||||
|
||||
void updateID();
|
||||
ChannelViewID id_{};
|
||||
|
||||
bool layoutQueued_ = false;
|
||||
bool bufferInvalidationQueued_ = false;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -126,23 +126,8 @@ private:
|
|||
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()
|
||||
{
|
||||
|
@ -152,8 +137,8 @@ private:
|
|||
} 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_;
|
||||
|
|
Loading…
Reference in a new issue