Compare commits

...

2 commits

Author SHA1 Message Date
hemirt
fec11f2d78
Merge 05ab3b27e7 into f66bc37368 2024-10-26 14:20:14 +00:00
unknown
05ab3b27e7 switch from using two sets to one map 2024-10-26 16:19:57 +02:00
2 changed files with 30 additions and 58 deletions

View file

@ -305,37 +305,25 @@ bool NotebookTab::isSelected() const
return this->selected_; return this->selected_;
} }
void NotebookTab::removeNewMessageSource(
const ChannelView::ChannelViewID &source)
{
this->highlightSources_.newMessageSource.erase(source);
}
void NotebookTab::removeHighlightedSource(
const ChannelView::ChannelViewID &source)
{
this->highlightSources_.highlightedSource.erase(source);
}
void NotebookTab::removeHighlightStateChangeSources( void NotebookTab::removeHighlightStateChangeSources(
const HighlightSources &toRemove) const HighlightSources &toRemove)
{ {
for (const auto &source : toRemove.newMessageSource) for (const auto &[source, _] : toRemove)
{ {
this->removeNewMessageSource(source); this->removeHighlightSource(source);
} }
}
for (const auto &source : toRemove.highlightedSource) void NotebookTab::removeHighlightSource(
{ const ChannelView::ChannelViewID &source)
this->removeHighlightedSource(source); {
} this->highlightSources_.erase(source);
} }
void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource) void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
{ {
auto channelViewId = channelViewSource.getID(); auto channelViewId = channelViewSource.getID();
this->removeHighlightedSource(channelViewId); this->removeHighlightSource(channelViewId);
this->removeNewMessageSource(channelViewId);
this->updateHighlightStateDueSourcesChange(); this->updateHighlightStateDueSourcesChange();
auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_); auto *splitNotebook = dynamic_cast<SplitNotebook *>(this->notebook_);
@ -350,8 +338,7 @@ void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
auto *tab = splitContainer->getTab(); auto *tab = splitContainer->getTab();
if (tab && tab != this) if (tab && tab != this)
{ {
tab->removeHighlightedSource(channelViewId); tab->removeHighlightSource(channelViewId);
tab->removeNewMessageSource(channelViewId);
tab->updateHighlightStateDueSourcesChange(); tab->updateHighlightStateDueSourcesChange();
} }
} }
@ -361,13 +348,17 @@ void NotebookTab::newHighlightSourceAdded(const ChannelView &channelViewSource)
void NotebookTab::updateHighlightStateDueSourcesChange() void NotebookTab::updateHighlightStateDueSourcesChange()
{ {
if (!this->highlightSources_.highlightedSource.empty()) if (std::ranges::any_of(this->highlightSources_, [](const auto &keyval) {
return keyval.second == HighlightState::Highlighted;
}))
{ {
assert(this->highlightState_ == HighlightState::Highlighted); assert(this->highlightState_ == HighlightState::Highlighted);
return; return;
} }
if (!this->highlightSources_.newMessageSource.empty()) if (std::ranges::any_of(this->highlightSources_, [](const auto &keyval) {
return keyval.second == HighlightState::NewMessage;
}))
{ {
if (this->highlightState_ != HighlightState::NewMessage) if (this->highlightState_ != HighlightState::NewMessage)
{ {
@ -391,8 +382,7 @@ void NotebookTab::copyHighlightStateAndSourcesFrom(const NotebookTab *sourceTab)
{ {
if (this->isSelected()) if (this->isSelected())
{ {
assert(this->highlightSources_.highlightedSource.empty()); assert(this->highlightSources_.empty());
assert(this->highlightSources_.newMessageSource.empty());
assert(this->highlightState_ == HighlightState::None); assert(this->highlightState_ == HighlightState::None);
return; return;
} }
@ -504,8 +494,7 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
{ {
if (this->isSelected()) if (this->isSelected())
{ {
assert(this->highlightSources_.highlightedSource.empty()); assert(this->highlightSources_.empty());
assert(this->highlightSources_.newMessageSource.empty());
assert(this->highlightState_ == HighlightState::None); assert(this->highlightState_ == HighlightState::None);
return; return;
} }
@ -534,8 +523,7 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,
{ {
if (this->isSelected()) if (this->isSelected())
{ {
assert(this->highlightSources_.highlightedSource.empty()); assert(this->highlightSources_.empty());
assert(this->highlightSources_.newMessageSource.empty());
assert(this->highlightState_ == HighlightState::None); assert(this->highlightState_ == HighlightState::None);
return; return;
} }
@ -557,19 +545,16 @@ void NotebookTab::updateHighlightState(HighlightState newHighlightStyle,
switch (newHighlightStyle) switch (newHighlightStyle)
{ {
case HighlightState::Highlighted: { case HighlightState::Highlighted:
if (!this->highlightSources_.highlightedSource.contains( // override lower states
channelViewId)) this->highlightSources_.insert_or_assign(channelViewId,
{ newHighlightStyle);
this->highlightSources_.highlightedSource.insert(channelViewId);
}
break;
}
case HighlightState::NewMessage: { case HighlightState::NewMessage: {
if (!this->highlightSources_.newMessageSource.contains( // only insert if no state already there to avoid overriding
channelViewId)) if (!this->highlightSources_.contains(channelViewId))
{ {
this->highlightSources_.newMessageSource.insert(channelViewId); this->highlightSources_.emplace(channelViewId,
newHighlightStyle);
} }
break; break;
} }

View file

@ -125,25 +125,12 @@ private:
bool shouldMessageHighlight(const ChannelView &channelViewSource, bool shouldMessageHighlight(const ChannelView &channelViewSource,
const MessagePtr &message) const; const MessagePtr &message) const;
struct HighlightSources { using HighlightSources =
// Source of the update to the highlight status is the split std::unordered_map<ChannelView::ChannelViewID, HighlightState>;
// in which a message that causes the update appears. HighlightSources highlightSources_;
// This message can be just a plain message causing the
// HighlightState::NewMessage state, or a message that pings the user
// causing the HighlightState::Highlighted state
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 removeHighlightStateChangeSources(const HighlightSources &toRemove);
void removeNewMessageSource(const ChannelView::ChannelViewID &source); void removeHighlightSource(const ChannelView::ChannelViewID &source);
void removeHighlightedSource(const ChannelView::ChannelViewID &source);
void updateHighlightStateDueSourcesChange(); void updateHighlightStateDueSourcesChange();
QPropertyAnimation positionChangedAnimation_; QPropertyAnimation positionChangedAnimation_;