Compare commits

..

1 commit

Author SHA1 Message Date
hemirt df9401f6a1
Merge 55c0e6980f into f66bc37368 2024-10-26 13:38:56 +02:00
2 changed files with 59 additions and 31 deletions

View file

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

View file

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