From 0e564065bac470e6e711b60597b9a3b2b4822d90 Mon Sep 17 00:00:00 2001 From: 0xRainy <35612912+0xRainy@users.noreply.github.com> Date: Sun, 21 Jun 2020 05:15:14 -0700 Subject: [PATCH] Added recent messages to UserInfoPopup (#1729) There's a Refresh button added to the popup to refresh the users messages in the popup. Not automatic now while we figure out how fast/slow it would be. Co-authored-by: dnsge --- src/common/Channel.cpp | 5 ++ src/common/Channel.hpp | 2 + src/messages/LimitedQueue.hpp | 7 ++- src/widgets/dialogs/UserInfoPopup.cpp | 80 +++++++++++++++++++++++++-- src/widgets/dialogs/UserInfoPopup.hpp | 6 ++ src/widgets/helper/ChannelView.cpp | 20 ++++++- src/widgets/helper/ChannelView.hpp | 5 ++ 7 files changed, 117 insertions(+), 8 deletions(-) diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index 43e88ee38..45280662b 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -59,6 +59,11 @@ bool Channel::isEmpty() const return this->name_.isEmpty(); } +bool Channel::hasMessages() const +{ + return !this->messages_.empty(); +} + LimitedQueueSnapshot Channel::getMessageSnapshot() { return this->messages_.getSnapshot(); diff --git a/src/common/Channel.hpp b/src/common/Channel.hpp index f484235ac..71eac8cd4 100644 --- a/src/common/Channel.hpp +++ b/src/common/Channel.hpp @@ -75,6 +75,8 @@ public: void deleteMessage(QString messageID); void clearMessages(); + bool hasMessages() const; + QStringList modList; // CHANNEL INFO diff --git a/src/messages/LimitedQueue.hpp b/src/messages/LimitedQueue.hpp index 22d1385eb..f206704f5 100644 --- a/src/messages/LimitedQueue.hpp +++ b/src/messages/LimitedQueue.hpp @@ -223,8 +223,13 @@ public: this->firstChunkOffset_, this->lastChunkEnd_); } + bool empty() const + { + return this->limit_ - this->space() == 0; + } + private: - qsizetype space() + qsizetype space() const { size_t totalSize = 0; for (auto &chunk : *this->chunks_) diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index dd3585e7b..34b178f99 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -5,6 +5,7 @@ #include "common/NetworkRequest.hpp" #include "controllers/accounts/AccountController.hpp" #include "controllers/highlights/HighlightBlacklistUser.hpp" +#include "messages/Message.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/api/Helix.hpp" #include "providers/twitch/api/Kraken.hpp" @@ -14,6 +15,7 @@ #include "util/PostToThread.hpp" #include "util/Shortcut.hpp" #include "widgets/Label.hpp" +#include "widgets/helper/ChannelView.hpp" #include "widgets/helper/EffectLabel.hpp" #include "widgets/helper/Line.hpp" @@ -26,6 +28,7 @@ const QString TEXT_VIEWS("Views: %1"); const QString TEXT_FOLLOWERS("Followers: %1"); const QString TEXT_CREATED("Created: %1"); +const QString TEXT_TITLE("%1's Usercard"); #define TEXT_USER_ID "ID: " #define TEXT_UNAVAILABLE "(not available)" @@ -49,16 +52,48 @@ namespace { return label.getElement(); }; + ChannelPtr filterMessages(const QString &userName, ChannelPtr channel) + { + LimitedQueueSnapshot snapshot = + channel->getMessageSnapshot(); + + ChannelPtr channelPtr( + new Channel(channel->getName(), Channel::Type::None)); + + 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)) + { + channelPtr->addMessage(message); + } + } + + return channelPtr; + }; } // namespace UserInfoPopup::UserInfoPopup() - : BaseWindow({BaseWindow::Frameless, BaseWindow::FramelessDraggable}) + : BaseWindow(BaseWindow::EnableCustomFrame) , hack_(new bool) { + this->setWindowTitle("Usercard"); this->setStayInScreenRect(true); - #ifdef Q_OS_LINUX - this->setWindowFlag(Qt::Popup); + this->setWindowFlag(Qt::Dialog); #endif // Close the popup when Escape is pressed @@ -118,7 +153,8 @@ UserInfoPopup::UserInfoPopup() .assign(&this->ui_.ignoreHighlights); auto usercard = user.emplace(this); usercard->getLabel().setText("Usercard"); - + auto refresh = user.emplace(this); + refresh->getLabel().setText("Refresh"); auto mod = user.emplace