From 76c42a9863b83229e6afaf4be32e9582e3d97d3f Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 14 Oct 2017 01:22:04 +0200 Subject: Cleanup around Room (potentially breaks API compatibility, beware) Notably: * API for SendEventJob and SetRoomStateJob has been altered to accept references, not pointers. * Methods on Room that invoke requests to the server, have lost const, because they may be reflecting the changed state on the fly, within themselves --- connection.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'connection.cpp') diff --git a/connection.cpp b/connection.cpp index e20f843f..c7492868 100644 --- a/connection.cpp +++ b/connection.cpp @@ -26,7 +26,6 @@ #include "jobs/sendeventjob.h" #include "jobs/postreceiptjob.h" #include "jobs/joinroomjob.h" -#include "jobs/leaveroomjob.h" #include "jobs/roommessagesjob.h" #include "jobs/syncjob.h" #include "jobs/mediathumbnailjob.h" -- cgit v1.2.3 From 608e7a7163583e2e30cd6c3e9de7449c41651ca4 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 14 Oct 2017 05:23:22 +0200 Subject: Connection::forgetRoom() --- connection.cpp | 37 +++++++++++++++++++++++++++++++++++++ connection.h | 14 ++++++++++++++ 2 files changed, 51 insertions(+) (limited to 'connection.cpp') diff --git a/connection.cpp b/connection.cpp index c7492868..7f1bbec4 100644 --- a/connection.cpp +++ b/connection.cpp @@ -237,6 +237,43 @@ MediaThumbnailJob* Connection::getThumbnail(const QUrl& url, int requestedWidth, return getThumbnail(url, QSize(requestedWidth, requestedHeight)); } +ForgetRoomJob* Connection::forgetRoom(const QString& id) const +{ + // To forget is hard :) First we should ensure the local user is not + // in the room (by leaving it, if necessary); once it's done, the /forget + // endpoint can be called; and once this is through, the local Room object + // (if any existed) is deleted. At the same time, we still have to + // (basically immediately) return a pointer to ForgetRoomJob. Therefore + // a ForgetRoomJob is created in advance and can be returned in a probably + // not-yet-started state (it will start once /leave completes). + auto forgetJob = new ForgetRoomJob(id); + auto joinedRoom = d->roomMap.value({id, false}); + if (joinedRoom && joinedRoom->joinState() == JoinState::Join) + { + auto leaveJob = joinedRoom->leaveRoom(); + connect(leaveJob, &BaseJob::success, + this, [=] { forgetJob->start(connectionData()); }); + connect(leaveJob, &BaseJob::failure, + this, [=] { forgetJob->abandon(); }); + } + else + forgetJob->start(connectionData()); + connect(forgetJob, &BaseJob::success, this, [=] + { + // If the room happens to be in the map (possible in both forms), + // delete the found object(s). + for (auto f: {false, true}) + if (auto r = d->roomMap.take({ id, f })) + { + qCDebug(MAIN) << "Room" << id + << "in join state" << toCString(r->joinState()) + << "will be deleted"; + r->deleteLater(); + } + }); + return forgetJob; +} + QUrl Connection::homeserver() const { return d->data->baseUrl(); diff --git a/connection.h b/connection.h index dbb50b9a..4afae08f 100644 --- a/connection.h +++ b/connection.h @@ -18,6 +18,7 @@ #pragma once +#include "jobs/generated/leaving.h" #include "joinstate.h" #include @@ -94,6 +95,19 @@ namespace QMatrixClient /** @deprecated Use callApi() instead */ MediaThumbnailJob* getThumbnail(const QUrl& url, int requestedWidth, int requestedHeight) const; + /** Sends /forget to the server and also deletes room locally. + * This method is in Connection, not in Room, since it's a + * room lifecycle operation, and Connection is an acting room manager. + * It ensures that the local user is not a member of a room (running /leave, + * if necessary) then issues a /forget request and if that one doesn't fail + * deletion of the local Room object is ensured. + * \param id - the room id to forget + * \return - the ongoing /forget request to the server; note that the + * success() signal of this request is connected to deleteLater() + * of a respective room so by the moment this finishes, there might be no + * Room object anymore. + */ + ForgetRoomJob* forgetRoom(const QString& id) const; Q_INVOKABLE QUrl homeserver() const; Q_INVOKABLE User* user(const QString& userId); -- cgit v1.2.3 From b231ed76210405e670d6aad53350faab1ae18d3b Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 14 Oct 2017 02:01:01 +0200 Subject: LogoutJob is supplied by generated code --- CMakeLists.txt | 1 - connection.cpp | 2 +- jobs/generated/logout.cpp | 22 ++++++++++++++++++++++ jobs/generated/logout.h | 24 ++++++++++++++++++++++++ jobs/logoutjob.cpp | 26 -------------------------- jobs/logoutjob.h | 30 ------------------------------ 6 files changed, 47 insertions(+), 58 deletions(-) create mode 100644 jobs/generated/logout.cpp create mode 100644 jobs/generated/logout.h delete mode 100644 jobs/logoutjob.cpp delete mode 100644 jobs/logoutjob.h (limited to 'connection.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index ca00ce4f..2abf7e69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,6 @@ set(libqmatrixclient_SRCS jobs/roommessagesjob.cpp jobs/syncjob.cpp jobs/mediathumbnailjob.cpp - jobs/logoutjob.cpp ) aux_source_directory(jobs/generated libqmatrixclient_job_SRCS) diff --git a/connection.cpp b/connection.cpp index 7f1bbec4..749d2062 100644 --- a/connection.cpp +++ b/connection.cpp @@ -21,8 +21,8 @@ #include "user.h" #include "events/event.h" #include "room.h" +#include "jobs/generated/logout.h" #include "jobs/passwordlogin.h" -#include "jobs/logoutjob.h" #include "jobs/sendeventjob.h" #include "jobs/postreceiptjob.h" #include "jobs/joinroomjob.h" diff --git a/jobs/generated/logout.cpp b/jobs/generated/logout.cpp new file mode 100644 index 00000000..b750efe2 --- /dev/null +++ b/jobs/generated/logout.cpp @@ -0,0 +1,22 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + + +#include "logout.h" + +#include "jobs/converters.h" +#include + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +LogoutJob::LogoutJob() + : BaseJob(HttpVerb::Post, "LogoutJob", + basePath % "/logout", + Query { }, + Data { } + ) +{ } + diff --git a/jobs/generated/logout.h b/jobs/generated/logout.h new file mode 100644 index 00000000..28e85d8f --- /dev/null +++ b/jobs/generated/logout.h @@ -0,0 +1,24 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + + +#pragma once + +#include "../basejob.h" + + + +namespace QMatrixClient +{ + + // Operations + + class LogoutJob : public BaseJob + { + public: + explicit LogoutJob(); + + }; + +} // namespace QMatrixClient diff --git a/jobs/logoutjob.cpp b/jobs/logoutjob.cpp deleted file mode 100644 index 5ea5cf4d..00000000 --- a/jobs/logoutjob.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2016 Kitsune Ral - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "logoutjob.h" - -using namespace QMatrixClient; - -LogoutJob::LogoutJob() - : BaseJob(HttpVerb::Post, "LogoutJob", "/_matrix/client/r0/logout") -{ -} diff --git a/jobs/logoutjob.h b/jobs/logoutjob.h deleted file mode 100644 index e1b988dc..00000000 --- a/jobs/logoutjob.h +++ /dev/null @@ -1,30 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2016 Kitsune Ral - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#pragma once - -#include "basejob.h" - -namespace QMatrixClient -{ - class LogoutJob: public BaseJob - { - public: - LogoutJob(); - }; -} -- cgit v1.2.3 From 1ae42237adcc5486e526ff3a9e93d0901940a74b Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 15 Oct 2017 23:03:03 +0900 Subject: Connection::forgetRoom(): Minor fixes --- connection.cpp | 3 ++- connection.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'connection.cpp') diff --git a/connection.cpp b/connection.cpp index 749d2062..84a52149 100644 --- a/connection.cpp +++ b/connection.cpp @@ -237,7 +237,7 @@ MediaThumbnailJob* Connection::getThumbnail(const QUrl& url, int requestedWidth, return getThumbnail(url, QSize(requestedWidth, requestedHeight)); } -ForgetRoomJob* Connection::forgetRoom(const QString& id) const +ForgetRoomJob* Connection::forgetRoom(const QString& id) { // To forget is hard :) First we should ensure the local user is not // in the room (by leaving it, if necessary); once it's done, the /forget @@ -265,6 +265,7 @@ ForgetRoomJob* Connection::forgetRoom(const QString& id) const for (auto f: {false, true}) if (auto r = d->roomMap.take({ id, f })) { + emit aboutToDeleteRoom(r); qCDebug(MAIN) << "Room" << id << "in join state" << toCString(r->joinState()) << "will be deleted"; diff --git a/connection.h b/connection.h index 4afae08f..b7d049f1 100644 --- a/connection.h +++ b/connection.h @@ -107,7 +107,7 @@ namespace QMatrixClient * of a respective room so by the moment this finishes, there might be no * Room object anymore. */ - ForgetRoomJob* forgetRoom(const QString& id) const; + ForgetRoomJob* forgetRoom(const QString& id); Q_INVOKABLE QUrl homeserver() const; Q_INVOKABLE User* user(const QString& userId); -- cgit v1.2.3