mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
replace ChannelViewProxy with ChannelViewId
This commit is contained in:
parent
374e0c5fa0
commit
0e4897969b
|
@ -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 HighlightSources::ChannelViewId &source)
|
||||
{
|
||||
this->highlightSources_.newMessageSource.erase(source);
|
||||
}
|
||||
|
||||
void NotebookTab::removeHighlightedSource(
|
||||
const HighlightSources::ChannelViewProxy &source)
|
||||
const HighlightSources::ChannelViewId &source)
|
||||
{
|
||||
this->highlightSources_.highlightedSource.erase(source);
|
||||
}
|
||||
|
@ -354,10 +333,12 @@ void NotebookTab::removeHighlightStateChangeSources(
|
|||
|
||||
void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
|
||||
{
|
||||
auto channelViewProxy =
|
||||
HighlightSources::ChannelViewProxy{&channelViewSource};
|
||||
this->removeHighlightedSource(channelViewProxy);
|
||||
this->removeNewMessageSource(channelViewProxy);
|
||||
const auto &channelName = channelViewSource.underlyingChannel()->getName();
|
||||
const auto &channelFilterIds = channelViewSource.getFilterIds();
|
||||
auto channelViewId =
|
||||
HighlightSources::GetChannelViewId(channelName, channelFilterIds);
|
||||
this->removeHighlightedSource(channelViewId);
|
||||
this->removeNewMessageSource(channelViewId);
|
||||
this->updateHighlightStateDueSourcesChange();
|
||||
|
||||
auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_);
|
||||
|
@ -372,8 +353,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();
|
||||
}
|
||||
}
|
||||
|
@ -575,28 +556,26 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,
|
|||
|
||||
// message is highlighting unvisible tab
|
||||
|
||||
auto underlyingChannel = channelViewSource.underlyingChannel();
|
||||
auto newFilters = channelViewSource.getFilterIds();
|
||||
auto channelViewProxy =
|
||||
HighlightSources::ChannelViewProxy{&channelViewSource};
|
||||
const auto &channelName = channelViewSource.underlyingChannel()->getName();
|
||||
const auto &channelFilterIds = channelViewSource.getFilterIds();
|
||||
auto channelViewId =
|
||||
HighlightSources::GetChannelViewId(channelName, channelFilterIds);
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -126,40 +126,34 @@ private:
|
|||
const MessagePtr &message) const;
|
||||
|
||||
struct HighlightSources {
|
||||
struct ChannelViewProxy {
|
||||
const ChannelView *channelView;
|
||||
};
|
||||
using ChannelViewId = std::size_t;
|
||||
|
||||
struct ChannelViewProxyHash {
|
||||
using is_transparent = void;
|
||||
std::size_t operator()(const ChannelViewProxy &cp) const noexcept;
|
||||
};
|
||||
static ChannelViewId GetChannelViewId(
|
||||
const QString &channelName, const QList<QUuid> &channelFilterIds)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
auto first = qHash(channelName);
|
||||
auto second = qHash(channelFilterIds);
|
||||
|
||||
struct ChannelViewProxyEqual {
|
||||
bool operator()(const ChannelViewProxy &l,
|
||||
const ChannelViewProxy &r) const;
|
||||
};
|
||||
boost::hash_combine(seed, first);
|
||||
boost::hash_combine(seed, second);
|
||||
|
||||
std::unordered_set<ChannelViewProxy, ChannelViewProxyHash,
|
||||
ChannelViewProxyEqual>
|
||||
newMessageSource;
|
||||
std::unordered_set<ChannelViewProxy, ChannelViewProxyHash,
|
||||
ChannelViewProxyEqual>
|
||||
highlightedSource;
|
||||
return seed;
|
||||
}
|
||||
|
||||
std::unordered_set<ChannelViewId> newMessageSource;
|
||||
std::unordered_set<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 HighlightSources::ChannelViewId &source);
|
||||
void removeHighlightedSource(const HighlightSources::ChannelViewId &source);
|
||||
void updateHighlightStateDueSourcesChange();
|
||||
|
||||
QPropertyAnimation positionChangedAnimation_;
|
||||
|
|
Loading…
Reference in a new issue