refactor: native feature management (#2350)

This commit is contained in:
Mo
2023-07-12 12:56:08 -05:00
committed by GitHub
parent 49f7581cd8
commit 078ef3772c
223 changed files with 3996 additions and 3438 deletions

View File

@@ -29,7 +29,6 @@ import * as Models from '@standardnotes/models'
import * as Responses from '@standardnotes/responses'
import * as InternalServices from '../Services'
import * as Utils from '@standardnotes/utils'
import { Subscription } from '@standardnotes/security'
import { UuidString, ApplicationEventPayload } from '../Types'
import { applicationEventForSyncEvent } from '@Lib/Application/Event'
import {
@@ -50,7 +49,7 @@ import {
EncryptionServiceEvent,
FilesBackupService,
FileService,
SubscriptionClientInterface,
SubscriptionManagerInterface,
SubscriptionManager,
ChallengePrompt,
Challenge,
@@ -151,7 +150,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
private declare userRequestServer: UserRequestServerInterface
private declare subscriptionApiService: SubscriptionApiServiceInterface
private declare subscriptionServer: SubscriptionServerInterface
private declare subscriptionManager: SubscriptionClientInterface
private declare subscriptionManager: SubscriptionManagerInterface
private declare webSocketApiService: WebSocketApiServiceInterface
private declare webSocketServer: WebSocketServerInterface
@@ -275,7 +274,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
this.defineInternalEventHandlers()
}
get subscriptions(): ExternalServices.SubscriptionClientInterface {
get subscriptions(): ExternalServices.SubscriptionManagerInterface {
return this.subscriptionManager
}
@@ -407,6 +406,10 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
return this.sharedVaultService
}
public get preferences(): ExternalServices.PreferenceServiceInterface {
return this.preferencesService
}
public computePrivateUsername(username: string): Promise<string | undefined> {
return ComputePrivateUsername(this.options.crypto, username)
}
@@ -633,6 +636,11 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
}
}
this.internalEventBus.publish({
type: event,
payload: data,
})
void this.migrationService.handleApplicationEvent(event)
}
@@ -671,19 +679,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
return Common.compareVersions(userVersion, Common.ProtocolVersion.V004) >= 0
}
public async getUserSubscription(): Promise<Subscription | Responses.ClientDisplayableError | undefined> {
return this.sessionManager.getSubscription()
}
public async getAvailableSubscriptions(): Promise<
Responses.AvailableSubscriptions | Responses.ClientDisplayableError
> {
if (this.isThirdPartyHostUsed()) {
return ClientDisplayableError.FromString('Third party hosts do not support subscriptions.')
}
return this.sessionManager.getAvailableSubscriptions()
}
/**
* Begin streaming items to display in the UI. The stream callback will be called
* immediately with the present items that match the constraint, and over time whenever
@@ -1268,9 +1263,9 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
this.createSubscriptionApiService()
this.createWebSocketServer()
this.createWebSocketApiService()
this.createSubscriptionManager()
this.createWebSocketsService()
this.createSessionManager()
this.createSubscriptionManager()
this.createHistoryManager()
this.createSyncManager()
this.createProtectionService()
@@ -1498,9 +1493,10 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
private createFeaturesService() {
this.featuresService = new InternalServices.SNFeaturesService(
this.diskStorageService,
this.apiService,
this.itemManager,
this.mutator,
this.subscriptions,
this.apiService,
this.webSocketsService,
this.settingsService,
this.userService,
@@ -1517,8 +1513,8 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
void this.notifyEvent(ApplicationEvent.UserRolesChanged)
break
}
case ExternalServices.FeaturesEvent.FeaturesUpdated: {
void this.notifyEvent(ApplicationEvent.FeaturesUpdated)
case ExternalServices.FeaturesEvent.FeaturesAvailabilityChanged: {
void this.notifyEvent(ApplicationEvent.FeaturesAvailabilityChanged)
break
}
case ExternalServices.FeaturesEvent.DidPurchaseSubscription: {
@@ -1561,6 +1557,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
internalEventBus: this.internalEventBus,
legacySessionStorageMapper: this.legacySessionStorageMapper,
backups: this.fileBackups,
preferences: this.preferencesService,
})
this.services.push(this.migrationService)
}
@@ -1629,7 +1626,13 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
}
private createSubscriptionManager() {
this.subscriptionManager = new SubscriptionManager(this.subscriptionApiService, this.internalEventBus)
this.subscriptionManager = new SubscriptionManager(
this.subscriptionApiService,
this.sessions,
this.storage,
this.internalEventBus,
)
this.services.push(this.subscriptionManager)
}
private createItemManager() {
@@ -1647,8 +1650,8 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
this.alertService,
this.environment,
this.platform,
this.internalEventBus,
this.deviceInterface,
this.internalEventBus,
)
this.services.push(this.componentManagerService)
}