onPublishModelLoaded method
Called when the publish model is loaded.
Implementation
Future<bool> onPublishModelLoaded(String projectId) async {
bool didChange = false;
final bool shouldInitLocalStorage =
_localDatabase == null || (_localDatabase!.identifier != projectId);
if (shouldInitLocalStorage) {
log('Initializing local storage for project $projectId...');
_localDatabase?.reset();
_localDatabase = await initializeLocalStorage(projectId: projectId);
didChange = true;
log('Local storage initialized.');
} else {
log('Local storage already initialized correctly. Skipping.');
}
final bool shouldInitCloudStorage = _cloudDatabase == null ||
(cloudDatabase!.publishSource != config.publishSource ||
cloudDatabase!.identifier != projectId);
bool isAuthenticated = false;
if (shouldInitCloudStorage) {
isAuthenticated = authManager.isAuthenticated() &&
authManager.hasCloudStorageAccess(projectId);
}
if (shouldInitCloudStorage && isAuthenticated) {
log('Initializing cloud storage for project $projectId...');
_cloudDatabase?.reset();
_cloudDatabase = await initializeCloudStorage(projectId: projectId);
_publishModelStreamController.add(_publishModel);
didChange = true;
log('Cloud storage initialized.');
} else {
if (shouldInitCloudStorage) {
log('Cloud storage cannot be initialized because the user is not authenticated.');
} else {
log('Cloud storage already initialized correctly. Skipping.');
}
}
return didChange;
}