Skip to content

Commit

Permalink
Merge #819(nvrWhere): Add isonline parameter to connection
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal authored Oct 26, 2024
2 parents e70e242 + 4464c35 commit 8ad6a9e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
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

0 comments on commit 8ad6a9e

Please sign in to comment.