From 47c46b64eaaf5eb9689810e8cc88b4ce85f3b683 Mon Sep 17 00:00:00 2001 From: nerix Date: Sat, 16 Mar 2024 13:03:57 +0100 Subject: [PATCH] fix(channel-view): use `underlyingChannel_` over `channel_` (#5248) --- CHANGELOG.md | 1 + src/widgets/helper/ChannelView.cpp | 72 ++++++++++++++++-------------- src/widgets/helper/ChannelView.hpp | 40 +++++++++++++++++ 3 files changed, 80 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04989684..6462cc96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,6 +109,7 @@ - Bugfix: Fixed the "Cancel" button in the settings dialog only working after opening the settings dialog twice. (#5229) - Bugfix: Fixed split header tooltips showing in the wrong position on Windows. (#5230) - Bugfix: Fixed split header tooltips appearing too tall. (#5232) +- Bugfix: Fixed past messages not showing in the search popup after adding a channel. (#5248) - Dev: Run miniaudio in a separate thread, and simplify it to not manage the device ourselves. There's a chance the simplification is a bad idea. (#4978) - Dev: Change clang-format from v14 to v16. (#4929) - Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 0cac3913..3a38cadf 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -453,7 +453,8 @@ void ChannelView::initializeSignals() this->signalHolder_.managedConnect( getIApp()->getWindows()->layoutRequested, [&](Channel *channel) { if (this->isVisible() && - (channel == nullptr || this->channel_.get() == channel)) + (channel == nullptr || + this->underlyingChannel_.get() == channel)) { this->queueLayout(); } @@ -463,7 +464,8 @@ void ChannelView::initializeSignals() getIApp()->getWindows()->invalidateBuffersRequested, [this](Channel *channel) { if (this->isVisible() && - (channel == nullptr || this->channel_.get() == channel)) + (channel == nullptr || + this->underlyingChannel_.get() == channel)) { this->invalidateBuffers(); } @@ -975,6 +977,41 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel) this->channel_->fillInMissingMessages(filtered); }); + // Copy over messages from the backing channel to the filtered one + // and the ui. + auto snapshot = underlyingChannel->getMessageSnapshot(); + + this->scrollBar_->setMaximum(qreal(snapshot.size())); + + for (const auto &msg : snapshot) + { + if (!this->shouldIncludeMessage(msg)) + { + continue; + } + + auto messageLayout = std::make_shared(msg); + + if (this->lastMessageHasAlternateBackground_) + { + messageLayout->flags.set(MessageLayoutFlag::AlternateBackground); + } + this->lastMessageHasAlternateBackground_ = + !this->lastMessageHasAlternateBackground_; + + if (underlyingChannel->shouldIgnoreHighlights()) + { + messageLayout->flags.set(MessageLayoutFlag::IgnoreHighlights); + } + + this->messages_.pushBack(messageLayout); + this->channel_->addMessage(msg); + if (this->showScrollbarHighlights()) + { + this->scrollBar_->addHighlight(msg->getScrollBarHighlight()); + } + } + // // Standard channel connections // @@ -1006,33 +1043,6 @@ void ChannelView::setChannel(const ChannelPtr &underlyingChannel) this->messagesUpdated(); }); - auto snapshot = underlyingChannel->getMessageSnapshot(); - - this->scrollBar_->setMaximum(qreal(snapshot.size())); - - for (const auto &msg : snapshot) - { - auto messageLayout = std::make_shared(msg); - - if (this->lastMessageHasAlternateBackground_) - { - messageLayout->flags.set(MessageLayoutFlag::AlternateBackground); - } - this->lastMessageHasAlternateBackground_ = - !this->lastMessageHasAlternateBackground_; - - if (underlyingChannel->shouldIgnoreHighlights()) - { - messageLayout->flags.set(MessageLayoutFlag::IgnoreHighlights); - } - - this->messages_.pushBack(messageLayout); - if (this->showScrollbarHighlights()) - { - this->scrollBar_->addHighlight(msg->getScrollBarHighlight()); - } - } - this->underlyingChannel_ = underlyingChannel; this->performLayout(); @@ -2991,10 +3001,6 @@ void ChannelView::setInputReply(const MessagePtr &message) // Message did not already have a thread attached, try to find or create one auto *tc = dynamic_cast(this->underlyingChannel_.get()); - if (!tc) - { - tc = dynamic_cast(this->channel_.get()); - } if (tc) { diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 50156c5e..e6cb7597 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -139,15 +139,32 @@ public: MessageElementFlags getFlags() const; + /// @brief The virtual channel used to display messages + /// + /// This channel contains all messages in this view and respects the + /// filter settings. It will always be of type Channel, not TwitchChannel + /// nor IrcChannel. + /// It's **not** equal to the channel passed in #setChannel(). ChannelPtr channel(); + + /// Set the channel this view is displaying void setChannel(const ChannelPtr &underlyingChannel); void setFilters(const QList &ids); QList getFilterIds() const; FilterSetPtr getFilterSet() const; + /// @brief The channel this is derived from + /// + /// In case of "nested" channel views such as in user popups, + /// this channel is set to the original channel the messages came from, + /// which is used to open user popups from this view. + /// It's not always set. + /// @see #hasSourceChannel() ChannelPtr sourceChannel() const; + /// Setter for #sourceChannel() void setSourceChannel(ChannelPtr sourceChannel); + /// Checks if this view has a #sourceChannel bool hasSourceChannel() const; LimitedQueueSnapshot &getMessagesSnapshot(); @@ -300,8 +317,31 @@ private: ThreadGuard snapshotGuard_; LimitedQueueSnapshot snapshot_; + /// @brief The backing (internal) channel + /// + /// This is a "virtual" channel where all filtered messages from + /// @a underlyingChannel_ are added to. It contains messages visible on + /// screen and will always be a @a Channel, or, it will never be a + /// TwitchChannel or IrcChannel, however, it will have the same type and + /// name as @a underlyingChannel_. It's not know to any registry/server. ChannelPtr channel_ = nullptr; + + /// @brief The channel receiving messages + /// + /// This channel is the one passed in #setChannel(). It's known to the + /// respective registry (e.g. TwitchIrcServer). For Twitch channels for + /// example, this will be an instance of TwitchChannel. This channel might + /// contain more messages than visible if filters are active. ChannelPtr underlyingChannel_ = nullptr; + + /// @brief The channel @a underlyingChannel_ is derived from + /// + /// In case of "nested" channel views such as in user popups, + /// this channel is set to the original channel the messages came from, + /// which is used to open user popups from this view. + /// + /// @see #sourceChannel() + /// @see #hasSourceChannel() ChannelPtr sourceChannel_ = nullptr; Split *split_;