Skip to content

Commit

Permalink
Merge pull request #1140 from matthiasn/inbox_v2
Browse files Browse the repository at this point in the history
Inbox refactoring
  • Loading branch information
matthiasn authored Jul 12, 2022
2 parents 02048f0 + 2543bd4 commit 9e0c2c0
Show file tree
Hide file tree
Showing 24 changed files with 654 additions and 490 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Changed:
- Simplified & cleaner Inbox Service

## [0.8.101] - 2022-07-11
### Changed:
- Show duration

## [0.8.100] - 2022-07-10
Expand Down
4 changes: 2 additions & 2 deletions lib/blocs/sync/sync_config_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:lotti/classes/config.dart';
import 'package:lotti/get_it.dart';
import 'package:lotti/services/sync_config_service.dart';
import 'package:lotti/sync/inbox_service.dart';
import 'package:lotti/sync/inbox/inbox_service.dart';
import 'package:lotti/sync/outbox_service.dart';

part 'sync_config_cubit.freezed.dart';
Expand Down Expand Up @@ -46,7 +46,7 @@ class SyncConfigCubit extends Cubit<SyncConfigState> {
await testConnection();

if (imapConfig != null && sharedSecret != null) {
await getIt<SyncInboxService>().init();
await getIt<InboxService>().init();
await getIt<OutboxService>().init();
}
}
Expand Down
8 changes: 6 additions & 2 deletions lib/get_it.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import 'package:lotti/services/sync_config_service.dart';
import 'package:lotti/services/tags_service.dart';
import 'package:lotti/services/time_service.dart';
import 'package:lotti/services/vector_clock_service.dart';
import 'package:lotti/sync/inbox_service.dart';
import 'package:lotti/sync/connectivity.dart';
import 'package:lotti/sync/fg_bg.dart';
import 'package:lotti/sync/inbox/inbox_service.dart';
import 'package:lotti/sync/outbox_service.dart';
import 'package:lotti/themes/themes_service.dart';

Expand All @@ -24,6 +26,8 @@ final getIt = GetIt.instance;
void registerSingletons() {
getIt
..registerSingleton<JournalDb>(JournalDb())
..registerSingleton<ConnectivityService>(ConnectivityService())
..registerSingleton<FgBgService>(FgBgService())
..registerSingleton<ThemesService>(ThemesService())
..registerSingleton<EditorDb>(EditorDb())
..registerSingleton<TagsService>(TagsService())
Expand All @@ -36,7 +40,7 @@ void registerSingletons() {
..registerSingleton<PersistenceLogic>(PersistenceLogic())
..registerSingleton<EditorStateService>(EditorStateService())
..registerSingleton<HealthImport>(HealthImport())
..registerSingleton<SyncInboxService>(SyncInboxService())
..registerSingleton<InboxService>(InboxService())
..registerSingleton<LinkService>(LinkService())
..registerSingleton<NotificationService>(NotificationService())
..registerSingleton<Maintenance>(Maintenance())
Expand Down
2 changes: 1 addition & 1 deletion lib/services/sync_config_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:lotti/classes/config.dart';
import 'package:lotti/get_it.dart';
import 'package:lotti/services/vector_clock_service.dart';
import 'package:lotti/sync/imap_client.dart';
import 'package:lotti/sync/inbox_service.dart';
import 'package:lotti/sync/secure_storage.dart';
import 'package:lotti/sync/utils.dart';

class SyncConfigService {
final sharedSecretKey = 'sharedSecret';
Expand Down
42 changes: 42 additions & 0 deletions lib/sync/connectivity.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'dart:async';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:lotti/database/logging_db.dart';
import 'package:lotti/get_it.dart';

class ConnectivityService {
ConnectivityService() {
_broadcastStream = _controller.stream.asBroadcastStream();

Connectivity().onConnectivityChanged.listen(
(ConnectivityResult result) {
debugPrint('Connectivity onConnectivityChanged $result');
getIt<LoggingDb>().captureEvent(
'onConnectivityChanged $result',
domain: 'CONNECTIVITY',
);
_controller.add(result != ConnectivityResult.none);
},
onError: (Object error, Object stacktrace) {
getIt<LoggingDb>().captureException(
error,
stackTrace: stacktrace,
domain: 'CONNECTIVITY',
);
},
);
}

final _controller = StreamController<bool>();
late final Stream<bool> _broadcastStream;

Future<bool> isConnected() async {
final status = await Connectivity().checkConnectivity();
return status != ConnectivityResult.none;
}

Stream<bool> get connectedStream {
return _broadcastStream;
}
}
34 changes: 34 additions & 0 deletions lib/sync/fg_bg.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:async';

import 'package:flutter_fgbg/flutter_fgbg.dart';
import 'package:lotti/database/logging_db.dart';
import 'package:lotti/get_it.dart';
import 'package:lotti/utils/platform.dart';

class FgBgService {
FgBgService() {
_broadcastStream = _controller.stream.asBroadcastStream();

if (isMobile) {
FGBGEvents.stream.listen(
(result) {
_controller.add(result != FGBGType.foreground);
},
onError: (Object error, Object stacktrace) {
getIt<LoggingDb>().captureException(
error,
stackTrace: stacktrace,
domain: 'FG_BG',
);
},
);
}
}

final _controller = StreamController<bool>();
late final Stream<bool> _broadcastStream;

Stream<bool> get fgBgStream {
return _broadcastStream;
}
}
4 changes: 4 additions & 0 deletions lib/sync/imap_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ Future<ImapClient?> createImapClient(
timeout: connectionTimeout,
);

debugPrint('ImapClient created');

loggingDb.captureEvent(
'ImapClient created',
domain: 'IMAP_CLIENT $clientId',
);

await imapClient.login(imapConfig.userName, imapConfig.password);

debugPrint('ImapClient logged in');

loggingDb.captureEvent(
'ImapClient logged in',
domain: 'IMAP_CLIENT $clientId',
Expand Down
Loading

0 comments on commit 9e0c2c0

Please sign in to comment.