aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/stores/Service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/stores/Service.ts')
-rw-r--r--packages/main/src/stores/Service.ts35
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
21import type { UnreadCount } from '@sophie/service-shared'; 21import type { UnreadCount } from '@sophie/service-shared';
22import { Service as ServiceBase } from '@sophie/shared'; 22import { Service as ServiceBase } from '@sophie/shared';
23import { Instance, getSnapshot, ReferenceIdentifier } from 'mobx-state-tree'; 23import { Instance, getSnapshot } from 'mobx-state-tree';
24 24
25import generateId from '../utils/generateId';
26import overrideProps from '../utils/overrideProps'; 25import overrideProps from '../utils/overrideProps';
27 26
28import { ProfileSettingsSnapshotWithId } from './Profile'; 27import ServiceSettings from './ServiceSettings';
29import ServiceSettings, { ServiceSettingsSnapshotIn } from './ServiceSettings'; 28import type ServiceConfig from './config/ServiceConfig';
30
31export interface ServiceConfig
32 extends Omit<ServiceSettingsSnapshotIn, 'profile'> {
33 id?: string | undefined;
34
35 profile?: ReferenceIdentifier | undefined;
36}
37 29
38const Service = overrideProps(ServiceBase, { 30const Service = overrideProps(ServiceBase, {
39 settings: ServiceSettings, 31 settings: ServiceSettings,
@@ -90,24 +82,3 @@ const Service = overrideProps(ServiceBase, {
90interface Service extends Instance<typeof Service> {} 82interface Service extends Instance<typeof Service> {}
91 83
92export default Service; 84export default Service;
93
94export type ServiceSettingsSnapshotWithId = [string, ServiceSettingsSnapshotIn];
95
96export 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}