From 1d38bc83513d054d0824ae5ddac09dc254d7c59a Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sun, 5 Feb 2023 17:41:40 +0800 Subject: [PATCH] feat: add knockroom api --- lib/connection.cpp | 16 ++++++++++++++++ lib/connection.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/lib/connection.cpp b/lib/connection.cpp index ea85ee1ae..d6ad033ae 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -1140,6 +1140,22 @@ JoinRoomJob* Connection::joinRoom(const QString& roomAlias, return job; } +KnockRoomJob* Connection::knockRoom(const QString& roomAlias, + const QStringList& serverNames, + const QString& reason) +{ + auto* const job = callApi(roomAlias, serverNames, reason); + // Upon completion, ensure a room object is created in case it hasn't come + // with a sync yet. If the room object is not there, provideRoom() will + // create it in Knock state. finished() is used here instead of success() + // to overtake clients that may add their own slots to finished(). + connect(job, &BaseJob::finished, this, [this, job] { + if (job->status().good()) + provideRoom(job->roomId(), JoinState::Knock); + }); + return job; +} + LeaveRoomJob* Connection::leaveRoom(Room* room) { const auto& roomId = room->id(); diff --git a/lib/connection.h b/lib/connection.h index 66b3d7151..46c0513af 100644 --- a/lib/connection.h +++ b/lib/connection.h @@ -10,6 +10,7 @@ #include "util.h" #include "csapi/create_room.h" +#include "csapi/knocking.h" #include "csapi/login.h" #include "events/accountdataevents.h" @@ -657,6 +658,9 @@ public Q_SLOTS: virtual JoinRoomJob* joinRoom(const QString& roomAlias, const QStringList& serverNames = {}); + virtual KnockRoomJob* knockRoom(const QString& roomAlias, + const QStringList& serverNames = {}, + const QString& reason = {}); //! \brief Send /forget to the server and delete room locally //! //! This method is in Connection, not in Room, since it's a