aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2017-03-25 14:33:01 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2017-03-25 17:21:02 +0900
commit2f57ea69098fee6a5f90ec35ebac89a26ef8efeb (patch)
tree3396002c787d8f3eb6f58dd54288df2b8004b8ab
parent0e00f6f74041a5fec528d1511095ea4974150239 (diff)
downloadlibquotient-2f57ea69098fee6a5f90ec35ebac89a26ef8efeb.tar.gz
libquotient-2f57ea69098fee6a5f90ec35ebac89a26ef8efeb.zip
Stop sync upon successful logout
-rw-r--r--connection.cpp23
-rw-r--r--connection.h1
2 files changed, 16 insertions, 8 deletions
diff --git a/connection.cpp b/connection.cpp
index a9b9a534..cf08321c 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -144,19 +144,17 @@ void Connection::reconnect()
void Connection::disconnectFromServer()
{
- if (d->syncJob)
- {
- d->syncJob->abandon();
- d->syncJob = nullptr;
- }
+ stopSync();
d->isConnected = false;
}
void Connection::logout()
{
- auto job = new LogoutJob(d->data);
- connect( job, &LogoutJob::success, this, &Connection::loggedOut);
- job->start();
+ auto job = callApi<LogoutJob>();
+ connect( job, &LogoutJob::success, [=] {
+ stopSync();
+ emit loggedOut();
+ });
}
void Connection::sync(int timeout)
@@ -186,6 +184,15 @@ void Connection::sync(int timeout)
});
}
+void Connection::stopSync()
+{
+ if (d->syncJob)
+ {
+ d->syncJob->abandon();
+ d->syncJob = nullptr;
+ }
+}
+
void Connection::postMessage(Room* room, QString type, QString message)
{
PostMessageJob* job = new PostMessageJob(d->data, room->id(), type, message);
diff --git a/connection.h b/connection.h
index 70a2eeaa..a00afc91 100644
--- a/connection.h
+++ b/connection.h
@@ -54,6 +54,7 @@ namespace QMatrixClient
Q_INVOKABLE virtual void logout();
Q_INVOKABLE virtual void sync(int timeout=-1);
+ Q_INVOKABLE virtual void stopSync();
/** @deprecated Use callApi<PostMessageJob>() or Room::postMessage() instead */
Q_INVOKABLE virtual void postMessage( Room* room, QString type, QString message );
/** @deprecated Use callApi<PostReceiptJob>() or Room::postReceipt() instead */