Skip to content

Commit

Permalink
feat: add knockroom api
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Feb 15, 2023
1 parent e20f13f commit 1d38bc8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<KnockRoomJob>(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();
Expand Down
4 changes: 4 additions & 0 deletions lib/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "util.h"

#include "csapi/create_room.h"
#include "csapi/knocking.h"
#include "csapi/login.h"

#include "events/accountdataevents.h"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1d38bc8

Please sign in to comment.