diff options
Diffstat (limited to 'packages/main/src/stores/Service.ts')
-rw-r--r-- | packages/main/src/stores/Service.ts | 35 |
1 files changed, 3 insertions, 32 deletions
diff --git a/packages/main/src/stores/Service.ts b/packages/main/src/stores/Service.ts index e70caa6..fea0bdf 100644 --- a/packages/main/src/stores/Service.ts +++ b/packages/main/src/stores/Service.ts | |||
@@ -20,20 +20,12 @@ | |||
20 | 20 | ||
21 | import type { UnreadCount } from '@sophie/service-shared'; | 21 | import type { UnreadCount } from '@sophie/service-shared'; |
22 | import { Service as ServiceBase } from '@sophie/shared'; | 22 | import { Service as ServiceBase } from '@sophie/shared'; |
23 | import { Instance, getSnapshot, ReferenceIdentifier } from 'mobx-state-tree'; | 23 | import { Instance, getSnapshot } from 'mobx-state-tree'; |
24 | 24 | ||
25 | import generateId from '../utils/generateId'; | ||
26 | import overrideProps from '../utils/overrideProps'; | 25 | import overrideProps from '../utils/overrideProps'; |
27 | 26 | ||
28 | import { ProfileSettingsSnapshotWithId } from './Profile'; | 27 | import ServiceSettings from './ServiceSettings'; |
29 | import ServiceSettings, { ServiceSettingsSnapshotIn } from './ServiceSettings'; | 28 | import type ServiceConfig from './config/ServiceConfig'; |
30 | |||
31 | export interface ServiceConfig | ||
32 | extends Omit<ServiceSettingsSnapshotIn, 'profile'> { | ||
33 | id?: string | undefined; | ||
34 | |||
35 | profile?: ReferenceIdentifier | undefined; | ||
36 | } | ||
37 | 29 | ||
38 | const Service = overrideProps(ServiceBase, { | 30 | const Service = overrideProps(ServiceBase, { |
39 | settings: ServiceSettings, | 31 | settings: ServiceSettings, |
@@ -90,24 +82,3 @@ const Service = overrideProps(ServiceBase, { | |||
90 | interface Service extends Instance<typeof Service> {} | 82 | interface Service extends Instance<typeof Service> {} |
91 | 83 | ||
92 | export default Service; | 84 | export default Service; |
93 | |||
94 | export type ServiceSettingsSnapshotWithId = [string, ServiceSettingsSnapshotIn]; | ||
95 | |||
96 | export function addMissingServiceIdsAndProfiles( | ||
97 | serviceConfigs: ServiceConfig[] | undefined, | ||
98 | profiles: ProfileSettingsSnapshotWithId[], | ||
99 | ): ServiceSettingsSnapshotWithId[] { | ||
100 | return (serviceConfigs ?? []).map((serviceConfig) => { | ||
101 | const { id, ...settings } = serviceConfig; | ||
102 | const { name } = settings; | ||
103 | let { profile: profileId } = settings; | ||
104 | if (profileId === undefined) { | ||
105 | profileId = generateId(name); | ||
106 | profiles.push([profileId, { name }]); | ||
107 | } | ||
108 | return [ | ||
109 | id === undefined ? generateId(name) : id, | ||
110 | { ...settings, profile: profileId }, | ||
111 | ]; | ||
112 | }); | ||
113 | } | ||