Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add knockroom api #615

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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