()
| 36 | import { useStaffCanSee } from '../utils/staff-utils.js'; |
| 37 | |
| 38 | function 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, |
no test coverage detected