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

fix: add enrollmentId to SyncService/NotificationService #1151

Merged
merged 6 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 4 additions & 6 deletions packages/at_client/lib/src/client/at_client_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ class AtClientImpl implements AtClient, AtSignChangeListener {

late final AtSignLogger _logger;

String? _enrollmentId;

@visibleForTesting
static final Map atClientInstanceMap = <String, AtClient>{};

Expand All @@ -126,7 +124,6 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
EncryptionService? encryptionService,
SecondaryKeyStore? localSecondaryKeyStore,
AtChops? atChops,
String? enrollmentId,
AtClientCommitLogCompaction? atClientCommitLogCompaction,
AtClientConfig? atClientConfig}) async {
atClientManager ??= AtClientManager.getInstance();
Expand Down Expand Up @@ -162,7 +159,6 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
EncryptionService? encryptionService,
SecondaryKeyStore? localSecondaryKeyStore,
AtChops? atChops,
String? enrollmentId,
AtClientCommitLogCompaction? atClientCommitLogCompaction,
AtClientConfig? atClientConfig}) {
_atSign = AtUtils.fixAtSign(theAtSign);
Expand All @@ -179,7 +175,6 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
_remoteSecondary = remoteSecondary;
_encryptionService = encryptionService;
_atChops = atChops;
_enrollmentId = enrollmentId;
_atClientCommitLogCompaction = atClientCommitLogCompaction;
}

Expand All @@ -198,7 +193,7 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
_remoteSecondary ??= RemoteSecondary(_atSign, _preference!,
atChops: atChops,
privateKey: _preference!.privateKey,
enrollmentId: _enrollmentId);
enrollmentId: enrollmentId);

// Now using ??= because we may be injecting an EncryptionService
_encryptionService ??= EncryptionService(_atSign);
Expand Down Expand Up @@ -996,4 +991,7 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
}
return result.notificationID;
}

@override
String? enrollmentId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this up to line 117 please?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
5 changes: 5 additions & 0 deletions packages/at_client/lib/src/client/at_client_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ abstract class AtClient {

AtChops? get atChops;

/// Enrollment id for apkam enrolled clients
set enrollmentId(String? enrollmentId);

String? get enrollmentId;

set syncService(SyncService syncService);
SyncService get syncService;

Expand Down
10 changes: 4 additions & 6 deletions packages/at_client/lib/src/manager/at_client_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class AtClientManager {
var previousAtClient = _currentAtClient;
_currentAtClient = await serviceFactory
.atClient(_atSign, namespace, preference, this, atChops: atChops);

_currentAtClient?.enrollmentId = enrollmentId;
final switchAtSignEvent =
SwitchAtSignEvent(previousAtClient, _currentAtClient!);
_notifyListeners(switchAtSignEvent);
Expand Down Expand Up @@ -144,7 +144,7 @@ class AtClientManager {
abstract class AtServiceFactory {
Future<AtClient> atClient(String atSign, String? namespace,
AtClientPreference preference, AtClientManager atClientManager,
{AtChops? atChops, String? enrollmentId});
{AtChops? atChops});

Future<NotificationService> notificationService(
AtClient atClient, AtClientManager atClientManager);
Expand All @@ -157,11 +157,9 @@ class DefaultAtServiceFactory implements AtServiceFactory {
@override
Future<AtClient> atClient(String atSign, String? namespace,
AtClientPreference preference, AtClientManager atClientManager,
{AtChops? atChops, String? enrollmentId}) async {
{AtChops? atChops}) async {
return await AtClientImpl.create(atSign, namespace, preference,
atClientManager: atClientManager,
atChops: atChops,
enrollmentId: enrollmentId);
atClientManager: atClientManager, atChops: atChops);
}

@override
Expand Down
1 change: 1 addition & 0 deletions packages/at_client/lib/src/manager/monitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class Monitor {
_keepAlive = monitorPreference.keepAlive;
_lastNotificationTime = monitorPreference.lastNotificationTime;
_enrollmentId = enrollmentId;
_logger.finer('enrollmentId: $_enrollmentId');
_remoteSecondary = remoteSecondary ??
RemoteSecondary(atSign, preference,
atChops: atChops, enrollmentId: enrollmentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class NotificationServiceImpl
_atClient = atClient;
_logger = AtSignLogger(
'NotificationServiceImpl (${_atClient.getCurrentAtSign()})');

_logger.finer('enrollmentId: ${atClient.enrollmentId}');
_monitor = monitor ??
Monitor(
_internalNotificationCallback,
Expand All @@ -98,7 +100,8 @@ class NotificationServiceImpl
_atClient.getPreferences()!,
MonitorPreference()..keepAlive = true,
monitorRetry,
atChops: atClient.atChops);
atChops: atClient.atChops,
enrollmentId: atClient.enrollmentId);
_atClientManager.listenToAtSignChange(this);
lastReceivedNotificationAtKey = AtKey.local(
lastReceivedNotificationKey, _atClient.getCurrentAtSign()!,
Expand Down
2 changes: 1 addition & 1 deletion packages/at_client/lib/src/service/sync_service_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SyncServiceImpl implements SyncService, AtSignChangeListener {
RemoteSecondary? remoteSecondary}) async {
remoteSecondary ??= RemoteSecondary(
atClient.getCurrentAtSign()!, atClient.getPreferences()!,
atChops: atClient.atChops);
atChops: atClient.atChops, enrollmentId: atClient.enrollmentId);
final syncService = SyncServiceImpl._(
atClientManager, atClient, notificationService, remoteSecondary);
await syncService.statsServiceListener();
Expand Down