Skip to content

Commit

Permalink
Merge pull request #1724 from matthiasn/feat/fetch_on_startup
Browse files Browse the repository at this point in the history
feat: fetch messages on startup
  • Loading branch information
matthiasn authored Apr 21, 2024
2 parents 9c49a1a + de784a4 commit 3620f21
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
6 changes: 0 additions & 6 deletions integration_test/matrix_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,6 @@ void main() {
final bobEntriesCount = await bobDb.getJournalCount();
expect(bobEntriesCount, n);
debugPrint('Bob persisted $bobEntriesCount entries');

debugPrint('\n--- Logging out Alice and Bob');

await alice.logout();
await waitSeconds(defaultDelay * delayFactor);
await bob.logout();
},
timeout: const Timeout(Duration(minutes: 15)),
);
Expand Down
1 change: 1 addition & 0 deletions lib/sync/matrix/matrix_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class MatrixService {

Future<void> logout() async {
if (_client.isLogged()) {
timeline?.cancelSubscriptions();
await _client.logout();
}
}
Expand Down
27 changes: 20 additions & 7 deletions lib/sync/matrix/timeline.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:lotti/database/database.dart';
import 'package:lotti/database/logging_db.dart';
Expand Down Expand Up @@ -25,12 +27,17 @@ Future<void> listenToTimelineEvents({
service.timeline = await service.syncRoom?.getTimeline(
onNewEvent: () {
final clientRunner = service.clientRunner;
if (clientRunner.queueSize < 2) {
if (clientRunner.queueSize < 5) {
service.clientRunner.enqueueRequest(null);
}
},
);

unawaited(
Future<void>.delayed(const Duration(seconds: 1))
.then((value) => service.clientRunner.enqueueRequest(null)),
);

final timeline = service.timeline;

if (timeline == null) {
Expand Down Expand Up @@ -61,6 +68,7 @@ Future<void> processNewTimelineEvents({

try {
final lastReadEventContextId = service.lastReadEventContextId;

await service.client.sync();
final hasMessage = await service.syncRoom
?.getEventById(lastReadEventContextId.toString()) !=
Expand Down Expand Up @@ -109,21 +117,26 @@ Future<void> processNewTimelineEvents({
service.lastReadEventContextId = eventId;
await setLastReadMatrixEventId(eventId);
}

await timeline.setReadMarker(eventId: eventId);
} catch (e) {
debugPrint('$e');
final loginState = service.client.onLoginStateChanged.value;
if (loginState == LoginState.loggedIn) {
await timeline.setReadMarker(eventId: eventId);
}
} catch (e, stackTrace) {
loggingDb.captureException(
e,
domain: 'MATRIX_SERVICE',
subDomain: 'setReadMarker ${service.client.deviceName}',
stackTrace: stackTrace,
);
}
}
} catch (e, stackTrace) {
debugPrint('$e');
loggingDb.captureException(
e,
domain: 'MATRIX_SERVICE',
subDomain: 'listenToTimelineEvents ${service.client.deviceName}',
stackTrace: stackTrace,
);
rethrow;
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: lotti
description: Achieve your goals and keep your data private with Lotti.
publish_to: 'none'
version: 0.9.449+2465
version: 0.9.450+2467

msix_config:
display_name: LottiApp
Expand Down

0 comments on commit 3620f21

Please sign in to comment.