diff options
author | Felix Rohrbach <fxrh@gmx.de> | 2016-05-08 18:59:11 +0200 |
---|---|---|
committer | Felix Rohrbach <fxrh@gmx.de> | 2016-05-08 18:59:11 +0200 |
commit | 1cd8802c73ee3c0cc0095f8be30a9bbf3442c3ca (patch) | |
tree | fa0f4aded71f27974c9922bd587ba78774ade46c /connection.cpp | |
parent | fc95edb7a63bcacb02418c55e15a1aa21ac080cd (diff) | |
parent | 5a0e6080a6245aa2c68f254d7105f19629a5a654 (diff) | |
download | libquotient-1cd8802c73ee3c0cc0095f8be30a9bbf3442c3ca.tar.gz libquotient-1cd8802c73ee3c0cc0095f8be30a9bbf3442c3ca.zip |
Merge pull request #5 from KitsuneRal/basejob-improvement
Basejob improvement
Diffstat (limited to 'connection.cpp')
-rw-r--r-- | connection.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/connection.cpp b/connection.cpp index e04de7aa..a219f1da 100644 --- a/connection.cpp +++ b/connection.cpp @@ -62,7 +62,13 @@ void Connection::resolveServer(QString domain) void Connection::connectToServer(QString user, QString password) { PasswordLogin* loginJob = new PasswordLogin(d->data, user, password); - connect( loginJob, &PasswordLogin::result, d, &ConnectionPrivate::connectDone ); + connect( loginJob, &PasswordLogin::success, [=] () { + qDebug() << "Our user ID: " << loginJob->id(); + connectWithToken(loginJob->id(), loginJob->token()); + }); + connect( loginJob, &PasswordLogin::failure, [=] () { + emit loginError(loginJob->errorString()); + }); loginJob->start(); d->username = user; // to be able to reconnect d->password = password; @@ -79,7 +85,14 @@ void Connection::connectWithToken(QString userId, QString token) void Connection::reconnect() { PasswordLogin* loginJob = new PasswordLogin(d->data, d->username, d->password ); - connect( loginJob, &PasswordLogin::result, d, &ConnectionPrivate::reconnectDone ); + connect( loginJob, &PasswordLogin::success, [=] () { + d->userId = loginJob->id(); + emit reconnected(); + }); + connect( loginJob, &PasswordLogin::failure, [=] () { + emit loginError(loginJob->errorString()); + d->isConnected = false; + }); loginJob->start(); } @@ -89,7 +102,13 @@ SyncJob* Connection::sync(int timeout) SyncJob* syncJob = new SyncJob(d->data, d->data->lastEvent()); syncJob->setFilter(filter); syncJob->setTimeout(timeout); - connect( syncJob, &SyncJob::result, d, &ConnectionPrivate::syncDone ); + connect( syncJob, &SyncJob::success, [=] () { + d->data->setLastEvent(syncJob->nextBatch()); + d->processRooms(syncJob->roomData()); + emit syncDone(); + }); + connect( syncJob, &SyncJob::failure, + [=] () { emit connectionError(syncJob->errorString());}); syncJob->start(); return syncJob; } @@ -110,7 +129,10 @@ PostReceiptJob* Connection::postReceipt(Room* room, Event* event) void Connection::joinRoom(QString roomAlias) { JoinRoomJob* job = new JoinRoomJob(d->data, roomAlias); - connect( job, &JoinRoomJob::result, d, &ConnectionPrivate::gotJoinRoom ); + connect( job, &SyncJob::success, [=] () { + if ( Room* r = d->provideRoom(job->roomId()) ) + emit joinedRoom(r); + }); job->start(); } |