Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3389023
D9633.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D9633.diff
View Options
diff --git a/web/database/database-module-provider.js b/web/database/database-module-provider.js
--- a/web/database/database-module-provider.js
+++ b/web/database/database-module-provider.js
@@ -5,7 +5,7 @@
import {
DATABASE_WORKER_PATH,
- DATABASE_MODULE_FILE_PATH,
+ WORKERS_MODULES_DIR_PATH,
SQLITE_ENCRYPTION_KEY,
} from './utils/constants.js';
import { isDesktopSafari, isSQLiteSupported } from './utils/db-utils.js';
@@ -86,7 +86,7 @@
invariant(this.workerProxy, 'Worker proxy should exist');
await this.workerProxy.scheduleOnWorker({
type: workerRequestMessageTypes.INIT,
- databaseModuleFilePath: `${origin}${baseURL}${DATABASE_MODULE_FILE_PATH}`,
+ databaseModuleFilePath: `${origin}${baseURL}${WORKERS_MODULES_DIR_PATH}`,
encryptionKey,
commQueryExecutorFilename,
});
diff --git a/web/database/utils/constants.js b/web/database/utils/constants.js
--- a/web/database/utils/constants.js
+++ b/web/database/utils/constants.js
@@ -8,10 +8,12 @@
export const CURRENT_USER_ID_KEY = 'current_user_id';
export const DATABASE_WORKER_PATH = 'worker/database';
-export const DATABASE_MODULE_FILE_PATH = '/compiled/webworkers';
+export const WORKERS_MODULES_DIR_PATH = '/compiled/webworkers';
export const DEFAULT_COMM_QUERY_EXECUTOR_FILENAME = 'comm_query_executor.wasm';
+export const DEFAULT_OLM_FILENAME = 'olm.wasm';
+
export const COMM_SQLITE_DATABASE_PATH = 'comm.sqlite';
export const NOTIFICATIONS_OLM_DATA_CONTENT = 'notificationsOlmDataContent';
diff --git a/web/push-notif/notif-crypto-utils.js b/web/push-notif/notif-crypto-utils.js
new file mode 100644
--- /dev/null
+++ b/web/push-notif/notif-crypto-utils.js
@@ -0,0 +1,8 @@
+// @flow
+
+export type WebNotifsServiceUtilsData = {
+ +olmWasmPath: string,
+ +staffCanSee: boolean,
+};
+
+export const WEB_NOTIFS_SERVICE_UTILS_KEY = 'webNotifsServiceUtils';
diff --git a/web/push-notif/push-notifs-handler.js b/web/push-notif/push-notifs-handler.js
--- a/web/push-notif/push-notifs-handler.js
+++ b/web/push-notif/push-notifs-handler.js
@@ -17,10 +17,17 @@
} from 'lib/utils/push-alerts.js';
import { ashoatKeyserverID } from 'lib/utils/validation-utils.js';
+import {
+ WORKERS_MODULES_DIR_PATH,
+ DEFAULT_OLM_FILENAME,
+} from '../database/utils/constants.js';
import electron from '../electron.js';
import PushNotifModal from '../modals/push-notif-modal.react.js';
import { updateNavInfoActionType } from '../redux/action-types.js';
import { useSelector } from '../redux/redux-utils.js';
+import { useStaffCanSee } from '../utils/staff-utils.js';
+
+declare var baseURL: string;
function useCreateDesktopPushSubscription() {
const dispatchActionPromise = useDispatchActionPromise();
@@ -64,6 +71,7 @@
const dispatchActionPromise = useDispatchActionPromise();
const callSetDeviceToken = useSetDeviceTokenFanout();
+ const staffCanSee = useStaffCanSee();
return React.useCallback(async () => {
if (!publicKey) {
@@ -75,6 +83,11 @@
return;
}
+ const origin = window.location.origin;
+ const olmWasmDirPath = `${origin}${baseURL}${WORKERS_MODULES_DIR_PATH}`;
+ const olmWasmPath = `${olmWasmDirPath}/${DEFAULT_OLM_FILENAME}`;
+ workerRegistration.active?.postMessage({ olmWasmPath, staffCanSee });
+
const subscription = await workerRegistration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: publicKey,
@@ -84,7 +97,7 @@
setDeviceTokenActionTypes,
callSetDeviceToken(JSON.stringify(subscription)),
);
- }, [callSetDeviceToken, dispatchActionPromise, publicKey]);
+ }, [callSetDeviceToken, dispatchActionPromise, publicKey, staffCanSee]);
}
function PushNotificationsHandler(): React.Node {
diff --git a/web/push-notif/service-worker.js b/web/push-notif/service-worker.js
--- a/web/push-notif/service-worker.js
+++ b/web/push-notif/service-worker.js
@@ -1,9 +1,17 @@
// @flow
+import localforage from 'localforage';
+
import type { PlainTextWebNotification } from 'lib/types/notif-types.js';
import { convertNonPendingIDToNewSchema } from 'lib/utils/migration-utils.js';
import { ashoatKeyserverID } from 'lib/utils/validation-utils.js';
+import {
+ WEB_NOTIFS_SERVICE_UTILS_KEY,
+ type WebNotifsServiceUtilsData,
+} from './notif-crypto-utils.js';
+import { localforageConfig } from '../database/utils/constants.js';
+
declare class PushMessageData {
json(): Object;
}
@@ -11,6 +19,10 @@
+data: PushMessageData;
}
+declare class CommAppMessage extends ExtendableEvent {
+ +data: { +olmWasmPath?: string, +staffCanSee?: boolean };
+}
+
declare var clients: Clients;
declare function skipWaiting(): Promise<void>;
@@ -22,6 +34,26 @@
event.waitUntil(clients.claim());
});
+self.addEventListener('message', (event: CommAppMessage) => {
+ localforage.config(localforageConfig);
+ event.waitUntil(
+ (async () => {
+ if (!event.data.olmWasmPath || event.data.staffCanSee === undefined) {
+ return;
+ }
+ const webNotifsServiceUtils: WebNotifsServiceUtilsData = {
+ olmWasmPath: event.data.olmWasmPath,
+ staffCanSee: event.data.staffCanSee,
+ };
+
+ await localforage.setItem(
+ WEB_NOTIFS_SERVICE_UTILS_KEY,
+ webNotifsServiceUtils,
+ );
+ })(),
+ );
+});
+
self.addEventListener('push', (event: PushEvent) => {
const data: PlainTextWebNotification = event.data.json();
diff --git a/web/webpack.config.cjs b/web/webpack.config.cjs
--- a/web/webpack.config.cjs
+++ b/web/webpack.config.cjs
@@ -145,6 +145,14 @@
},
],
}),
+ new CopyPlugin({
+ patterns: [
+ {
+ from: 'node_modules/@commapp/olm/olm.wasm',
+ to: path.join(__dirname, 'dist', 'webworkers'),
+ },
+ ],
+ }),
];
const prodWebWorkersPlugins = [
@@ -161,6 +169,19 @@
},
],
}),
+ new CopyPlugin({
+ patterns: [
+ {
+ from: 'node_modules/@commapp/olm/olm.wasm',
+ to: path.join(
+ __dirname,
+ 'dist',
+ 'webworkers',
+ 'olm.[contenthash:12].wasm',
+ ),
+ },
+ ],
+ }),
new WebpackManifestPlugin({
publicPath: '',
}),
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 5:09 PM (21 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2601732
Default Alt Text
D9633.diff (6 KB)
Attached To
Mode
D9633: Expose olm WASM to push notif service-worker on web.
Attached
Detach File
Event Timeline
Log In to Comment