Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85959282
D383.1795444318.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
22 KB
Referenced Files
None
Subscribers
None
D383.1795444318.diff
View Options
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -51,6 +51,7 @@
matrix-sdk.cpp
matrix-session.cpp
matrix-session-controller.cpp
+ matrix-sync-status.cpp
sso-login-process.cpp
kazv-session-lock-guard.cpp
matrix-room.cpp
@@ -200,6 +201,7 @@
LoginPage.qml
LoginFlows.qml
MainPage.qml
+ SyncStatusNotice.qml
TabView.qml
Tab.qml
ClosableScrollablePage.qml
diff --git a/src/contents/ui/MainPage.qml b/src/contents/ui/MainPage.qml
--- a/src/contents/ui/MainPage.qml
+++ b/src/contents/ui/MainPage.qml
@@ -23,6 +23,11 @@
header: ColumnLayout {
spacing: 0
+ Kazv.SyncStatusNotice {
+ session: matrixSession
+ sdk: matrixSdk
+ }
+
TextField {
text: sdkVars.roomList.filter
onTextChanged: sdkVars.roomList.filter = text
diff --git a/src/contents/ui/SyncStatusNotice.qml b/src/contents/ui/SyncStatusNotice.qml
new file mode 100644
--- /dev/null
+++ b/src/contents/ui/SyncStatusNotice.qml
@@ -0,0 +1,38 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2026 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtQuick
+import QtQuick.Layouts
+import org.kde.kirigami 2.13 as Kirigami
+
+/**
+ * A persistent notice shown while syncing is paused because a sync
+ * cycle failed. It offers a way to retry immediately instead of
+ * waiting for the next scheduled retry.
+ */
+Kirigami.InlineMessage {
+ id: notice
+ objectName: 'syncStatusNotice'
+
+ required property var session
+ required property var sdk
+
+ Layout.fillWidth: true
+ visible: session.syncFailed
+ type: Kirigami.MessageType.Warning
+ text: session.syncInProgress
+ ? l10n.get('sync-status-reconnecting')
+ : l10n.get('sync-status-waiting-to-reconnect')
+
+ actions: [
+ Kirigami.Action {
+ objectName: 'syncStatusRetryNowButton'
+ text: l10n.get('sync-status-retry-now')
+ visible: !session.syncInProgress
+ onTriggered: sdk.retrySyncNow()
+ }
+ ]
+}
diff --git a/src/l10n/cmn-Hans/100-ui.ftl b/src/l10n/cmn-Hans/100-ui.ftl
--- a/src/l10n/cmn-Hans/100-ui.ftl
+++ b/src/l10n/cmn-Hans/100-ui.ftl
@@ -504,3 +504,7 @@
media-viewer-play-or-pause = 播放或暂停
media-viewer-play = 播放
media-viewer-pause = 暂停
+
+sync-status-waiting-to-reconnect = 正在等待重新连接到服务器
+sync-status-reconnecting = 正在重新连接...
+sync-status-retry-now = 立即重试
diff --git a/src/l10n/en/100-ui.ftl b/src/l10n/en/100-ui.ftl
--- a/src/l10n/en/100-ui.ftl
+++ b/src/l10n/en/100-ui.ftl
@@ -526,3 +526,7 @@
media-viewer-play-or-pause = Play or pause
media-viewer-play = Play
media-viewer-pause = Pause
+
+sync-status-waiting-to-reconnect = Waiting to reconnect to the server
+sync-status-reconnecting = Reconnecting...
+sync-status-retry-now = Retry now
diff --git a/src/matrix-sdk.hpp b/src/matrix-sdk.hpp
--- a/src/matrix-sdk.hpp
+++ b/src/matrix-sdk.hpp
@@ -59,6 +59,13 @@
void loadSessionFinished(QString sessionName, Constants::LoadSessionResult result);
void dbResolved(bool success);
+ void loginSuccessful();
+
+public:
+ /**
+ * Retry syncing now instead of waiting for the next scheduled retry.
+ */
+ Q_INVOKABLE void retrySyncNow();
public Q_SLOTS:
@@ -109,6 +116,8 @@
private Q_SLOTS:
void handleLoadSessionResult(QString sessionName, Constants::LoadSessionResult result);
+ void handleLoginSuccessful();
+
private: // Testing
friend MatrixSdkSessionsTest;
diff --git a/src/matrix-sdk.cpp b/src/matrix-sdk.cpp
--- a/src/matrix-sdk.cpp
+++ b/src/matrix-sdk.cpp
@@ -67,6 +67,7 @@
controller.reset(new MatrixSessionController(thread, userDataDir));
Q_EMIT q->sessionChanged();
QObject::connect(controller.get(), &MatrixSessionController::loadSessionFinished, q, &MatrixSdk::loadSessionFinished);
+ QObject::connect(controller.get(), &MatrixSessionController::loginSuccessful, q, &MatrixSdk::loginSuccessful);
QObject::connect(controller.get(), &MatrixSessionController::sessionReady, q, &MatrixSdk::sessionChanged);
}
@@ -99,6 +100,7 @@
m_d->saveTimer.start(std::chrono::milliseconds{saveIntervalMs});
connect(this, &MatrixSdk::loadSessionFinished, this, &MatrixSdk::handleLoadSessionResult);
+ connect(this, &MatrixSdk::loginSuccessful, this, &MatrixSdk::handleLoginSuccessful);
}
MatrixSdk::MatrixSdk(QObject *parent)
@@ -199,6 +201,16 @@
}
}
+void MatrixSdk::handleLoginSuccessful()
+{
+ m_d->controller->startSyncing();
+}
+
+void MatrixSdk::retrySyncNow()
+{
+ m_d->controller->retrySyncNow();
+}
+
void MatrixSdk::setUserDataDir(const std::string &userDataDir)
{
m_d->userDataDir = userDataDir;
diff --git a/src/matrix-session-controller-p.hpp b/src/matrix-session-controller-p.hpp
--- a/src/matrix-session-controller-p.hpp
+++ b/src/matrix-session-controller-p.hpp
@@ -14,6 +14,8 @@
#include "qt-job-handler.hpp"
#include "db-store.hpp"
#include <lager/event_loop/qt.hpp>
+#include <lager/state.hpp>
+#include "matrix-sync-status.hpp"
#include <QPointer>
using namespace Kazv;
@@ -73,6 +75,7 @@
public:
MatrixSessionControllerPrivate(
+ MatrixSessionController *q,
QThread *thread,
std::string userDataDir,
SdkModel model,
@@ -89,12 +92,25 @@
void saveEvents(SaveEventsRequested s);
+ void increaseRetryTime();
+
+ Q_SLOT void handleSyncCycleResult(bool success);
+
+ void doOneSyncCycle();
+
+ void retryNow();
+
+ void updateSyncStatus(MatrixSyncStatus status);
+
Q_SIGNALS:
void dbResolved(bool success);
+ void syncCycleFinished(bool success);
+
private:
friend class MatrixSessionController;
+ MatrixSessionController *q;
QPointer<QThread> thread;
std::string userDataDir;
UniquePtrDL<QObject> obj;
@@ -110,4 +126,9 @@
Client clientOnSecondaryRoot;
PendingSaveEvents pendingSaveEvents{};
lager::state<VerificationTrackerModel> verificationTrackerState;
+ lager::state<MatrixSyncStatus, lager::automatic_tag> syncStatus;
+ bool syncing{false};
+ bool inSyncCycle{false};
+ QTimer syncRetryTimer;
+ std::size_t nextRetryMs{0};
};
diff --git a/src/matrix-session-controller.hpp b/src/matrix-session-controller.hpp
--- a/src/matrix-session-controller.hpp
+++ b/src/matrix-session-controller.hpp
@@ -8,6 +8,7 @@
#include <kazv-defs.hpp>
#include "constants.hpp"
#include "helper.hpp"
+#include "matrix-sync-status.hpp"
#include <QObject>
#include <QThread>
#include <QPointer>
@@ -64,6 +65,17 @@
*/
void sessionReady();
+ void loginSuccessful();
+
+ void syncCycleFinished(bool success);
+
+ /**
+ * Signals that the sync status has changed.
+ *
+ * @param status The new sync status.
+ */
+ void syncStatusChanged(MatrixSyncStatus status);
+
public Q_SLOTS:
/**
* Load session at <userDataDir>/sessions/<sessionName> asynchronously.
@@ -96,6 +108,14 @@
void startSyncing();
+ /**
+ * Retry syncing now instead of waiting for the next scheduled retry.
+ *
+ * Does nothing unless syncing has failed and is currently waiting
+ * to retry.
+ */
+ void retrySyncNow();
+
private:
QPointer<QThread> m_thread;
std::string m_userDataDir;
diff --git a/src/matrix-session-controller.cpp b/src/matrix-session-controller.cpp
--- a/src/matrix-session-controller.cpp
+++ b/src/matrix-session-controller.cpp
@@ -44,6 +44,7 @@
}
MatrixSessionControllerPrivate::MatrixSessionControllerPrivate(
+ MatrixSessionController *q,
QThread *threadArg,
std::string userDataDirArg,
SdkModel model,
@@ -52,6 +53,7 @@
QObject *parent
)
: QObject(parent)
+ , q(q)
, thread(threadArg)
, userDataDir(userDataDirArg)
, obj(new QObject())
@@ -81,6 +83,7 @@
});
watchable.after<LoginSuccessful>([this](LoginSuccessful) {
+ Q_EMIT this->q->loginSuccessful();
QMetaObject::invokeMethod(this, [this]() {
if (dbStatus == Ready) {
qCWarning(kazvLog) << "Trying to replace current db store, ignoring";
@@ -120,6 +123,14 @@
dbStatus = Ready;
}
});
+
+ syncRetryTimer.setSingleShot(true);
+
+ connect(this, &MatrixSessionControllerPrivate::syncCycleFinished,
+ this, &MatrixSessionControllerPrivate::handleSyncCycleResult);
+
+ connect(&syncRetryTimer, &QTimer::timeout,
+ this, &MatrixSessionControllerPrivate::doOneSyncCycle);
}
void MatrixSessionControllerPrivate::saveSession()
@@ -216,6 +227,76 @@
{
}
+static const std::size_t INITIAL_RETRY_MS = 2000;
+static const std::size_t MAX_RETRY_MS = 1000 * 60 * 5;
+
+void MatrixSessionControllerPrivate::increaseRetryTime()
+{
+ if (nextRetryMs == 0) {
+ nextRetryMs = INITIAL_RETRY_MS;
+ } else {
+ nextRetryMs *= 2;
+ if (nextRetryMs > MAX_RETRY_MS) {
+ nextRetryMs = MAX_RETRY_MS;
+ }
+ }
+}
+
+void MatrixSessionControllerPrivate::updateSyncStatus(MatrixSyncStatus status)
+{
+ syncStatus.set(status);
+ Q_EMIT q->syncStatusChanged(status);
+}
+
+void MatrixSessionControllerPrivate::doOneSyncCycle()
+{
+ if (!syncing) {
+ return;
+ }
+ if (inSyncCycle) {
+ return;
+ }
+ inSyncCycle = true;
+ auto status = syncStatus.get();
+ status.syncing = true;
+ updateSyncStatus(status);
+ clientOnSecondaryRoot.doOneSyncCycle()
+ .then([this](const auto &stat) {
+ Q_EMIT syncCycleFinished(stat.success());
+ });
+}
+
+void MatrixSessionControllerPrivate::retryNow()
+{
+ if (!syncing || !syncStatus.get().failed || inSyncCycle) {
+ return;
+ }
+ syncRetryTimer.stop();
+ doOneSyncCycle();
+}
+
+void MatrixSessionControllerPrivate::handleSyncCycleResult(bool success)
+{
+ inSyncCycle = false;
+ auto status = syncStatus.get();
+ if (success) {
+ nextRetryMs = 0;
+ status.failed = false;
+ status.syncing = false;
+ status.nextSyncTimeUtc = QDateTime{};
+ updateSyncStatus(status);
+ doOneSyncCycle();
+ } else {
+ increaseRetryTime();
+ status.failed = true;
+ status.syncing = false;
+ status.nextSyncTimeUtc = QDateTime::currentDateTimeUtc().addMSecs(qint64(nextRetryMs));
+ syncRetryTimer.start(std::chrono::milliseconds(nextRetryMs));
+ updateSyncStatus(status);
+ }
+ Q_EMIT q->syncCycleFinished(success);
+}
+
MatrixSessionController::MatrixSessionController(
QThread *workerThread,
std::string userDataDir,
@@ -280,6 +361,7 @@
// helper->cleanup();
// }
+
void MatrixSessionController::load(QString sessionName)
{
if (m_d) {
@@ -354,7 +436,7 @@
}
QMetaObject::invokeMethod(this, [this, model=std::move(model), lockGuard=std::move(lockGuard), dbStore=std::move(dbStore)]() mutable {
m_d.reset(new MatrixSessionControllerPrivate(
- m_thread, m_userDataDir,
+ this, m_thread, m_userDataDir,
std::move(model), std::move(lockGuard), std::move(dbStore)
));
Q_EMIT sessionReady();
@@ -406,6 +488,7 @@
return;
}
m_d.reset(new MatrixSessionControllerPrivate(
+ this,
m_thread,
m_userDataDir,
model,
@@ -426,14 +509,29 @@
{
if (m_d) {
qCDebug(kazvLog) << "MatrixSessionController::prepareDestroy";
- m_d->clientOnSecondaryRoot.stopSyncing();
+ m_d->syncing = false;
+ m_d->syncRetryTimer.stop();
+ m_d->updateSyncStatus(MatrixSyncStatus{});
m_d->obj = nullptr;
}
}
void MatrixSessionController::startSyncing()
{
- m_d->clientOnSecondaryRoot.startSyncing();
+ if (!m_d) {
+ return;
+ }
+ m_d->syncing = true;
+ m_d->nextRetryMs = 0;
+ m_d->updateSyncStatus(MatrixSyncStatus{});
+ m_d->doOneSyncCycle();
+}
+
+void MatrixSessionController::retrySyncNow()
+{
+ if (m_d) {
+ m_d->retryNow();
+ }
}
MatrixSession *MatrixSessionController::session() const
@@ -444,6 +542,7 @@
m_d->clientOnSecondaryRoot,
m_d->ee.watchable(),
m_d->verificationTrackerState,
+ m_d->syncStatus,
[d=m_d.get()]() -> DbStore & { return *(d->dbStore); }
);
} else {
diff --git a/src/matrix-session.hpp b/src/matrix-session.hpp
--- a/src/matrix-session.hpp
+++ b/src/matrix-session.hpp
@@ -14,6 +14,7 @@
#include <notification-handler.hpp>
#include <lagerstoreeventemitter.hpp>
#include <lager/extra/qt.hpp>
+#include "matrix-sync-status.hpp"
#include <QObject>
#include <QQmlEngine>
@@ -58,6 +59,7 @@
Kazv::Client client,
Kazv::LagerStoreEventEmitter::Watchable watchable,
lager::reader<Kazv::VerificationTrackerModel> verificationTrackerState,
+ lager::reader<MatrixSyncStatus> syncStatus,
std::function<DbStore &()> dbStoreGetter,
QObject *parent = nullptr
);
@@ -71,6 +73,14 @@
LAGER_QT_READER(QString, deviceId);
LAGER_QT_READER(immer::array<std::string>, specVersions); // The versions of the Matrix Spec supported by the server.
+ /// Whether a sync cycle has failed since the last successful one.
+ /// While this is true the sync status notice should be displayed.
+ LAGER_QT_READER(bool, syncFailed);
+ /// Whether a sync cycle is currently in progress.
+ LAGER_QT_READER(bool, syncInProgress);
+ /// If syncFailed is true, the estimated time of the next retry.
+ LAGER_QT_READER(QDateTime, nextSyncTimeUtc);
+
Q_INVOKABLE MatrixRoomList *roomList() const;
Q_INVOKABLE QString mxcUriToHttp(QString mxcUri) const;
diff --git a/src/matrix-session.cpp b/src/matrix-session.cpp
--- a/src/matrix-session.cpp
+++ b/src/matrix-session.cpp
@@ -34,6 +34,7 @@
Client client,
LagerStoreEventEmitter::Watchable watchable,
lager::reader<VerificationTrackerModel> verificationTrackerState,
+ lager::reader<MatrixSyncStatus> syncStatus,
std::function<DbStore &()> dbStoreGetter,
QObject *parent
)
@@ -50,6 +51,15 @@
, LAGER_QT(token)(m_clientOnSecondaryRoot.token().xform(strToQt))
, LAGER_QT(deviceId)(m_clientOnSecondaryRoot.deviceId().xform(strToQt))
, LAGER_QT(specVersions)(m_clientOnSecondaryRoot.supportVersions())
+ , LAGER_QT(syncFailed)(syncStatus.xform(zug::map([](const MatrixSyncStatus &s) {
+ return s.failed;
+ })))
+ , LAGER_QT(syncInProgress)(syncStatus.xform(zug::map([](const MatrixSyncStatus &s) {
+ return s.syncing;
+ })))
+ , LAGER_QT(nextSyncTimeUtc)(syncStatus.xform(zug::map([](const MatrixSyncStatus &s) {
+ return s.nextSyncTimeUtc;
+ })))
{
m_watchable.afterAll(
[this](KazvTrigger e) {
@@ -217,7 +227,7 @@
userId.toStdString(),
password.toStdString(),
clientName,
- /* startSyncingOnSuccess = */ true
+ /* startSyncingOnSuccess = */ false
);
};
@@ -311,7 +321,7 @@
homeserverUrl.toStdString(),
loginToken.toStdString(),
clientName,
- /* startSyncingOnSuccess = */ true
+ /* startSyncingOnSuccess = */ false
);
});
return link;
diff --git a/src/matrix-sync-status.hpp b/src/matrix-sync-status.hpp
new file mode 100644
--- /dev/null
+++ b/src/matrix-sync-status.hpp
@@ -0,0 +1,33 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2026 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+#include <kazv-defs.hpp>
+#include <QDateTime>
+#include <QMetaType>
+
+struct MatrixSyncStatus
+{
+ Q_GADGET
+ Q_PROPERTY(bool failed MEMBER failed)
+ Q_PROPERTY(bool syncing MEMBER syncing)
+ Q_PROPERTY(QDateTime nextSyncTimeUtc MEMBER nextSyncTimeUtc)
+
+public:
+ /// true iff a sync cycle has failed and we have not yet completed
+ /// a successful sync cycle since. While this is true the sync status
+ /// notice is displayed.
+ bool failed{false};
+ /// true iff a sync cycle is currently in progress.
+ /// This is false when we are waiting to retry, or have not yet
+ /// started syncing, or have stopped syncing.
+ bool syncing{false};
+ /// If a sync cycle has failed, this is the estimated time of the
+ /// next retry. Otherwise, this is an invalid QDateTime.
+ QDateTime nextSyncTimeUtc;
+};
+
+Q_DECLARE_METATYPE(MatrixSyncStatus)
diff --git a/src/matrix-sync-status.cpp b/src/matrix-sync-status.cpp
new file mode 100644
--- /dev/null
+++ b/src/matrix-sync-status.cpp
@@ -0,0 +1,9 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2026 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include "matrix-sync-status.hpp"
+
+#include "moc_matrix-sync-status.cpp"
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -109,6 +109,7 @@
tst_RoomStickerPacksPage.qml
tst_RoomTimelineView.qml
tst_SendMessageBoxDrafts.qml
+ tst_SyncStatusNotice.qml
tst_SendMessageBox.qml
tst_StickerPackNameProvider.qml
tst_StickerPicker.qml
diff --git a/src/tests/matrix-session-controller-test.cpp b/src/tests/matrix-session-controller-test.cpp
--- a/src/tests/matrix-session-controller-test.cpp
+++ b/src/tests/matrix-session-controller-test.cpp
@@ -12,7 +12,11 @@
#include <db-store.hpp>
#include <QTemporaryDir>
#include <QSignalSpy>
+#include <QHostAddress>
+#include <QTcpServer>
+#include <QTcpSocket>
#include <QtTest>
+#include <algorithm>
#include <fstream>
using namespace Qt::Literals::StringLiterals;
@@ -53,6 +57,7 @@
private Q_SLOTS:
void testLoadSession();
void testSaveSessionFailure();
+ void testSyncFailureReportsStatus();
};
void MatrixSessionControllerTest::createSession(std::string userDataDir, std::string userId, std::string deviceId)
@@ -153,6 +158,68 @@
err.clear();
}
+void MatrixSessionControllerTest::testSyncFailureReportsStatus()
+{
+ auto s = ControllerSetup(this);
+
+ // A homeserver that fails every sync request, mocking a failed
+ // sync response.
+ QTcpServer server;
+ QVERIFY(server.listen(QHostAddress::LocalHost));
+ connect(&server, &QTcpServer::newConnection, &server, [&server]() {
+ while (auto *socket = server.nextPendingConnection()) {
+ connect(socket, &QTcpSocket::readyRead, socket, [socket]() {
+ socket->readAll();
+ socket->write("HTTP/1.1 500 Internal Server Error\r\n"
+ "Content-Type: application/json\r\n"
+ "Content-Length: 0\r\n"
+ "Connection: close\r\n\r\n");
+ socket->disconnectFromHost();
+ });
+ connect(socket, &QTcpSocket::disconnected, socket, &QObject::deleteLater);
+ }
+ });
+
+ SdkModel model;
+ model.client.userId = "@user1:example.org";
+ model.client.deviceId = "device1";
+ model.client.token = "token";
+ model.client.loggedIn = true;
+ model.client.serverUrl =
+ QStringLiteral("http://127.0.0.1:%1").arg(server.serverPort()).toStdString();
+
+ s.controller->createWithModel(model);
+
+ auto hasStatus = [](const QSignalSpy &spy, bool failed, bool syncing) {
+ return std::any_of(
+ spy.cbegin(), spy.cend(),
+ [failed, syncing](const QList<QVariant> &args) {
+ if (args.size() != 1) {
+ return false;
+ }
+ const auto status = args.at(0).value<MatrixSyncStatus>();
+ return status.failed == failed && status.syncing == syncing;
+ });
+ };
+
+ QSignalSpy spy(s.controller.get(), &MatrixSessionController::syncStatusChanged);
+ s.controller->startSyncing();
+ QTRY_VERIFY_WITH_TIMEOUT(hasStatus(spy, true, false), 10000);
+ QVERIFY(spy.last().at(0).value<MatrixSyncStatus>().nextSyncTimeUtc.isValid());
+
+ auto session = toUniquePtr(s.controller->session());
+ QVERIFY(session);
+ QCOMPARE(session->syncFailed(), true);
+ QCOMPARE(session->syncInProgress(), false);
+ QVERIFY(session->nextSyncTimeUtc().isValid());
+
+ // Retrying before the scheduled time moves to the in-progress state.
+ s.controller->retrySyncNow();
+ QVERIFY(hasStatus(spy, true, true));
+ QCOMPARE(session->syncFailed(), true);
+ QCOMPARE(session->syncInProgress(), true);
+}
+
QTEST_MAIN(MatrixSessionControllerTest)
#include "matrix-session-controller-test.moc"
diff --git a/src/tests/quick-tests/tst_SyncStatusNotice.qml b/src/tests/quick-tests/tst_SyncStatusNotice.qml
new file mode 100644
--- /dev/null
+++ b/src/tests/quick-tests/tst_SyncStatusNotice.qml
@@ -0,0 +1,70 @@
+/*
+ * This file is part of kazv.
+ * SPDX-FileCopyrightText: 2026 tusooa <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+import QtQuick
+import QtTest
+import '../../contents/ui' as Kazv
+import 'test-helpers' as QmlHelpers
+
+QmlHelpers.TestItem {
+ id: item
+
+ // A mocked MatrixSession that simulates a failed sync response.
+ property var sessionMock: QtObject {
+ property bool syncFailed: false
+ property bool syncInProgress: false
+ }
+
+ property var sdkMock: QtObject {
+ property var retrySyncNow: item.mockHelper.noop()
+ }
+
+ Kazv.SyncStatusNotice {
+ id: notice
+ width: parent.width
+ session: item.sessionMock
+ sdk: item.sdkMock
+ }
+
+ TestCase {
+ name: 'SyncStatusNoticeTest'
+ when: windowShown
+
+ function init() {
+ item.mockHelper.clearAll();
+ sessionMock.syncFailed = false;
+ sessionMock.syncInProgress = false;
+ }
+
+ function test_failedSyncShowsNotice() {
+ sessionMock.syncFailed = true;
+ tryVerify(() => notice.visible);
+ compare(notice.text, l10n.get('sync-status-waiting-to-reconnect'));
+ }
+
+ function test_reconnectingWhileRetrying() {
+ sessionMock.syncFailed = true;
+ sessionMock.syncInProgress = true;
+ tryVerify(() => notice.visible);
+ compare(notice.text, l10n.get('sync-status-reconnecting'));
+ }
+
+ function test_retryNow() {
+ sessionMock.syncFailed = true;
+ tryVerify(() => notice.visible);
+ notice.actions[0].trigger();
+ compare(sdkMock.retrySyncNow.calledTimes(), 1);
+ }
+
+ function test_successHidesNotice() {
+ sessionMock.syncFailed = true;
+ tryVerify(() => notice.visible);
+ sessionMock.syncFailed = false;
+ sessionMock.syncInProgress = true;
+ tryVerify(() => !notice.visible);
+ }
+ }
+}
diff --git a/src/tests/test-model.hpp b/src/tests/test-model.hpp
--- a/src/tests/test-model.hpp
+++ b/src/tests/test-model.hpp
@@ -26,6 +26,7 @@
LagerStoreEventEmitter ee;
MatrixSessionSdkT sdk;
lager::state<VerificationTrackerModel> verificationTrackerState;
+ lager::state<MatrixSyncStatus> syncStatusState;
// SecondaryRootT secondaryRoot;
DbStore dbStore;
MatrixSession session;
@@ -50,6 +51,7 @@
sdk.client(),
ee.watchable(),
verificationTrackerState,
+ syncStatusState,
[this]() -> DbStore & { return dbStore; }
)
{}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 23, 6:31 AM (22 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1846891
Default Alt Text
D383.1795444318.diff (22 KB)
Attached To
Mode
D383: Allow user to retry failed sync earlier
Attached
Detach File
Event Timeline