mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Auto-refresh UserInfoPopup recent messages (#1982)
* Auto-refresh UserInfoPopup recent messages * Update CHANGELOG.md * Clean up code * changed something about the connection Co-authored-by: fourtf <tf.four@gmail.com>
This commit is contained in:
parent
d314566ab6
commit
f7f858a4fc
3 changed files with 55 additions and 14 deletions
|
@ -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)
|
||||
|
|
|
@ -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<MessagePtr> 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()
|
||||
|
|
|
@ -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<bool> hack_;
|
||||
|
||||
struct {
|
||||
|
|
Loading…
Reference in a new issue