Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(channel-view): use underlyingChannel_ over channel_ #5248

Merged
merged 6 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
72 changes: 39 additions & 33 deletions src/widgets/helper/ChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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<MessageLayout>(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
//
Expand Down Expand Up @@ -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<MessageLayout>(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();
Expand Down Expand Up @@ -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<TwitchChannel *>(this->underlyingChannel_.get());
if (!tc)
{
tc = dynamic_cast<TwitchChannel *>(this->channel_.get());
}

if (tc)
{
Expand Down
40 changes: 40 additions & 0 deletions src/widgets/helper/ChannelView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,32 @@ class ChannelView final : public BaseWidget

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<QUuid> &ids);
QList<QUuid> 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<MessageLayoutPtr> &getMessagesSnapshot();
Expand Down Expand Up @@ -300,8 +317,31 @@ class ChannelView final : public BaseWidget
ThreadGuard snapshotGuard_;
LimitedQueueSnapshot<MessageLayoutPtr> 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_;

Expand Down
Loading