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 <sagedanielr@gmail.com>
This commit is contained in:
0xRainy
2020-06-21 05:15:14 -07:00
committed by GitHub
parent c5f6fd7568
commit 0e564065ba
7 changed files with 117 additions and 8 deletions
+75 -5
View File
@@ -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<MessagePtr> 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<EffectLabel2>(this);
usercard->getLabel().setText("Usercard");
auto refresh = user.emplace<EffectLabel2>(this);
refresh->getLabel().setText("Refresh");
auto mod = user.emplace<Button>(this);
mod->setPixmap(getResources().buttons.mod);
mod->setScaleIndependantSize(30, 30);
@@ -134,6 +170,8 @@ UserInfoPopup::UserInfoPopup()
"/viewercard/" + this->userName_);
});
QObject::connect(refresh.getElement(), &Button::leftClicked,
[this] { this->updateLatestMessages(); });
QObject::connect(mod.getElement(), &Button::leftClicked, [this] {
this->channel_->sendMessage("/mod " + this->userName_);
});
@@ -215,8 +253,25 @@ UserInfoPopup::UserInfoPopup()
});
}
this->installEvents();
layout.emplace<Line>(false);
// fourth line (last messages)
auto logs = layout.emplace<QVBoxLayout>().withoutMargin();
{
this->ui_.noMessagesLabel = new Label("No recent messages");
this->ui_.noMessagesLabel->setVisible(false);
this->ui_.latestMessages = new ChannelView(this);
this->ui_.latestMessages->setMinimumSize(400, 275);
this->ui_.latestMessages->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Expanding);
logs->addWidget(this->ui_.noMessagesLabel);
logs->addWidget(this->ui_.latestMessages);
logs->setAlignment(this->ui_.noMessagesLabel, Qt::AlignHCenter);
}
this->installEvents();
this->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Policy::Ignored);
}
@@ -358,6 +413,7 @@ void UserInfoPopup::setData(const QString &name, const ChannelPtr &channel)
{
this->userName_ = name;
this->channel_ = channel;
this->setWindowTitle(TEXT_TITLE.arg(name));
this->ui_.nameLabel->setText(name);
this->ui_.nameLabel->setProperty("copy-text", name);
@@ -365,6 +421,20 @@ void UserInfoPopup::setData(const QString &name, const ChannelPtr &channel)
this->updateUserData();
this->userStateChanged_.invoke();
this->updateLatestMessages();
QTimer::singleShot(1, this, [this] { this->setStayInScreenRect(true); });
}
void UserInfoPopup::updateLatestMessages()
{
auto filteredChannel = filterMessages(this->userName_, this->channel_);
this->ui_.latestMessages->setChannel(filteredChannel);
this->ui_.latestMessages->setSourceChannel(this->channel_);
const bool hasMessages = filteredChannel->hasMessages();
this->ui_.latestMessages->setVisible(hasMessages);
this->ui_.noMessagesLabel->setVisible(!hasMessages);
}
void UserInfoPopup::updateUserData()