refactor: add Channel::addSystemMessage function (#5500)
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -393,10 +393,10 @@ Split::Split(QWidget *parent)
|
||||
imageUploader->getImages(original);
|
||||
if (images.empty())
|
||||
{
|
||||
channel->addMessage(makeSystemMessage(
|
||||
channel->addSystemMessage(
|
||||
QString(
|
||||
"An error occurred trying to process your image: %1")
|
||||
.arg(imageProcessError)));
|
||||
.arg(imageProcessError));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user