diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-10-19 08:12:50 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-10-19 08:14:56 +0900 |
commit | ecc364d4ad752b34e41b717e3deff4d17a840378 (patch) | |
tree | ca1077fb3a751ad01f6638ee5733ddd4583d005f /connection.cpp | |
parent | 8800690c691dc9534fdb0f2d902862f816704d50 (diff) | |
parent | f2f85ba093df5dcd991fd206af4d79d57f4c7fc8 (diff) | |
download | libquotient-ecc364d4ad752b34e41b717e3deff4d17a840378.tar.gz libquotient-ecc364d4ad752b34e41b717e3deff4d17a840378.zip |
Merge branch 'master' into kitsune-gtad
Diffstat (limited to 'connection.cpp')
-rw-r--r-- | connection.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/connection.cpp b/connection.cpp index e20f843f..84a52149 100644 --- a/connection.cpp +++ b/connection.cpp @@ -21,12 +21,11 @@ #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" -#include "jobs/leaveroomjob.h" #include "jobs/roommessagesjob.h" #include "jobs/syncjob.h" #include "jobs/mediathumbnailjob.h" @@ -238,6 +237,44 @@ MediaThumbnailJob* Connection::getThumbnail(const QUrl& url, int requestedWidth, return getThumbnail(url, QSize(requestedWidth, requestedHeight)); } +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 + // 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 })) + { + emit aboutToDeleteRoom(r); + 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(); |