From 4e70dd91bb70fa2b9b338686e4d5ab2560947723 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 6 Sep 2016 12:02:56 +0900 Subject: Connection: homeserver(); Connection and ConnectionData: accessToken(); accessors de-virtualized Details: - New: Connection::homeserver(), returns the homeserver URL from inside ConnectionData - New/Modify: Connection::accessToken() and ConnectionData::accessToken() - because we will also have refresh tokens eventually; deprecate token() for the same reason - Modify: Connection::user(), token(), accessToken() are no more virtual (they should have never been, these are plain accessors, after all) --- connection.cpp | 21 ++++++++++++++++----- connection.h | 12 ++++++++---- connectiondata.cpp | 8 ++++---- connectiondata.h | 4 ++-- jobs/basejob.cpp | 2 +- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/connection.cpp b/connection.cpp index d357599b..f7f09c04 100644 --- a/connection.cpp +++ b/connection.cpp @@ -106,7 +106,6 @@ void Connection::connectToServer(QString user, QString password) { PasswordLogin* loginJob = new PasswordLogin(d->data, user, password); connect( loginJob, &PasswordLogin::success, [=] () { - qDebug() << "Our user ID: " << loginJob->id(); connectWithToken(loginJob->id(), loginJob->token()); }); connect( loginJob, &PasswordLogin::failure, [=] () { @@ -122,7 +121,9 @@ void Connection::connectWithToken(QString userId, QString token) d->isConnected = true; d->userId = userId; d->data->setToken(token); - qDebug() << "Connected with token:"; + qDebug() << "Accessing" << d->data->baseUrl() + << "by user" << userId + << "with the following access token:"; qDebug() << token; emit connected(); } @@ -223,6 +224,11 @@ MediaThumbnailJob* Connection::getThumbnail(QUrl url, int requestedWidth, int re return job; } +QUrl Connection::homeserver() const +{ + return d->data->baseUrl(); +} + User* Connection::user(QString userId) { if( d->userMap.contains(userId) ) @@ -239,14 +245,19 @@ User *Connection::user() return user(d->userId); } -QString Connection::userId() +QString Connection::userId() const { return d->userId; } -QString Connection::token() +QString Connection::token() const +{ + return accessToken(); +} + +QString Connection::accessToken() const { - return d->data->token(); + return d->data->accessToken(); } QHash< QString, Room* > Connection::roomMap() const diff --git a/connection.h b/connection.h index 2816895e..bfb4d377 100644 --- a/connection.h +++ b/connection.h @@ -20,6 +20,7 @@ #define QMATRIXCLIENT_CONNECTION_H #include +#include namespace QMatrixClient { @@ -59,10 +60,13 @@ namespace QMatrixClient Q_INVOKABLE virtual RoomMessagesJob* getMessages( Room* room, QString from ); virtual MediaThumbnailJob* getThumbnail( QUrl url, int requestedWidth, int requestedHeight ); - Q_INVOKABLE virtual User* user(QString userId); - Q_INVOKABLE virtual User* user(); - Q_INVOKABLE virtual QString userId(); - Q_INVOKABLE virtual QString token(); + Q_INVOKABLE QUrl homeserver() const; + Q_INVOKABLE User* user(QString userId); + Q_INVOKABLE User* user(); + Q_INVOKABLE QString userId() const; + /** @deprecated Use accessToken() instead. */ + Q_INVOKABLE QString token() const; + Q_INVOKABLE QString accessToken() const; signals: void resolved(); diff --git a/connectiondata.cpp b/connectiondata.cpp index 4a3bd47f..72e8f3d8 100644 --- a/connectiondata.cpp +++ b/connectiondata.cpp @@ -29,7 +29,7 @@ class ConnectionData::Private QUrl baseUrl; //bool isConnected; - QString token; + QString accessToken; QString lastEvent; QNetworkAccessManager* nam; }; @@ -52,9 +52,9 @@ ConnectionData::~ConnectionData() // return d->isConnected; // } -QString ConnectionData::token() const +QString ConnectionData::accessToken() const { - return d->token; + return d->accessToken; } QUrl ConnectionData::baseUrl() const @@ -69,7 +69,7 @@ QNetworkAccessManager* ConnectionData::nam() const void ConnectionData::setToken(QString token) { - d->token = token; + d->accessToken = token; } void ConnectionData::setHost(QString host) diff --git a/connectiondata.h b/connectiondata.h index 6407780c..5c8342d7 100644 --- a/connectiondata.h +++ b/connectiondata.h @@ -32,11 +32,11 @@ namespace QMatrixClient virtual ~ConnectionData(); //bool isConnected() const; - QString token() const; + QString accessToken() const; QUrl baseUrl() const; QNetworkAccessManager* nam() const; - void setToken( QString token ); + void setToken( QString accessToken ); void setHost( QString host ); void setPort( int port ); diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index e0dff287..20b45a15 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -92,7 +92,7 @@ void BaseJob::start() url.setPath( url.path() + "/" + apiPath() ); QUrlQuery query = this->query(); if( d->needsToken ) - query.addQueryItem("access_token", connection()->token()); + query.addQueryItem("access_token", connection()->accessToken()); url.setQuery(query); QNetworkRequest req = QNetworkRequest(url); req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); -- cgit v1.2.3