Compare commits

...

3 commits

Author SHA1 Message Date
unknown
1bdb118391 cache channel view id 2024-10-23 01:29:37 +02:00
unknown
0e4897969b replace ChannelViewProxy with ChannelViewId 2024-10-23 00:57:57 +02:00
unknown
374e0c5fa0 remove leftovers 2024-10-23 00:28:47 +02:00
5 changed files with 49 additions and 70 deletions

View file

@ -2,7 +2,6 @@
#include "widgets/BaseWidget.hpp"
#include <ForwardDecl.hpp>
#include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp>
#include <QList>

View file

@ -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

View file

@ -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;

View file

@ -56,27 +56,6 @@ namespace {
}
} // namespace
std::size_t NotebookTab::HighlightSources::ChannelViewProxyHash::operator()(
const ChannelViewProxy &cp) const noexcept
{
std::size_t seed = 0;
auto first = qHash(cp.channelView->underlyingChannel()->getName());
auto second = qHash(cp.channelView->getFilterIds());
boost::hash_combine(seed, first);
boost::hash_combine(seed, second);
return seed;
}
bool NotebookTab::HighlightSources::ChannelViewProxyEqual::operator()(
const ChannelViewProxy &lp, const ChannelViewProxy &rp) const
{
return lp.channelView->underlyingChannel() ==
rp.channelView->underlyingChannel() &&
lp.channelView->getFilterIds() == rp.channelView->getFilterIds();
}
NotebookTab::NotebookTab(Notebook *notebook)
: Button(notebook)
, positionChangedAnimation_(this, "pos")
@ -327,13 +306,13 @@ bool NotebookTab::isSelected() const
}
void NotebookTab::removeNewMessageSource(
const HighlightSources::ChannelViewProxy &source)
const ChannelView::ChannelViewID &source)
{
this->highlightSources_.newMessageSource.erase(source);
}
void NotebookTab::removeHighlightedSource(
const HighlightSources::ChannelViewProxy &source)
const ChannelView::ChannelViewID &source)
{
this->highlightSources_.highlightedSource.erase(source);
}
@ -354,11 +333,9 @@ void NotebookTab::removeHighlightStateChangeSources(
void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
{
auto channelViewProxy =
HighlightSources::ChannelViewProxy{&channelViewSource};
auto sourceChannel = channelViewSource.underlyingChannel();
this->removeHighlightedSource(channelViewProxy);
this->removeNewMessageSource(channelViewProxy);
auto channelViewId = channelViewSource.getID();
this->removeHighlightedSource(channelViewId);
this->removeNewMessageSource(channelViewId);
this->updateHighlightStateDueSourcesChange();
auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_);
@ -373,8 +350,8 @@ void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
auto *tab = splitContainer->getTab();
if (tab && tab != this)
{
tab->removeHighlightedSource(channelViewProxy);
tab->removeNewMessageSource(channelViewProxy);
tab->removeHighlightedSource(channelViewId);
tab->removeNewMessageSource(channelViewId);
tab->updateHighlightStateDueSourcesChange();
}
}
@ -576,32 +553,23 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,
// message is highlighting unvisible tab
auto underlyingChannel = channelViewSource.underlyingChannel();
auto newFilters = channelViewSource.getFilterIds();
auto channelViewProxy =
HighlightSources::ChannelViewProxy{&channelViewSource};
// the unvisible tab should unhighlight other tabs iff
// the other tab's filters are more generic therefore
// the other tab's filter set is subset of the unvisible tab
auto channelViewId = channelViewSource.getID();
switch (newHighlightStyle)
{
case HighlightState::Highlighted: {
if (!this->highlightSources_.highlightedSource.contains(
channelViewProxy))
channelViewId))
{
this->highlightSources_.highlightedSource.insert(
channelViewProxy);
this->highlightSources_.highlightedSource.insert(channelViewId);
}
break;
}
case HighlightState::NewMessage: {
if (!this->highlightSources_.newMessageSource.contains(
channelViewProxy))
channelViewId))
{
this->highlightSources_.newMessageSource.insert(
channelViewProxy);
this->highlightSources_.newMessageSource.insert(channelViewId);
}
break;
}

View file

@ -126,40 +126,19 @@ private:
const MessagePtr &message) const;
struct HighlightSources {
struct ChannelViewProxy {
const ChannelView *channelView;
};
struct ChannelViewProxyHash {
using is_transparent = void;
std::size_t operator()(const ChannelViewProxy &cp) const noexcept;
};
struct ChannelViewProxyEqual {
bool operator()(const ChannelViewProxy &l,
const ChannelViewProxy &r) const;
};
std::unordered_set<ChannelViewProxy, ChannelViewProxyHash,
ChannelViewProxyEqual>
newMessageSource;
std::unordered_set<ChannelViewProxy, ChannelViewProxyHash,
ChannelViewProxyEqual>
highlightedSource;
std::unordered_set<ChannelView::ChannelViewID> newMessageSource;
std::unordered_set<ChannelView::ChannelViewID> highlightedSource;
void clear()
{
this->newMessageSource.clear();
this->highlightedSource.clear();
}
} highlightSources_;
void removeHighlightStateChangeSources(const HighlightSources &toRemove);
void removeNewMessageSource(
const HighlightSources::ChannelViewProxy &source);
void removeHighlightedSource(
const HighlightSources::ChannelViewProxy &source);
void removeNewMessageSource(const ChannelView::ChannelViewID &source);
void removeHighlightedSource(const ChannelView::ChannelViewID &source);
void updateHighlightStateDueSourcesChange();
QPropertyAnimation positionChangedAnimation_;