decord/source/actions/native/PushNotificationActionCreators.tsx

254 lines
9.5 KiB
TypeScript
Raw Normal View History

// Module ID: 12442
// Function ID: 12443
// Name: PushNotificationActionCreators
// Dependencies: [5, 12443, 502, 1074, 6610, 3, 1099, 1272, 1232, 12447, 510, 4767, 1115, 1250, 1369, 573, 2]
2026-07-20 16:05:17 +00:00
// Exports: setPushNotificationPermissionEligibleForPrompt, setPushPermissionReactivationSeen, setPushPermissionState, updateNotificationAuthorizationStatus
// Module 12442 (PushNotificationActionCreators)
import LoggerDefault from "Logger" /* 3 */;
import Storage2 from "Storage" /* 510 */;
import DispatcherDefault from "Dispatcher" /* 573 */;
import TokenManagerAll from "TokenManager" /* 1099 */;
import discord_common_AnalyticsUtils from "discord_common/AnalyticsUtils" /* 1250 */;
import HTTPUtils from "HTTPUtils" /* 1272 */;
import TrackedHTTPUtilsDefault from "TrackedHTTPUtils" /* 4767 */;
import asyncGeneratorStep from "asyncGeneratorStep" /* 5 */;
import MultiAccountStore from "MultiAccountStore" /* 12443 */;
import AuthenticationStore from "AuthenticationStore" /* 502 */;
2026-07-23 10:11:24 +00:00
require = fn;
2026-07-20 16:05:17 +00:00
function getOrRefreshPushSyncToken() {
2026-07-29 08:29:29 +00:00
const self = this;
const apply = closure_16.apply;
2026-07-29 08:29:29 +00:00
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
2026-07-20 16:05:17 +00:00
}
let closure_16 = async function _getOrRefreshPushSyncToken(arg0) {
let pushSyncToken = arg0;
c5 = 0;
c6 = 0;
c4 = 0;
return (async (arg0, value) => {
if (c6 === 2) {
c6 = 3;
throw new TypeError("Generator functions may not be called on executing generators");
} else if (tmp7 === 3) {
if (arg0 === 1) {
throw value;
} else if (arg0 === 2) {
const obj2 = { value, done: true };
return obj2;
2026-07-29 08:29:29 +00:00
} else {
return { value: "HermesInternal", done: null };
}
} else {
try {
c6 = 2;
if (0 === c5) {
if (arg0 === 1) {
2026-07-29 08:29:29 +00:00
c6 = 3;
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
c6 = 3;
const obj3 = { value, done: true };
return obj3;
2026-07-29 08:29:29 +00:00
} else {
closure_2 = tmp3;
closure_1 = tmp5;
closure_129_0 = pushSyncToken;
let token2;
if (null == pushSyncToken.pushSyncToken) {
const token = TokenManagerAll.getToken(tmp39.id);
if (null == token) {
c6 = 3;
return { value: null, done: true };
} else {
c4 = 1;
const HTTP = HTTPUtils.HTTP;
const obj5 = { url: constants.DEVICES_SYNC_TOKEN, headers: null, rejectWithError: false };
const obj7 = { authorization: token };
obj5.headers = obj7;
c5 = 2;
c6 = 1;
const obj8 = { value: HTTP.get(obj5), done: false };
return obj8;
}
} else {
c6 = 3;
const obj9 = { value: tmp39.pushSyncToken, done: true };
return obj9;
}
2026-07-29 08:29:29 +00:00
}
} else if (1 === tmp8) {
c4 = 0;
closure_129_2 = closure_3;
closure_130_1(closure_130_3[8]).captureException(closure_129_2);
c6 = 3;
return { value: null, done: true };
} else if (arg0 === 1) {
c6 = 3;
throw value;
} else if (arg0 === 2) {
c4 = 0;
c6 = 3;
const obj10 = { value, done: true };
return obj10;
} else {
token2 = value.body.token;
c4 = 0;
closure_130_2(closure_130_3[9]).updatePushSyncToken(closure_129_0.id, token2);
c6 = 3;
const obj11 = { value: token2, done: true };
return obj11;
}
} catch (tmp31) {
closure_3 = tmp31;
if (tmp4 === c4) {
c6 = tmp2;
throw tmp31;
} else {
c5 = tmp;
2026-07-29 08:29:29 +00:00
}
}
}
})();
};
const Constants = fn(1074);
({ DEVICE_TOKEN: closure_7, DEVICE_VOIP_TOKEN: closure_8, Endpoints: closure_9 } = Constants);
const PushNotificationConstants = fn(6610);
({ BUNDLE_ID: c10, DEVICE_PUSH_VOIP_PROVIDER: closure_11, getDevicePushProvider: closure_12, IS_QUEST_RELEASE: map1 } = PushNotificationConstants);
const logger = new LoggerDefault("PushNotificationActionCreators");
const size = fn(2);
let result = size.fileFinishedImporting("actions/native/PushNotificationActionCreators.tsx");
export default {
2026-07-20 16:05:17 +00:00
registerDevice(token, flag) {
if (flag === undefined) {
flag = false;
}
const canUseMultiAccountNotifications = MultiAccountStore.canUseMultiAccountNotifications;
2026-08-24 06:08:38 +00:00
logger.log("Registering push notification token: " + token + ", is voip:" + flag + ", multi-account:" + canUseMultiAccountNotifications);
const Storage = Storage2.Storage;
const result = Storage.set(flag ? React6 : React5, token);
2026-07-20 16:05:17 +00:00
if (canUseMultiAccountNotifications) {
2026-07-29 08:29:29 +00:00
const self = this;
let syncDeviceResult = this.syncDevice(token, flag);
2026-07-20 16:05:17 +00:00
} else {
const request = { url: constants.DEVICES, body: null, oldFormErrors: true, trackedActionData: null, rejectWithError: false };
2026-07-20 16:05:17 +00:00
if (flag) {
let tmp8 = closure_1_11;
2026-07-20 16:05:17 +00:00
} else {
tmp8 = closure_1_12();
2026-07-20 16:05:17 +00:00
}
const obj2 = { provider: tmp8, token, bypass_server_throttling_supported: null, bundle_id: null };
const obj = TrackedHTTPUtilsDefault;
let isAndroidResult = tmp2(1115).isAndroid();
2026-07-20 16:05:17 +00:00
if (isAndroidResult) {
isAndroidResult = !map1;
2026-07-20 16:05:17 +00:00
}
obj2.bypass_server_throttling_supported = isAndroidResult;
obj2.bundle_id = bundle_id;
request.body = obj2;
const obj3 = { event: tmp2(1250).NetworkActionNames.USER_REGISTER_DEVICE_TOKEN };
request.trackedActionData = obj3;
syncDeviceResult = obj.post(request);
const tmp2Result = tmp2(1115);
2026-07-20 16:05:17 +00:00
}
return syncDeviceResult;
},
syncDevice(token, flag) {
2026-08-24 06:08:38 +00:00
closure_0 = token;
2026-07-20 16:05:17 +00:00
if (flag === undefined) {
flag = false;
}
return (async (arg0, value) => {
const id2 = id.getId();
validUsers = validUsers.getValidUsers();
2026-08-04 21:03:28 +00:00
const sorted = validUsers.sort((id, id2) => {
let num = -1;
if (id.id !== closure_1_0) {
2026-08-04 21:03:28 +00:00
let num2 = 0;
if (id2.id === tmp) {
num2 = 1;
}
num = num2;
}
return num;
});
await Promise.all(sorted.map(closure_1_15));
2026-08-04 21:03:28 +00:00
if (1 === tmp5) {
2026-07-29 08:29:29 +00:00
if (arg0 === 1) {
2026-08-24 06:08:38 +00:00
dependencyMap = 3;
throw value;
2026-07-29 08:29:29 +00:00
} else if (arg0 === 2) {
2026-08-04 21:03:28 +00:00
dependencyMap = 3;
return { value, done: true };
2026-07-29 08:29:29 +00:00
} else {
closure_128_1 = value;
if (closure_128_1.length >= 1) {
if (null != closure_128_1[0]) {
const HTTP = tmp2(1272).HTTP;
const request = { url: constants.DEVICES_SYNC, body: null, rejectWithError: false };
if (closure_129_1) {
2026-08-24 06:08:38 +00:00
let tmp9 = closure_1_11;
2026-07-29 08:29:29 +00:00
} else {
2026-08-24 06:08:38 +00:00
tmp9 = closure_1_12();
2026-07-29 08:29:29 +00:00
}
const obj7 = { provider: tmp9, token: closure_129_0, push_sync_tokens: closure_128_1.filter(tmp2(1369).isNotNullish), bypass_server_throttling_supported: null, bundle_id: null };
let isAndroidResult = tmp2(1115).isAndroid();
2026-08-04 21:03:28 +00:00
if (isAndroidResult) {
2026-08-24 06:08:38 +00:00
isAndroidResult = !closure_1_13;
2026-07-29 08:29:29 +00:00
}
obj7.bypass_server_throttling_supported = isAndroidResult;
obj7.bundle_id = bundle_id;
request.body = obj7;
const v2 = 2;
2026-08-04 21:03:28 +00:00
dependencyMap = 1;
return { value: HTTP.put(request), done: false };
2026-07-29 08:29:29 +00:00
}
}
2026-08-04 21:03:28 +00:00
dependencyMap = 3;
}
} else if (arg0 === 1) {
dependencyMap = 3;
throw value;
2026-08-04 21:03:28 +00:00
} else if (arg0 !== 2) {
closure_128_2 = value;
if (closure_128_2.body.invalid_push_sync_tokens.length > 0) {
const result = v2(12447).invalidatePushSyncTokens(closure_128_2.body.invalid_push_sync_tokens);
v2(12447);
2026-07-29 08:29:29 +00:00
}
}
return value;
2026-07-29 08:29:29 +00:00
})();
2026-07-20 16:05:17 +00:00
},
unregisterDevice(token) {
2026-08-24 06:08:38 +00:00
logger.log("Unregistering push notification token: " + token);
const request = { url: constants.DEVICES, body: null, trackedActionData: null, rejectWithError: false };
const obj = TrackedHTTPUtilsDefault;
request.body = { provider: closure_1_12(), token };
const obj2 = { provider: closure_1_12(), token };
request.trackedActionData = { event: discord_common_AnalyticsUtils.NetworkActionNames.USER_UNREGISTER_DEVICE_TOKEN };
return obj.delete(request);
2026-07-20 16:05:17 +00:00
}
};
export const setPushPermissionState = function setPushPermissionState(PROMPT_SEEN) {
const permissionState = PROMPT_SEEN;
DispatcherDefault.wait(() => {
DispatcherDefault.dispatch({ type: "PUSH_NOTIFICATION_PERMISSION_SET_STATE", permissionState });
2026-07-20 16:05:17 +00:00
});
};
export const setPushPermissionReactivationSeen = function setPushPermissionReactivationSeen(promptType) {
DispatcherDefault.dispatch({ type: "PUSH_NOTIFICATION_PERMISSION_REACTIVATION_SEEN", promptType });
2026-07-20 16:05:17 +00:00
};
export const setPushNotificationPermissionEligibleForPrompt = function setPushNotificationPermissionEligibleForPrompt(CHANNEL_BANNER) {
DispatcherDefault.dispatch({ type: "PUSH_NOTIFICATION_PERMISSION_SET_ELIGIBLE", promptType: CHANNEL_BANNER });
2026-07-20 16:05:17 +00:00
};
export const updateNotificationAuthorizationStatus = function updateNotificationAuthorizationStatus(authorizationStatus) {
DispatcherDefault.dispatch({ type: "PUSH_NOTIFICATION_AUTHORIZATION_STATUS_UPDATE", authorizationStatus });
2026-07-20 16:05:17 +00:00
};