refactor: add Channel::addSystemMessage function (#5500)

This commit is contained in:
pajlada
2024-07-07 22:03:05 +02:00
committed by GitHub
parent 4535823ca8
commit 354079c74c
47 changed files with 443 additions and 588 deletions
-52
View File
@@ -1,52 +0,0 @@
#include "NotificationPopup.hpp"
#include "common/Channel.hpp"
#include "messages/Message.hpp"
#include "widgets/helper/ChannelView.hpp"
#include <QApplication>
#include <QScreen>
#include <QVBoxLayout>
namespace chatterino {
NotificationPopup::NotificationPopup()
: BaseWindow({BaseWindow::Frameless, BaseWindow::DisableLayoutSave})
, channel_(std::make_shared<Channel>("notifications", Channel::Type::None))
{
this->channelView_ = new ChannelView(this);
auto *layout = new QVBoxLayout(this);
this->setLayout(layout);
layout->addWidget(this->channelView_);
this->channelView_->setChannel(this->channel_);
this->setScaleIndependantSize(300, 150);
}
void NotificationPopup::updatePosition()
{
Location location = BottomRight;
const QRect rect = QGuiApplication::primaryScreen()->availableGeometry();
switch (location)
{
case BottomRight: {
this->move(rect.right() - this->width(),
rect.bottom() - this->height());
}
break;
}
}
void NotificationPopup::addMessage(MessagePtr msg)
{
this->channel_->addMessage(std::move(msg));
// QTimer::singleShot(5000, this, [this, msg] { this->channel->remove });
}
} // namespace chatterino
-29
View File
@@ -1,29 +0,0 @@
#pragma once
#include "widgets/BaseWindow.hpp"
namespace chatterino {
class ChannelView;
class Channel;
using ChannelPtr = std::shared_ptr<Channel>;
struct Message;
using MessagePtr = std::shared_ptr<const Message>;
class NotificationPopup : public BaseWindow
{
public:
enum Location { TopLeft, TopRight, BottomLeft, BottomRight };
NotificationPopup();
void addMessage(MessagePtr msg);
void updatePosition();
private:
ChannelView *channelView_;
ChannelPtr channel_;
};
} // namespace chatterino
+8 -8
View File
@@ -620,17 +620,17 @@ void UserInfoPopup::installEvents()
getIApp()->getAccounts()->twitch.getCurrent()->unblockUser(
this->userId_, this,
[this, reenableBlockCheckbox, currentUser] {
this->channel_->addMessage(makeSystemMessage(
this->channel_->addSystemMessage(
QString("You successfully unblocked user %1")
.arg(this->userName_)));
.arg(this->userName_));
reenableBlockCheckbox();
},
[this, reenableBlockCheckbox] {
this->channel_->addMessage(makeSystemMessage(
this->channel_->addSystemMessage(
QString(
"User %1 couldn't be unblocked, an unknown "
"error occurred!")
.arg(this->userName_)));
.arg(this->userName_));
reenableBlockCheckbox();
});
}
@@ -647,17 +647,17 @@ void UserInfoPopup::installEvents()
getIApp()->getAccounts()->twitch.getCurrent()->blockUser(
this->userId_, this,
[this, reenableBlockCheckbox, currentUser] {
this->channel_->addMessage(makeSystemMessage(
this->channel_->addSystemMessage(
QString("You successfully blocked user %1")
.arg(this->userName_)));
.arg(this->userName_));
reenableBlockCheckbox();
},
[this, reenableBlockCheckbox] {
this->channel_->addMessage(makeSystemMessage(
this->channel_->addSystemMessage(
QString(
"User %1 couldn't be blocked, an unknown "
"error occurred!")
.arg(this->userName_)));
.arg(this->userName_));
reenableBlockCheckbox();
});
}