diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d1a159f..65c205198 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Minor: Added customizable timeout buttons to the user info popup - Minor: Deprecate loading of "v1" window layouts. If you haven't updated Chatterino in more than 2 years, there's a chance you will lose your window layout. - Minor: Disable checking for updates on unsupported platforms (#1874) +- Minor: User popup will now automatically display messages as they are received - Minor: Changed the English in two rate-limited system messages (#1878) - Bugfix: Fix bug preventing users from setting the highlight color of the second entry in the "User" highlights tab (#1898) - Bugfix: Fix bug where the "check user follow state" event could trigger a network request requesting the user to follow or unfollow a user. By itself its quite harmless as it just repeats to Twitch the same follow state we had, so no follows should have been lost by this but it meant there was a rogue network request that was fired that could cause a crash (#1906) diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index feee58076..0991790f3 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -53,6 +53,25 @@ namespace { return label.getElement(); }; + + bool checkMessageUserName(const QString &userName, MessagePtr message) + { + if (message->flags.has(MessageFlag::Whisper)) + return false; + + bool isSubscription = message->flags.has(MessageFlag::Subscription) && + message->loginName.isEmpty() && + message->messageText.split(" ").at(0).compare( + userName, Qt::CaseInsensitive) == 0; + + bool isModAction = + message->timeoutUser.compare(userName, Qt::CaseInsensitive) == 0; + bool isSelectedUser = + message->loginName.compare(userName, Qt::CaseInsensitive) == 0; + + return (isSubscription || isModAction || isSelectedUser); + } + ChannelPtr filterMessages(const QString &userName, ChannelPtr channel) { LimitedQueueSnapshot snapshot = @@ -64,20 +83,7 @@ namespace { for (size_t i = 0; i < snapshot.size(); i++) { MessagePtr message = snapshot[i]; - - bool isSubscription = - message->flags.has(MessageFlag::Subscription) && - message->loginName == "" && - message->messageText.split(" ").at(0).compare( - userName, Qt::CaseInsensitive) == 0; - - bool isModAction = message->timeoutUser.compare( - userName, Qt::CaseInsensitive) == 0; - bool isSelectedUser = - message->loginName.compare(userName, Qt::CaseInsensitive) == 0; - - if ((isSubscription || isModAction || isSelectedUser) && - !message->flags.has(MessageFlag::Whisper)) + if (checkMessageUserName(userName, message)) { channelPtr->addMessage(message); } @@ -292,6 +298,12 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically) this->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Policy::Ignored); } +// remove once https://github.com/pajlada/signals/pull/10 gets merged +UserInfoPopup::~UserInfoPopup() +{ + this->refreshConnection_.disconnect(); +} + void UserInfoPopup::themeChangedEvent() { BaseWindow::themeChangedEvent(); @@ -473,6 +485,30 @@ void UserInfoPopup::updateLatestMessages() const bool hasMessages = filteredChannel->hasMessages(); this->ui_.latestMessages->setVisible(hasMessages); this->ui_.noMessagesLabel->setVisible(!hasMessages); + + // shrink dialog in case ChannelView goes from visible to hidden + this->adjustSize(); + + this->refreshConnection_ + .disconnect(); // remove once https://github.com/pajlada/signals/pull/10 gets merged + + this->refreshConnection_ = this->channel_->messageAppended.connect( + [this, hasMessages](auto message, auto) { + if (!checkMessageUserName(this->userName_, message)) + return; + + if (hasMessages) + { + // display message in ChannelView + this->ui_.latestMessages->channel()->addMessage(message); + } + else + { + // The ChannelView is currently hidden, so manually refresh + // and display the latest messages + this->updateLatestMessages(); + } + }); } void UserInfoPopup::updateUserData() diff --git a/src/widgets/dialogs/UserInfoPopup.hpp b/src/widgets/dialogs/UserInfoPopup.hpp index 2523c2521..6970b3e2c 100644 --- a/src/widgets/dialogs/UserInfoPopup.hpp +++ b/src/widgets/dialogs/UserInfoPopup.hpp @@ -19,6 +19,7 @@ class UserInfoPopup final : public BaseWindow public: UserInfoPopup(bool closeAutomatically); + ~UserInfoPopup(); void setData(const QString &name, const ChannelPtr &channel); @@ -41,6 +42,9 @@ private: pajlada::Signals::NoArgSignal userStateChanged_; + // replace with ScopedConnection once https://github.com/pajlada/signals/pull/10 gets merged + pajlada::Signals::Connection refreshConnection_; + std::shared_ptr hack_; struct {