// Metro module 11507 (f11508). import MultiAccountStore from "../../modules/multi_account/MultiAccountStore"; import AuthenticationStore from "../../stores/AuthenticationStore"; import { DEVICE_TOKEN, DEVICE_VOIP_TOKEN, Endpoints } from "../../Constants"; import { BUNDLE_ID, DEVICE_PUSH_VOIP_PROVIDER, IS_QUEST_RELEASE, getDevicePushProvider } from "../../modules/push_notifications/PushNotificationConstants"; import Logger from "../../modules/debug/Logger"; import { getToken } from "../../_bundle/setSecondaryToken"; import { HTTP } from "../../_bundle/sendRequest"; import SentryUtils_native from "../../utils/SentryUtils.native"; import { updatePushSyncToken, invalidatePushSyncTokens } from "../../modules/multi_account/MultiAccountActionCreators"; import { Storage } from "../../_bundle/Module595"; import TrackedHTTPUtils from "../../utils/TrackedHTTPUtils"; import { isAndroid } from "../../utils/PlatformUtils"; import { NetworkActionNames } from "../../_bundle/Module503"; import { isNotNullish } from "../../utils/GlobalUtils"; import Dispatcher from "../../Dispatcher"; let c7842_14; const getOrRefreshPushSyncToken = async function getOrRefreshPushSyncToken(c27089_0) { let r78, pushSyncToken; let c27089_3; let c27089_4 = 0; let c30411_0, c30411_1, c30411_2; L15: { L14: { try { c30411_0 = c27089_0; c30411_1 = void 0; if (c27089_0.pushSyncToken == null) { const token = getToken(c27089_0.id); if (token == null) { break L15; } c27089_4 = 1; c30411_1 = (await HTTP.get({ url: Endpoints.DEVICES_SYNC_TOKEN, headers: { authorization: token }, rejectWithError: false })).body.token; c27089_4 = 0; updatePushSyncToken(c30411_0.id, c30411_1); r78 = c30411_1; break L14; } pushSyncToken = c27089_0.pushSyncToken; } catch ($e) { const r26 = $e; let r8 = r26; c27089_3 = r26; if (c27089_4 !== 0) { while (true) { try { const r87 = c27089_3; c27089_4 = 0; c30411_2 = r87; SentryUtils_native.captureException(c30411_2); } catch (r83) { r8 = r83; c27089_3 = r83; if (c27089_4 === 0) { break; } continue; } return null; } } throw r8; } return pushSyncToken; } return r78; } return null; }; c7842_14 = new Logger("PushNotificationActionCreators"); const r42 = { registerDevice: function registerDevice(a0, r3 = false) { c7842_14.log(`Registering push notification token: ${a0}, is voip:${r3}, multi-account:${MultiAccountStore.canUseMultiAccountNotifications}`); const r27 = r3; Storage.set(r27 ? DEVICE_VOIP_TOKEN : DEVICE_TOKEN, a0); return MultiAccountStore.canUseMultiAccountNotifications ? this.syncDevice(a0, r27) : TrackedHTTPUtils.post({ url: Endpoints.DEVICES, body: { provider: r27 ? DEVICE_PUSH_VOIP_PROVIDER : getDevicePushProvider(), token: a0, bypass_server_throttling_supported: isAndroid() && !IS_QUEST_RELEASE, bundle_id: BUNDLE_ID }, oldFormErrors: true, trackedActionData: { event: NetworkActionNames.USER_REGISTER_DEVICE_TOKEN }, rejectWithError: false }); }, syncDevice: async function syncDevice(c18905_0, r4 = false) { let c18905_1 = r4; let c27090_1; let env30412; c27090_1 = void 0; const r16 = env30412 = {}; let c27090_0 = r16; env30412[0] = void 0; env30412[1] = void 0; env30412[2] = void 0; env30412[0] = AuthenticationStore.getId(); env30412[1] = await Promise.all(MultiAccountStore.getValidUsers().sort(function({ id }, b) { const r6 = env30412[0]; return id !== r6 ? b.id === r6 ? 1 : 0 : -1; }).map(getOrRefreshPushSyncToken)); if (!(env30412[1].length < 1) && env30412[1][0] != null) { env30412[2] = await HTTP.put({ url: Endpoints.DEVICES_SYNC, body: { provider: c18905_1 ? DEVICE_PUSH_VOIP_PROVIDER : (0, getDevicePushProvider)(), token: c18905_0, push_sync_tokens: env30412[1].filter(isNotNullish), bypass_server_throttling_supported: isAndroid() && !IS_QUEST_RELEASE, bundle_id: BUNDLE_ID }, rejectWithError: false }); if (env30412[2].body.invalid_push_sync_tokens.length > 0) { invalidatePushSyncTokens(env30412[2].body.invalid_push_sync_tokens); } } }, unregisterDevice: (a0) => { c7842_14.log(`Unregistering push notification token: ${a0}`); return TrackedHTTPUtils.delete({ url: Endpoints.DEVICES, body: { provider: getDevicePushProvider(), token: a0 }, trackedActionData: { event: NetworkActionNames.USER_UNREGISTER_DEVICE_TOKEN }, rejectWithError: false }); } }; export default r42; export function setPushPermissionState(permissionState) { Dispatcher.wait(() => { Dispatcher.dispatch({ type: "PUSH_NOTIFICATION_PERMISSION_SET_STATE", permissionState }); }); } export function setPushPermissionReactivationSeen(a0) { Dispatcher.dispatch({ type: "PUSH_NOTIFICATION_PERMISSION_REACTIVATION_SEEN", promptType: a0 }); } export function setPushNotificationPermissionEligibleForPrompt(a0) { Dispatcher.dispatch({ type: "PUSH_NOTIFICATION_PERMISSION_SET_ELIGIBLE", promptType: a0 }); } export function updateNotificationAuthorizationStatus(a0) { Dispatcher.dispatch({ type: "PUSH_NOTIFICATION_AUTHORIZATION_STATUS_UPDATE", authorizationStatus: a0 }); }