Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isonline parameter to connection #819

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Quotient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,22 @@ void Connection::sync(int timeout)
connect(job, &SyncJob::success, this, [this, job] {
onSyncSuccess(job->takeData());
d->syncJob = nullptr;
d->lastSyncSuccessful = true;
emit isOnlineChanged();
emit syncDone();
});
connect(job, &SyncJob::retryScheduled, this,
[this, job](int retriesTaken, int nextInMilliseconds) {
d->lastSyncSuccessful = false;
emit isOnlineChanged();
emit networkError(job->errorString(), job->rawDataSample(),
retriesTaken, nextInMilliseconds);
});
connect(job, &SyncJob::failure, this, [this, job] {
// SyncJob persists with retries on transient errors; if it fails,
// there's likely something serious enough to stop the loop.
d->lastSyncSuccessful = false;
emit isOnlineChanged();
stopSync();
if (job->error() == BaseJob::Unauthorised) {
qCWarning(SYNCJOB)
Expand Down Expand Up @@ -1099,6 +1105,8 @@ QByteArray Connection::accessToken() const

bool Connection::isLoggedIn() const { return !accessToken().isEmpty(); }

bool Connection::isOnline() const { return d->lastSyncSuccessful; }

QOlmAccount* Connection::olmAccount() const
{
return d->encryptionData ? &d->encryptionData->olmAccount : nullptr;
Expand Down
10 changes: 10 additions & 0 deletions Quotient/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class QUOTIENT_API Connection : public QObject {
Q_PROPERTY(QString deviceId READ deviceId NOTIFY stateChanged)
Q_PROPERTY(QByteArray accessToken READ accessToken NOTIFY stateChanged)
Q_PROPERTY(bool isLoggedIn READ isLoggedIn NOTIFY stateChanged STORED false)
Q_PROPERTY(bool isOnline READ isOnline NOTIFY isOnlineChanged)
Q_PROPERTY(QString defaultRoomVersion READ defaultRoomVersion NOTIFY capabilitiesLoaded)
Q_PROPERTY(QUrl homeserver READ homeserver WRITE setHomeserver NOTIFY homeserverChanged)
Q_PROPERTY(QVector<GetLoginFlowsJob::LoginFlow> loginFlows READ loginFlows NOTIFY loginFlowsChanged)
Expand Down Expand Up @@ -332,6 +333,11 @@ class QUOTIENT_API Connection : public QObject {
QString deviceId() const;
QByteArray accessToken() const;
bool isLoggedIn() const;

//! \brief Whether the connection is successfully syncing with the server.
//!
//! \return true, if the last sync was successful, false otherwise.
bool isOnline() const;
QOlmAccount* olmAccount() const;
Database* database() const;

Expand Down Expand Up @@ -787,6 +793,10 @@ public Q_SLOTS:
//! accessToken - these properties normally only change at
//! a successful login and logout and are constant at other times.
void stateChanged();

//! The online state has changed.
void isOnlineChanged();

void loginError(QString message, QString details);

//! \brief A network request (job) started by callApi() has failed
Expand Down
1 change: 1 addition & 0 deletions Quotient/connection_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Q_DECL_HIDDEN Quotient::Connection::Private {
JobHandle<GetLoginFlowsJob> loginFlowsJob = nullptr;

SyncJob* syncJob = nullptr;
bool lastSyncSuccessful = true;
JobHandle<LogoutJob> logoutJob = nullptr;

bool cacheState = true;
Expand Down
Loading