Add /knock command

This commit is contained in:
Nicolas Werner 2022-03-30 21:15:22 +02:00
parent cb76777fce
commit c91f91d5d3
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
4 changed files with 25 additions and 2 deletions

View File

@ -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.

View File

@ -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);

View File

@ -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);

View File

@ -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")) {