MCPcopy Create free account
hub / github.com/CommE2E/comm / useCreateDesktopPushSubscription

Function useCreateDesktopPushSubscription

web/push-notif/push-notifs-handler.js:38–135  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36import { useStaffCanSee } from '../utils/staff-utils.js';
37
38function useCreateDesktopPushSubscription() {
39 const dispatchActionPromise = useDispatchActionPromise();
40 const callSetDeviceToken = useSetDeviceTokenFanout();
41 const staffCanSee = useStaffCanSee();
42 const [notifsOlmSessionMigrated, setNotifsSessionsMigrated] =
43 React.useState<boolean>(false);
44 const platformDetails = getConfig().platformDetails;
45
46 React.useEffect(() => {
47 if (
48 !isDesktopPlatform(platformDetails.platform) ||
49 !hasMinCodeVersion(platformDetails, { majorDesktop: 12 })
50 ) {
51 return;
52 }
53 void (async () => {
54 await migrateLegacyOlmNotificationsSessions();
55 setNotifsSessionsMigrated(true);
56 })();
57 }, [platformDetails]);
58
59 React.useEffect(
60 () =>
61 electron?.onDeviceTokenRegistered?.((token: ?string) => {
62 void dispatchActionPromise(
63 setDeviceTokenActionTypes,
64 callSetDeviceToken(token),
65 undefined,
66 { type: 'device_token', deviceToken: token },
67 );
68 }),
69 [callSetDeviceToken, dispatchActionPromise],
70 );
71
72 React.useEffect(() => {
73 electron?.fetchDeviceToken?.();
74 }, []);
75
76 React.useEffect(() => {
77 if (
78 hasMinCodeVersion(platformDetails, { majorDesktop: 12 }) &&
79 !notifsOlmSessionMigrated
80 ) {
81 return undefined;
82 }
83
84 return electron?.onEncryptedNotification?.(
85 async ({
86 encryptedPayload,
87 senderDeviceDescriptor,
88 type: messageType,
89 }: {
90 encryptedPayload: string,
91 type: string,
92 senderDeviceDescriptor: SenderDeviceDescriptor,
93 }) => {
94 const decryptedPayload = await decryptDesktopNotification(
95 encryptedPayload,

Callers 1

PushNotificationsHandlerFunction · 0.85

Calls 11

useDispatchActionPromiseFunction · 0.90
useSetDeviceTokenFanoutFunction · 0.90
useStaffCanSeeFunction · 0.90
getConfigFunction · 0.90
isDesktopPlatformFunction · 0.90
hasMinCodeVersionFunction · 0.90
useDispatchFunction · 0.90
useSelectorFunction · 0.90
dispatchActionPromiseFunction · 0.85

Tested by

no test coverage detected