Skip to content

Commit fc6c6c3

Browse files
committed
remove app state
1 parent e8d4297 commit fc6c6c3

5 files changed

Lines changed: 36 additions & 32 deletions

File tree

__test__/unit/pushSubscription/nativePermissionChange.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import { createPushSub } from '__test__/support/environment/TestEnvironmentHelpe
1010
import { MockServiceWorker } from '__test__/support/mocks/MockServiceWorker';
1111
import { clearStore, db, getOptionsValue } from 'src/shared/database/client';
1212
import { setAppState as setDBAppState } from 'src/shared/database/config';
13+
import type { AppState } from 'src/shared/database/types';
1314
import * as PermissionUtils from 'src/shared/helpers/permissions';
1415
import Emitter from 'src/shared/libraries/Emitter';
1516
import { checkAndTriggerSubscriptionChanged } from 'src/shared/listeners';
16-
import { AppState } from 'src/shared/models/AppState';
1717
import MainHelper from '../../../src/shared/helpers/MainHelper';
1818

1919
vi.mock('src/shared/libraries/Log');

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@
8484
},
8585
{
8686
"path": "./build/releases/OneSignalSDK.page.es6.js",
87-
"limit": "51.91 kB",
87+
"limit": "51.88 kB",
8888
"gzip": true
8989
},
9090
{
9191
"path": "./build/releases/OneSignalSDK.sw.js",
92-
"limit": "14.04 kB",
92+
"limit": "14.01 kB",
9393
"gzip": true
9494
},
9595
{

src/shared/database/config.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getConsentRequired } from '../helpers/localStorage';
22
import Log from '../libraries/Log';
3-
import { AppState } from '../models/AppState';
43
import { db, getIdsValue, getOptionsValue } from './client';
4+
import type { AppState } from './types';
55

66
export const getDBAppConfig = async () => {
77
const config: any = {};
@@ -12,21 +12,27 @@ export const getDBAppConfig = async () => {
1212
};
1313

1414
export const getAppState = async (): Promise<AppState> => {
15-
const state = new AppState();
16-
state.defaultNotificationUrl = await getOptionsValue<string>('defaultUrl');
17-
state.defaultNotificationTitle =
15+
const defaultNotificationUrl = await getOptionsValue<string>('defaultUrl');
16+
const defaultNotificationTitle =
1817
await getOptionsValue<string>('defaultTitle');
19-
state.lastKnownPushEnabled = await getOptionsValue<boolean>('isPushEnabled');
20-
state.lastKnownOptedIn = await getOptionsValue<boolean>('lastOptedIn');
18+
const lastKnownPushEnabled = await getOptionsValue<boolean>('isPushEnabled');
19+
const lastKnownOptedIn = await getOptionsValue<boolean>('lastOptedIn');
2120

2221
// lastKnown<PushId|PushToken|OptedIn> are used to track changes to the user's subscription
2322
// state. Displayed in the `current` & `previous` fields of the `subscriptionChange` event.
2423
// want undefined instead of null since its used to check for subscription changes
25-
state.lastKnownPushId =
24+
const lastKnownPushId =
2625
(await getOptionsValue<string>('lastPushId')) ?? undefined;
27-
state.lastKnownPushToken =
26+
const lastKnownPushToken =
2827
(await getOptionsValue<string>('lastPushToken')) ?? undefined;
29-
return state;
28+
return {
29+
defaultNotificationUrl,
30+
defaultNotificationTitle,
31+
lastKnownPushEnabled,
32+
lastKnownPushId,
33+
lastKnownPushToken,
34+
lastKnownOptedIn,
35+
};
3036
};
3137

3238
export const setAppState = async (appState: AppState) => {

src/shared/database/types.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
NotificationClickForOpenHandlingSchema,
55
NotificationReceivedForOutcomesSchema,
66
} from '../helpers/serializer';
7-
import type { AppState } from '../models/AppState';
87
import type { SentUniqueOutcome } from '../models/Outcomes';
98
import type { Session } from '../session/types';
109

@@ -187,4 +186,22 @@ export interface IndexedDBSchema extends DBSchema {
187186
};
188187
}
189188

189+
export interface AppState {
190+
defaultNotificationUrl: string | null | undefined;
191+
defaultNotificationTitle: string | null | undefined;
192+
193+
/**
194+
* Whether the user is currently completely subscribed, including not opted out. Database cached version of
195+
* isPushNotificationsEnabled().
196+
*/
197+
lastKnownPushEnabled: boolean | null | undefined;
198+
199+
lastKnownPushToken: string | null | undefined;
200+
201+
lastKnownPushId: string | null | undefined;
202+
203+
// default true
204+
lastKnownOptedIn: boolean | null;
205+
}
206+
190207
export type IDBStoreName = StoreNames<IndexedDBSchema>;

src/shared/models/AppState.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)