mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Enable ban and kick button in UserProfile (and try to fix centering)
This commit is contained in:
parent
a07e699811
commit
b541cecd2e
4 changed files with 97 additions and 90 deletions
162
src/ChatPage.cpp
162
src/ChatPage.cpp
|
@ -280,87 +280,10 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
|
|||
connect(text_input_, &TextInputWidget::sendJoinRoomRequest, this, &ChatPage::joinRoom);
|
||||
|
||||
// invites and bans via quick command
|
||||
connect(text_input_,
|
||||
&TextInputWidget::sendInviteRoomRequest,
|
||||
this,
|
||||
[this](QString userid, QString reason) {
|
||||
http::client()->invite_user(
|
||||
current_room_.toStdString(),
|
||||
userid.toStdString(),
|
||||
[this, userid, room = current_room_](const mtx::responses::Empty &,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
emit showNotification(tr("Failed to invite %1 to %2: %3")
|
||||
.arg(userid)
|
||||
.arg(room)
|
||||
.arg(QString::fromStdString(
|
||||
err->matrix_error.error)));
|
||||
} else
|
||||
emit showNotification(tr("Invited user: %1").arg(userid));
|
||||
},
|
||||
reason.trimmed().toStdString());
|
||||
});
|
||||
connect(text_input_,
|
||||
&TextInputWidget::sendKickRoomRequest,
|
||||
this,
|
||||
[this](QString userid, QString reason) {
|
||||
http::client()->kick_user(
|
||||
current_room_.toStdString(),
|
||||
userid.toStdString(),
|
||||
[this, userid, room = current_room_](const mtx::responses::Empty &,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
emit showNotification(tr("Failed to kick %1 to %2: %3")
|
||||
.arg(userid)
|
||||
.arg(room)
|
||||
.arg(QString::fromStdString(
|
||||
err->matrix_error.error)));
|
||||
} else
|
||||
emit showNotification(tr("Kicked user: %1").arg(userid));
|
||||
},
|
||||
reason.trimmed().toStdString());
|
||||
});
|
||||
connect(text_input_,
|
||||
&TextInputWidget::sendBanRoomRequest,
|
||||
this,
|
||||
[this](QString userid, QString reason) {
|
||||
http::client()->ban_user(
|
||||
current_room_.toStdString(),
|
||||
userid.toStdString(),
|
||||
[this, userid, room = current_room_](const mtx::responses::Empty &,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
emit showNotification(tr("Failed to ban %1 in %2: %3")
|
||||
.arg(userid)
|
||||
.arg(room)
|
||||
.arg(QString::fromStdString(
|
||||
err->matrix_error.error)));
|
||||
} else
|
||||
emit showNotification(tr("Banned user: %1").arg(userid));
|
||||
},
|
||||
reason.trimmed().toStdString());
|
||||
});
|
||||
connect(
|
||||
text_input_,
|
||||
&TextInputWidget::sendUnbanRoomRequest,
|
||||
this,
|
||||
[this](QString userid, QString reason) {
|
||||
http::client()->unban_user(
|
||||
current_room_.toStdString(),
|
||||
userid.toStdString(),
|
||||
[this, userid, room = current_room_](const mtx::responses::Empty &,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
emit showNotification(
|
||||
tr("Failed to unban %1 in %2: %3")
|
||||
.arg(userid)
|
||||
.arg(room)
|
||||
.arg(QString::fromStdString(err->matrix_error.error)));
|
||||
} else
|
||||
emit showNotification(tr("Unbanned user: %1").arg(userid));
|
||||
},
|
||||
reason.trimmed().toStdString());
|
||||
});
|
||||
connect(text_input_, &TextInputWidget::sendInviteRoomRequest, this, &ChatPage::inviteUser);
|
||||
connect(text_input_, &TextInputWidget::sendKickRoomRequest, this, &ChatPage::kickUser);
|
||||
connect(text_input_, &TextInputWidget::sendBanRoomRequest, this, &ChatPage::banUser);
|
||||
connect(text_input_, &TextInputWidget::sendUnbanRoomRequest, this, &ChatPage::unbanUser);
|
||||
|
||||
connect(
|
||||
text_input_,
|
||||
|
@ -1138,6 +1061,83 @@ ChatPage::leaveRoom(const QString &room_id)
|
|||
});
|
||||
}
|
||||
|
||||
void
|
||||
ChatPage::inviteUser(QString userid, QString reason)
|
||||
{
|
||||
http::client()->invite_user(
|
||||
current_room_.toStdString(),
|
||||
userid.toStdString(),
|
||||
[this, userid, room = current_room_](const mtx::responses::Empty &,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
emit showNotification(
|
||||
tr("Failed to invite %1 to %2: %3")
|
||||
.arg(userid)
|
||||
.arg(room)
|
||||
.arg(QString::fromStdString(err->matrix_error.error)));
|
||||
} else
|
||||
emit showNotification(tr("Invited user: %1").arg(userid));
|
||||
},
|
||||
reason.trimmed().toStdString());
|
||||
}
|
||||
void
|
||||
ChatPage::kickUser(QString userid, QString reason)
|
||||
{
|
||||
http::client()->kick_user(
|
||||
current_room_.toStdString(),
|
||||
userid.toStdString(),
|
||||
[this, userid, room = current_room_](const mtx::responses::Empty &,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
emit showNotification(
|
||||
tr("Failed to kick %1 to %2: %3")
|
||||
.arg(userid)
|
||||
.arg(room)
|
||||
.arg(QString::fromStdString(err->matrix_error.error)));
|
||||
} else
|
||||
emit showNotification(tr("Kicked user: %1").arg(userid));
|
||||
},
|
||||
reason.trimmed().toStdString());
|
||||
}
|
||||
void
|
||||
ChatPage::banUser(QString userid, QString reason)
|
||||
{
|
||||
http::client()->ban_user(
|
||||
current_room_.toStdString(),
|
||||
userid.toStdString(),
|
||||
[this, userid, room = current_room_](const mtx::responses::Empty &,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
emit showNotification(
|
||||
tr("Failed to ban %1 in %2: %3")
|
||||
.arg(userid)
|
||||
.arg(room)
|
||||
.arg(QString::fromStdString(err->matrix_error.error)));
|
||||
} else
|
||||
emit showNotification(tr("Banned user: %1").arg(userid));
|
||||
},
|
||||
reason.trimmed().toStdString());
|
||||
}
|
||||
void
|
||||
ChatPage::unbanUser(QString userid, QString reason)
|
||||
{
|
||||
http::client()->unban_user(
|
||||
current_room_.toStdString(),
|
||||
userid.toStdString(),
|
||||
[this, userid, room = current_room_](const mtx::responses::Empty &,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
emit showNotification(
|
||||
tr("Failed to unban %1 in %2: %3")
|
||||
.arg(userid)
|
||||
.arg(room)
|
||||
.arg(QString::fromStdString(err->matrix_error.error)));
|
||||
} else
|
||||
emit showNotification(tr("Unbanned user: %1").arg(userid));
|
||||
},
|
||||
reason.trimmed().toStdString());
|
||||
}
|
||||
|
||||
void
|
||||
ChatPage::sendTypingNotifications()
|
||||
{
|
||||
|
|
|
@ -90,6 +90,11 @@ public slots:
|
|||
void leaveRoom(const QString &room_id);
|
||||
void createRoom(const mtx::requests::CreateRoom &req);
|
||||
|
||||
void inviteUser(QString userid, QString reason);
|
||||
void kickUser(QString userid, QString reason);
|
||||
void banUser(QString userid, QString reason);
|
||||
void unbanUser(QString userid, QString reason);
|
||||
|
||||
signals:
|
||||
void connectionLost();
|
||||
void connectionRestored();
|
||||
|
|
|
@ -613,7 +613,8 @@ utils::centerWidget(QWidget *widget, QWidget *parent)
|
|||
};
|
||||
|
||||
if (parent) {
|
||||
widget->move(findCenter(parent->geometry()));
|
||||
widget->move(parent->window()->frameGeometry().topLeft() +
|
||||
parent->window()->rect().center() - widget->rect().center());
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ UserProfile::UserProfile(QWidget *parent)
|
|||
{
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
QIcon banIcon, kickIcon, ignoreIcon, startChatIcon;
|
||||
|
@ -61,7 +60,6 @@ UserProfile::UserProfile(QWidget *parent)
|
|||
banBtn_->setIcon(banIcon);
|
||||
banBtn_->setIconSize(QSize(BUTTON_RADIUS, BUTTON_RADIUS));
|
||||
banBtn_->setToolTip(tr("Ban the user from the room"));
|
||||
banBtn_->setDisabled(true); // Not used yet.
|
||||
|
||||
ignoreIcon.addFile(":/icons/icons/ui/volume-off-indicator.png");
|
||||
ignoreBtn_ = new FlatButton(this);
|
||||
|
@ -79,7 +77,6 @@ UserProfile::UserProfile(QWidget *parent)
|
|||
kickBtn_->setIcon(kickIcon);
|
||||
kickBtn_->setIconSize(QSize(BUTTON_RADIUS, BUTTON_RADIUS));
|
||||
kickBtn_->setToolTip(tr("Kick the user from the room"));
|
||||
kickBtn_->setDisabled(true); // Not used yet.
|
||||
|
||||
startChatIcon.addFile(":/icons/icons/ui/black-bubble-speech.png");
|
||||
startChat_ = new FlatButton(this);
|
||||
|
@ -102,6 +99,13 @@ UserProfile::UserProfile(QWidget *parent)
|
|||
emit ChatPage::instance()->createRoom(req);
|
||||
});
|
||||
|
||||
connect(banBtn_, &QPushButton::clicked, this, [this] {
|
||||
ChatPage::instance()->banUser(userIdLabel_->text(), "");
|
||||
});
|
||||
connect(kickBtn_, &QPushButton::clicked, this, [this] {
|
||||
ChatPage::instance()->kickUser(userIdLabel_->text(), "");
|
||||
});
|
||||
|
||||
// Button line
|
||||
auto btnLayout = new QHBoxLayout;
|
||||
btnLayout->addStretch(1);
|
||||
|
@ -166,10 +170,6 @@ UserProfile::UserProfile(QWidget *parent)
|
|||
vlayout->setAlignment(avatar_, Qt::AlignCenter | Qt::AlignTop);
|
||||
vlayout->setAlignment(userIdLabel_, Qt::AlignCenter | Qt::AlignTop);
|
||||
|
||||
setAutoFillBackground(true);
|
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
||||
setWindowModality(Qt::WindowModal);
|
||||
|
||||
QFont largeFont;
|
||||
largeFont.setPointSizeF(largeFont.pointSizeF() * 1.5);
|
||||
|
||||
|
@ -180,7 +180,8 @@ UserProfile::UserProfile(QWidget *parent)
|
|||
vlayout->setSpacing(WIDGET_SPACING);
|
||||
vlayout->setContentsMargins(WIDGET_MARGIN, TOP_WIDGET_MARGIN, WIDGET_MARGIN, WIDGET_MARGIN);
|
||||
|
||||
qRegisterMetaType<std::vector<DeviceInfo>>();
|
||||
static auto ignored = qRegisterMetaType<std::vector<DeviceInfo>>();
|
||||
(void)ignored;
|
||||
|
||||
auto closeShortcut = new QShortcut(QKeySequence(QKeySequence::Cancel), this);
|
||||
connect(closeShortcut, &QShortcut::activated, this, &UserProfile::close);
|
||||
|
|
Loading…
Reference in a new issue