mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Add /knock command
This commit is contained in:
parent
cb76777fce
commit
c91f91d5d3
4 changed files with 25 additions and 2 deletions
|
@ -157,6 +157,9 @@ Send a message as a rainbow-colored notice.
|
|||
*/join* _<roomname>_::
|
||||
Join a room.
|
||||
|
||||
*/knock* _<roomname>_::
|
||||
Ask to join a room.
|
||||
|
||||
*/part*, */leave*::
|
||||
Leave the current room.
|
||||
|
||||
|
|
|
@ -658,6 +658,25 @@ ChatPage::trySync()
|
|||
});
|
||||
}
|
||||
|
||||
void
|
||||
ChatPage::knockRoom(const QString &room)
|
||||
{
|
||||
const auto room_id = room.toStdString();
|
||||
if (QMessageBox::Yes !=
|
||||
QMessageBox::question(
|
||||
nullptr, tr("Confirm knock"), tr("Do you really want to ask to join %1?").arg(room)))
|
||||
return;
|
||||
|
||||
http::client()->knock_room(
|
||||
room_id, {}, [this, room_id](const mtx::responses::RoomId &, mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
emit showNotification(tr("Failed to knock room: %1")
|
||||
.arg(QString::fromStdString(err->matrix_error.error)));
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
ChatPage::joinRoom(const QString &room)
|
||||
{
|
||||
|
@ -686,8 +705,6 @@ ChatPage::joinRoomVia(const std::string &room_id,
|
|||
return;
|
||||
}
|
||||
|
||||
emit tr("You joined the room");
|
||||
|
||||
// We remove any invites with the same room_id.
|
||||
try {
|
||||
cache::removeInvite(room_id);
|
||||
|
|
|
@ -84,6 +84,7 @@ public slots:
|
|||
void leaveRoom(const QString &room_id);
|
||||
void createRoom(const mtx::requests::CreateRoom &req);
|
||||
void joinRoom(const QString &room);
|
||||
void knockRoom(const QString &room);
|
||||
void joinRoomVia(const std::string &room_id,
|
||||
const std::vector<std::string> &via,
|
||||
bool promptForConfirmation = true);
|
||||
|
|
|
@ -670,6 +670,8 @@ InputBar::command(const QString &command, QString args)
|
|||
reaction(eventId, args.trimmed());
|
||||
} else if (command == QLatin1String("join")) {
|
||||
ChatPage::instance()->joinRoom(args);
|
||||
} else if (command == QLatin1String("knock")) {
|
||||
ChatPage::instance()->knockRoom(args);
|
||||
} else if (command == QLatin1String("part") || command == QLatin1String("leave")) {
|
||||
ChatPage::instance()->timelineManager()->openLeaveRoomDialog(room->roomId());
|
||||
} else if (command == QLatin1String("invite")) {
|
||||
|
|
Loading…
Reference in a new issue