Files
discord-decomp/sources/modules/notifications/native/NotificationTokenManager.tsx
T
2026-07-27 16:20:00 +03:00

393 lines
21 KiB
TypeScript

/* Metro module 12998; source: modules/notifications/native/NotificationTokenManager.tsx; dependencies: [6, 7, 15, 17, 18, 27, 1220, 11876, 1226, 12999, 661, 1244, 11875, 694, 10741, 13002, 13003, 1216, 2518, 477, 13004, 683, 4561, 2] */
function _fun99146(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#99146, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:6, offset: 0x021bc33e, size: 344 bytes, params: 8, frame: 19
const env0_0 = require;
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
const env0_3 = importDefault(6) /* metro dependency 6 */;
const env0_4 = importDefault(7) /* metro dependency 7 */;
const env0_5 = importDefault(15) /* metro dependency 15 */;
const env0_6 = importDefault(17) /* metro dependency 17 */;
const env0_7 = importDefault(18) /* metro dependency 18 */;
const env0_8 = (require(27) /* metro dependency 27 */).NativeModules;
const apexExperimentStore = importDefault(1220) /* metro dependency 1220: ApexExperimentStore */;
const multiAccountStore = importDefault(11876) /* metro dependency 11876: MultiAccountStore */;
const authenticationStore = importDefault(1226) /* metro dependency 1226: AuthenticationStore */;
const env0_12 = (require(12999) /* metro dependency 12999: NotificationSettingsConstants */).NOTIF_SETTINGS;
const env0_13 = (require(661) /* metro dependency 661: Constants */).AnalyticEvents;
let value = importDefault(4561) /* metro dependency 4561: LifecycleManager */;
value = _fun99150(value);
value = new value();
(require(2) /* metro dependency 2 */).fileFinishedImporting('modules/notifications/native/NotificationTokenManager.tsx');
exports.default = value;
}
function _isNativeReflectConstruct_99147() { // fn#99147, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:253, offset: 0x021bc496, size: 98 bytes, params: 1, frame: 18
var Boolean;
var prototype;
var valueOf;
var call;
var Reflect;
var construct;
var closure;
var value;
var error;
try {
Boolean = global.Boolean;
prototype = Boolean.prototype;
valueOf = prototype.valueOf;
call = valueOf.call;
Reflect = global.Reflect;
construct = Reflect.construct;
Boolean = global.Boolean;
closure = function() {
};
value = Reflect.apply(construct, Reflect, [Boolean, [], closure]);
value = Reflect.apply(call, valueOf, [value]);
var result = !value;
} catch (error) {
}
return (_isNativeReflectConstruct_99147_isNativeReflectConstruct = function() {
return !!result;
})();
}
function _fun99150(a0) { // fn#99150, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:456, offset: 0x021bc4f8, size: 253 bytes, params: 2, frame: 16
const closure = NotificationTokenManager;
env0_7(closure, a0);
return env0_4(closure, [{key: '_initialize', value: value_99161}, {key: '_terminate', value: value_99163},
{key: 'registerListener', value: value_99164}, {key: 'registerNotificationCategories', value: value_99165},
{key: 'registerLegacyNotificationCategories', value: value_99166}, {key: 'trackDisabledAndroidNotifChannels',
value: value_99167}, {key: 'getToken', value: function() {
return this.token;
}}, {key: 'canSync', get: get_99172}]);
}
function NotificationTokenManager(a0) { // fn#99151, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:468, offset: 0x021bc5f5, size: 270 bytes, params: 2, frame: 20
var r0;
var Reflect;
let value = copyRestArgs(0, undefined);
let binding = env1_3;
binding(this, NotificationTokenManager);
const items2 = [];
arraySpread(items2, value, 0, items2);
value = env1_6(NotificationTokenManager);
binding = env1_5;
if (_isNativeReflectConstruct_99147()) {
Reflect = global.Reflect;
value = Reflect.construct(value, items2, env1_6(this).constructor);
r0 = value;
} else {
value = value.apply(this, items2);
r0 = value;
}
value = binding(this, r0);
value._experimentUnsubscribe = null;
value.token = null;
value.hasRegisterEventListener = false;
value.hasTrackedDisabledAndroidNotifChannels = false;
value.postConnectionOpenTimeoutID = null;
value._handleExperimentsUpdated = _handleExperimentsUpdated;
value.handleToken = handleToken;
value.registerToken = registerToken;
value.handleSyncNoMultiAccountOnLoginSuccess = handleSyncNoMultiAccountOnLoginSuccess;
value.handleSyncNoMultiAccountOnRegisterSuccess = handleSyncNoMultiAccountOnRegisterSuccess;
value.handleSyncNoMultiAccountOnPostConnectionOpen = handleSyncNoMultiAccountOnPostConnectionOpen;
value.handleSyncNoMultiAccount = handleSyncNoMultiAccount;
value.handleSyncWithMultiAccount = handleSyncWithMultiAccount;
return value;
}
function value_99161() { // fn#99161, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:2063, offset: 0x021bc943, size: 241 bytes, params: 1, frame: 18
var environment;
if (this.token != null) {
this.handleToken(this.token);
}
let value = environment.__proto__;
ApexExperimentStore.addChangeListener(this._handleExperimentsUpdated);
this._experimentUnsubscribe = _experimentUnsubscribe;
value = importDefault(694) /* metro dependency 694: Dispatcher */;
value.subscribe('LOGIN_SUCCESS', this.handleSyncNoMultiAccountOnLoginSuccess);
value = importDefault(694) /* metro dependency 694: Dispatcher */;
value.subscribe('REGISTER_SUCCESS', this.handleSyncNoMultiAccountOnRegisterSuccess);
value = importDefault(694) /* metro dependency 694: Dispatcher */;
value.subscribe('POST_CONNECTION_OPEN', this.handleSyncNoMultiAccountOnPostConnectionOpen);
value = importDefault(694) /* metro dependency 694: Dispatcher */;
value.subscribe('POST_CONNECTION_OPEN', this.handleSyncWithMultiAccount);
value = importDefault(694) /* metro dependency 694: Dispatcher */;
value.subscribe('MULTI_ACCOUNT_REMOVE_ACCOUNT', this.handleSyncWithMultiAccount);
}
function value_99163() { // fn#99163, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:2705, offset: 0x021bca57, size: 200 bytes, params: 1, frame: 18
let value = environment.__proto__;
value = importDefault(694) /* metro dependency 694: Dispatcher */;
value.unsubscribe('LOGIN_SUCCESS', this.handleSyncNoMultiAccountOnLoginSuccess);
value = importDefault(694) /* metro dependency 694: Dispatcher */;
value.unsubscribe('REGISTER_SUCCESS', this.handleSyncNoMultiAccountOnRegisterSuccess);
value = importDefault(694) /* metro dependency 694: Dispatcher */;
value.unsubscribe('POST_CONNECTION_OPEN', this.handleSyncNoMultiAccountOnPostConnectionOpen);
value = importDefault(694) /* metro dependency 694: Dispatcher */;
value.unsubscribe('POST_CONNECTION_OPEN', this.handleSyncWithMultiAccount);
value = importDefault(694) /* metro dependency 694: Dispatcher */;
value.unsubscribe('MULTI_ACCOUNT_REMOVE_ACCOUNT', this.handleSyncWithMultiAccount);
if (this._experimentUnsubscribe != null) {
this._experimentUnsubscribe();
this._experimentUnsubscribe = null;
}
}
function value_99164() { // fn#99164, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:3275, offset: 0x021bcb1f, size: 100 bytes, params: 1, frame: 12
if (this.hasRegisterEventListener) {
throw new global.Error('Device token listener already registered.');
}
this.hasRegisterEventListener = true;
let value = environment.__proto__;
value = importDefault(10741) /* metro dependency 10741: PushNotification */;
value.addRegisterEventListener(this.handleToken);
}
function value_99165() { // fn#99165, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:3511, offset: 0x021bcb83, size: 275 bytes, params: 1, frame: 17
var r4;
var enabled;
var property;
var defaultImport;
var value4;
var error;
var defaultImport2;
var clearDeclarative;
var defaultImport3;
var defaultImport4;
let value = environment.__proto__;
const config = require(dependencyMap[15]).declarativeNotifSettingsExperiment.getConfig({location: 'registerNotificationCategories'});
const value3 = false;
try {
enabled = config.enabled;
if (enabled) {
property = dependencyMap[16];
defaultImport = importDefault(property);
value4 = defaultImport.registerDeclarativeNotificationCategories();
r4 = value4;
} else {
r4 = value3;
}
} catch (error) {
defaultImport2 = importDefault(dependencyMap[17]);
defaultImport2.captureException(error);
r4 = value3;
}
if (!r4) {
try {
clearDeclarative = config.clearDeclarative;
if (clearDeclarative) {
property = dependencyMap[17];
defaultImport3 = importDefault(property);
defaultImport3.addBreadcrumb({message: 'Clearing declarative notification categories'});
property = dependencyMap[16];
defaultImport4 = importDefault(property);
defaultImport4.clear();
}
} catch (error) {
value = importDefault(dependencyMap[17]);
value.captureException(error);
}
this.registerLegacyNotificationCategories();
}
this.trackDisabledAndroidNotifChannels();
}
function value_99166() { // fn#99166, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:4048, offset: 0x021bcc96, size: 1563 bytes, params: 1, frame: 21
var object3;
const intl = (require(1244) /* metro dependency 1244: indexNative */).intl;
const t = (require(1244) /* metro dependency 1244: indexNative */).t;
var object4;
let DCDNotificationCategoryUtils = NativeModules.DCDNotificationCategoryUtils;
const registerNotificationCategories = DCDNotificationCategoryUtils.registerNotificationCategories;
DCDNotificationCategoryUtils = NativeModules.DCDNotificationCategoryUtils;
const registerNotificationCategoriesAndGroups = DCDNotificationCategoryUtils.registerNotificationCategoriesAndGroups;
if (registerNotificationCategoriesAndGroups != null) {
object3 = {};
object3.calls = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */)['IUH/Oe']);
object3.mediaConnections = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */).VeBD1N);
object3.messages = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */)['4qWUAO']);
object3.directMessages = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */).NGdNZb);
object3.friendRequests = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */).NxgGZA);
object3.polls = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */).MOjygY);
object3.social = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */)['UzRF+8']);
object3.stageLive = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */)['4n388K']);
object3.guildEventLive = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */)['40TIqW']);
object3.guildHighlights = intl.string(t.p5jg9S);
object3.forumThreadCreated = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */).HibKoy);
object3.systemMessages = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */).zJlwvV);
object3.other = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */).kIrLfg);
object3.default = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */)['T+79Eo']);
object3.reactions = intl.string(t.gHp0C4);
object4 = {};
object4.realtime = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */).S5cB9e);
object4.social = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */)['UzRF+8']);
object4.server = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */).zRKbpz);
object4.other = intl.string((importDefault(2518) /* metro dependency 2518: NotificationSettingsMessages */).q5M7HV);
registerNotificationCategoriesAndGroups(object3, object4);
} else if (registerNotificationCategories != null) {
object3 = {};
object3.calls = intl.string(t.JJogjm);
object3.mediaConnections = intl.string(t.K3lovD);
object3.messages = intl.string(t.OIgYlQ);
object3.directMessages = intl.string(t.YUU0RF);
object3.social = intl.string(t.TdEu5X);
object3.gameDetection = intl.string(t['A/4saf']);
object3.stageLive = intl.string(t.qGRagm);
object3.guildEventLive = intl.string(t.MfGr0a);
object3.guildHighlights = intl.string(t.p5jg9S);
object3.forumThreadCreated = intl.string(t.dl57ho);
object3.other = intl.string(t.BcZTKu);
object3.otherHighPriority = intl.string(t.bcv3rp);
registerNotificationCategories(object3);
}
}
function value_99167() { // fn#99167, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:5863, offset: 0x021bd2b1, size: 272 bytes, params: 1, frame: 17
var environment;
var getAndroidNotifChannelStates;
var value;
var value2;
var moduleValue;
var androidNotifChannelStates;
var Set;
var value4;
var set;
var value7;
var defaultImport2;
var track;
var ANDROID_NOTIFICATION_CHANNELS_SYNCED;
var object2;
if (!this.hasTrackedDisabledAndroidNotifChannels) {
this.hasTrackedDisabledAndroidNotifChannels = true;
value = environment.__proto__;
value2 = undefined;
moduleValue = require(477) /* metro dependency 477: PlatformUtils */;
if (moduleValue.isAndroid()) {
getAndroidNotifChannelStates = (importDefault(13004) /* metro dependency 13004: NativeNotifSettingsModule */) == null ? value2 : (importDefault(13004) /* metro dependency 13004: NativeNotifSettingsModule */).getAndroidNotifChannelStates;
if (getAndroidNotifChannelStates != null) {
androidNotifChannelStates = getAndroidNotifChannelStates();
Set = global.Set;
value4 = NOTIF_SETTINGS.map(function(a0) {
return a0.string_id;
});
set = new Set();
value7 = androidNotifChannelStates.filter(_fun99169);
defaultImport2 = importDefault(683) /* metro dependency 683: AnalyticsUtils */;
track = defaultImport2.track;
ANDROID_NOTIFICATION_CHANNELS_SYNCED = AnalyticEvents.ANDROID_NOTIFICATION_CHANNELS_SYNCED;
object2 = {};
object2.disabled_channels = value7.map(_fun99170);
Reflect.apply(track, defaultImport2, [ANDROID_NOTIFICATION_CHANNELS_SYNCED, object2]);
}
}
}
}
function get_99172() { // fn#99172, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:6350, offset: 0x021bd401, size: 50 bytes, params: 1, frame: 10
var r0;
var value;
const isInitialized = this.isInitialized;
if (isInitialized) {
value = environment.__proto__;
value = AuthenticationStore.isAuthenticated();
r0 = value;
} else {
r0 = isInitialized;
}
if (r0) {
value = environment.__proto__;
value = !MultiAccountStore.isSwitchingAccount;
r0 = value;
}
return r0;
}
function _handleExperimentsUpdated() { // fn#99152, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:906, owner: NotificationTokenManager._handleExperimentsUpdated, offset: 0x021bc703, size: 19 bytes, params: 1, frame: 9
return env0_0.registerNotificationCategories();
}
function handleToken(a0) { // fn#99153, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:959, owner: NotificationTokenManager.handleToken, offset: 0x021bc716, size: 43 bytes, params: 2, frame: 10
const binding = env0_0;
binding.token = a0;
if (binding.canSync) {
env0_0.registerToken();
}
}
function registerToken() { // fn#99154, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:1019, owner: NotificationTokenManager.registerToken, offset: 0x021bc741, size: 283 bytes, params: 1, frame: 24
var environment;
var value2;
var DCDNotificationCategoryUtils;
var registerNotificationReplyCategories;
const intl = (require(1244) /* metro dependency 1244: indexNative */).intl;
var string;
const t = (require(1244) /* metro dependency 1244: indexNative */).t;
var TBA5Xg;
var value3;
var value4;
var defaultImport;
if (env0_0.token != null) {
value2 = environment.__proto__.__proto__;
DCDNotificationCategoryUtils = NativeModules.DCDNotificationCategoryUtils;
registerNotificationReplyCategories = DCDNotificationCategoryUtils.registerNotificationReplyCategories;
string = intl.string;
TBA5Xg = t.TBA5Xg;
value3 = Reflect.apply(string, intl, [TBA5Xg]);
value4 = intl.string(t.TXNS7S);
string = intl.string;
TBA5Xg = t.TBA5Xg;
Reflect.apply(registerNotificationReplyCategories, DCDNotificationCategoryUtils, [value3, value4,
Reflect.apply(string, intl, [TBA5Xg]), function() {
}]);
if (NativeModules.PushNotificationAndroid) {
NativeModules.PushNotificationAndroid.onRegisterNotificationToken();
}
defaultImport = importDefault(11875) /* metro dependency 11875: PushNotificationActionCreators */;
defaultImport.registerDevice(env0_0.token);
}
}
function handleSyncNoMultiAccountOnLoginSuccess() { // fn#99156, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:1396, owner: NotificationTokenManager.handleSyncNoMultiAccountOnLoginSuccess, offset: 0x021bc85c, size: 21 bytes, params: 1, frame: 9
env0_0.handleSyncNoMultiAccount();
}
function handleSyncNoMultiAccountOnRegisterSuccess() { // fn#99157, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:1475, owner: NotificationTokenManager.handleSyncNoMultiAccountOnRegisterSuccess, offset: 0x021bc871, size: 43 bytes, params: 1, frame: 14
const binding = env0_0;
binding.postConnectionOpenTimeoutID = global.setTimeout(binding.handleSyncNoMultiAccountOnPostConnectionOpen, 5000);
}
function handleSyncNoMultiAccountOnPostConnectionOpen() { // fn#99158, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:1621, owner: NotificationTokenManager.handleSyncNoMultiAccountOnPostConnectionOpen, offset: 0x021bc89c, size: 64 bytes, params: 1, frame: 13
var clearTimeout;
var binding;
if (env0_0.postConnectionOpenTimeoutID != null) {
clearTimeout = global.clearTimeout;
binding = env0_0;
clearTimeout(binding.postConnectionOpenTimeoutID);
binding.postConnectionOpenTimeoutID = null;
binding.handleSyncNoMultiAccount();
}
}
function handleSyncNoMultiAccount() { // fn#99159, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:1801, owner: NotificationTokenManager.handleSyncNoMultiAccount, offset: 0x021bc8dc, size: 53 bytes, params: 1, frame: 10
if (env0_0.canSync && !MultiAccountStore.canUseMultiAccountNotifications) {
env0_0.registerToken();
}
}
function handleSyncWithMultiAccount() { // fn#99160, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:1901, owner: NotificationTokenManager.handleSyncWithMultiAccount, offset: 0x021bc911, size: 50 bytes, params: 1, frame: 10
if (env0_0.canSync && MultiAccountStore.canUseMultiAccountNotifications) {
env0_0.registerToken();
}
}
function value_99161_experimentUnsubscribe() { // fn#99162, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:2201, owner: value_99161._experimentUnsubscribe, offset: 0x021bca34, size: 35 bytes, params: 1, frame: 11
ApexExperimentStore.removeChangeListener(env0_0._handleExperimentsUpdated);
}
function _fun99169(a0) { // fn#99169, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:13188:6129, offset: 0x021bd3cc, size: 42 bytes, params: 2, frame: 12
return a0.importance === 0 && env0_0.has(a0.channelId);
}