Skip to content

Commit

Permalink
Connection::assumeIdentity: Set UserId and DeviceId and completeSetup…
Browse files Browse the repository at this point in the history
… before connecting to the server

This allows libQuotient-based clients to operate with the cached state (and in the future, room events)
when there is no network connection. It's losing the check whether userid and deviceid correspond to the given token,
but I don't see a strong need for that.
  • Loading branch information
TobiasFella committed Jul 18, 2024
1 parent 1d04afd commit 479a8df
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions Quotient/accountregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void AccountRegistry::invokeLogin()
});
connection->assumeIdentity(
account.userId(),
account.deviceId(),
QString::fromUtf8(accessTokenLoadingJob->binaryData()));
add(connection);
});
Expand Down
6 changes: 3 additions & 3 deletions Quotient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ void Connection::loginWithToken(const QString& loginToken,
QString() /*password*/, loginToken, deviceId, initialDeviceName);
}

void Connection::assumeIdentity(const QString& mxId, const QString& accessToken)
void Connection::assumeIdentity(const QString& mxId, const QString& deviceId, const QString& accessToken)
{
d->data->setDeviceId(deviceId);
d->completeSetup(mxId);
d->ensureHomeserver(mxId).then([this, mxId, accessToken] {
d->data->setToken(accessToken.toLatin1());
callApi<GetTokenOwnerJob>().onResult([this, mxId](const GetTokenOwnerJob* job) {
Expand All @@ -182,8 +184,6 @@ void Connection::assumeIdentity(const QString& mxId, const QString& accessToken)
qCWarning(MAIN).nospace()
<< "The access_token owner (" << job->userId()
<< ") is different from passed MXID (" << mxId << ")!";
d->data->setDeviceId(job->deviceId());
d->completeSetup(job->userId());
return;
case BaseJob::NetworkError:
emit networkError(job->errorString(), job->rawDataSample(), job->maxRetries(), -1);
Expand Down
2 changes: 1 addition & 1 deletion Quotient/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ public Q_SLOTS:
//! Similar to loginWithPassword(), this method checks that the homeserver
//! URL is valid and tries to resolve it from the MXID in case it is not.
//! \since 0.7.2
void assumeIdentity(const QString& mxId, const QString& accessToken);
void assumeIdentity(const QString& mxId, const QString& deviceId, const QString& accessToken);

//! Explicitly request capabilities from the server
void reloadCapabilities();
Expand Down

0 comments on commit 479a8df

Please sign in to comment.