Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/push/providers.js
// @flow | // @flow | ||||
import apn from '@parse/node-apn'; | import apn from '@parse/node-apn'; | ||||
import type { Provider as APNProvider } from '@parse/node-apn'; | import type { Provider as APNProvider } from '@parse/node-apn'; | ||||
import fcmAdmin from 'firebase-admin'; | import fcmAdmin from 'firebase-admin'; | ||||
import type { FirebaseApp } from 'firebase-admin'; | import type { FirebaseApp } from 'firebase-admin'; | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
import webpush from 'web-push'; | import webpush from 'web-push'; | ||||
import type { PlatformDetails } from 'lib/types/device-types'; | |||||
import { importJSON } from '../utils/import-json.js'; | import { importJSON } from '../utils/import-json.js'; | ||||
type APNPushProfile = 'apn_config' | 'comm_apn_config'; | type APNPushProfile = 'apn_config' | 'comm_apn_config'; | ||||
function getAPNPushProfileForCodeVersion(codeVersion: ?number): APNPushProfile { | function getAPNPushProfileForCodeVersion( | ||||
return codeVersion && codeVersion >= 87 ? 'comm_apn_config' : 'apn_config'; | platformDetails: PlatformDetails, | ||||
): APNPushProfile { | |||||
if (platformDetails.platform === 'macos') { | |||||
return 'comm_apn_config'; | |||||
} | |||||
return platformDetails.codeVersion && platformDetails.codeVersion >= 87 | |||||
? 'comm_apn_config' | |||||
: 'apn_config'; | |||||
} | } | ||||
type FCMPushProfile = 'fcm_config' | 'comm_fcm_config'; | type FCMPushProfile = 'fcm_config' | 'comm_fcm_config'; | ||||
function getFCMPushProfileForCodeVersion(codeVersion: ?number): FCMPushProfile { | function getFCMPushProfileForCodeVersion(codeVersion: ?number): FCMPushProfile { | ||||
return codeVersion && codeVersion >= 87 ? 'comm_fcm_config' : 'fcm_config'; | return codeVersion && codeVersion >= 87 ? 'comm_fcm_config' : 'fcm_config'; | ||||
} | } | ||||
const cachedAPNProviders = new Map(); | const cachedAPNProviders = new Map(); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
function endAPNs() { | function endAPNs() { | ||||
for (const provider of cachedAPNProviders.values()) { | for (const provider of cachedAPNProviders.values()) { | ||||
provider?.shutdown(); | provider?.shutdown(); | ||||
} | } | ||||
} | } | ||||
function getAPNsNotificationTopic(codeVersion: ?number): string { | function getAPNsNotificationTopic(platformDetails: PlatformDetails): string { | ||||
return codeVersion && codeVersion >= 87 ? 'app.comm' : 'org.squadcal.app'; | if (platformDetails.platform === 'macos') { | ||||
return 'app.comm.macos'; | |||||
} | |||||
return platformDetails.codeVersion && platformDetails.codeVersion >= 87 | |||||
? 'app.comm' | |||||
: 'org.squadcal.app'; | |||||
} | } | ||||
type WebPushConfig = { +publicKey: string, +privateKey: string }; | type WebPushConfig = { +publicKey: string, +privateKey: string }; | ||||
let cachedWebPushConfig: ?WebPushConfig = null; | let cachedWebPushConfig: ?WebPushConfig = null; | ||||
async function getWebPushConfig(): Promise<?WebPushConfig> { | async function getWebPushConfig(): Promise<?WebPushConfig> { | ||||
if (cachedWebPushConfig) { | if (cachedWebPushConfig) { | ||||
return cachedWebPushConfig; | return cachedWebPushConfig; | ||||
} | } | ||||
Show All 32 Lines |