Files
discord-decomp/sources/modules/spotify/SpotifyActionCreators.tsx
T
2026-07-27 16:20:00 +03:00

328 lines
16 KiB
TypeScript

/* Metro module 6869; source: modules/spotify/SpotifyActionCreators.tsx; dependencies: [6870, 6868, 661, 4041, 507, 694, 672, 477, 6871, 2] */
function _fun54365(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#54365, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:6, offset: 0x01363f14, size: 371 bytes, params: 8, frame: 22
var object2;
const env0_0 = require;
const closure = apiRequest;
const closure2 = getAccessToken;
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
const spotifyProtocolStore = importDefault(6870) /* metro dependency 6870: SpotifyProtocolStore */;
let value = require(6868) /* metro dependency 6868: SpotifyConstants */;
const env0_4 = value.SPOTIFY_APP_PROTOCOL;
const env0_5 = value.SpotifyEndpoints;
value = require(661) /* metro dependency 661: Constants */;
const env0_6 = value.AbortCodes;
const env0_7 = value.Endpoints;
const env0_8 = value.PlatformTypes;
object2 = {};
const bind = closure.bind;
const HTTP = (require(507) /* metro dependency 507: HTTPUtils */).HTTP;
const get = HTTP.get;
object2.get = Reflect.apply(bind, closure, [null, get]);
object2.put = closure.bind(null, HTTP.put);
(require(2) /* metro dependency 2 */).fileFinishedImporting('modules/spotify/SpotifyActionCreators.tsx');
exports.SpotifyAPI = object2;
exports.getAccessToken = closure2;
exports.subscribePlayerStateNotifications = subscribePlayerStateNotifications;
exports.getProfile = getProfile;
exports.getDevices = getDevices;
exports.play = play_54385;
exports.pause = pause_54388;
exports.fetchIsSpotifyProtocolRegistered = fetchIsSpotifyProtocolRegistered;
exports.setActiveDevice = setActiveDevice_54392;
}
function apiRequest(a0, a1, a2, a3) { // fn#54366, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:219, offset: 0x01364087, size: 136 bytes, params: 5, frame: 17
let value = a4;
const env0_0 = a0;
const env0_1 = a1;
const env0_2 = a3;
const env0_3 = value !== undefined ? value : 1;
const object2 = {};
copyDataProperties(object2, a3, undefined);
object2['headers'] = {authorization: 'Bearer ' + a2};
value = a0(object2);
value = value.then(function(a0) {
var r0;
var value = a0;
if (value.status !== 202) {
r0 = value;
} else {
value = global.Promise.reject(value);
r0 = value;
}
return r0;
});
return value.catch(_fun54368);
}
function getAccessToken(a0) { // fn#54374, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:780, offset: 0x0136429f, size: 124 bytes, params: 2, frame: 17
const env0_0 = a0;
const HTTP = (require(507) /* metro dependency 507: HTTPUtils */).HTTP;
const get = HTTP.get;
const CONNECTION_ACCESS_TOKEN = Endpoints.CONNECTION_ACCESS_TOKEN;
const SPOTIFY = PlatformTypes.SPOTIFY;
let value = Reflect.apply(get, HTTP, [{'url': null, 'oldFormErrors': true, 'rejectWithError': false,
url: Reflect.apply(CONNECTION_ACCESS_TOKEN, Endpoints, [SPOTIFY, a0])}]);
value = value.catch(_fun54375);
return value.then(_fun54377);
}
function subscribePlayerStateNotifications(a0, a1, a2) { // fn#54378, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:1544, offset: 0x01364494, size: 105 bytes, params: 4, frame: 18
const value = a3;
const env0_0 = a0;
const env0_1 = a1;
const env0_2 = a2;
const env0_3 = value !== undefined ? value : 2;
const binding = env0_9;
const put = binding.put;
const NOTIFICATIONS_PLAYER = SpotifyEndpoints.NOTIFICATIONS_PLAYER;
return Reflect.apply(put, binding, [a0, a1, {url: NOTIFICATIONS_PLAYER,
query: {connection_id: a2}}]).catch(_fun54379);
}
function getProfile(a0, a1) { // fn#54381, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:1803, offset: 0x01364588, size: 64 bytes, params: 3, frame: 16
const env0_0 = a0;
const binding = env0_9;
const get = binding.get;
const PROFILE = SpotifyEndpoints.PROFILE;
return Reflect.apply(get, binding, [a0, a1, {url: PROFILE}]).then(_fun54382);
}
function getDevices(a0, a1) { // fn#54383, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:1990, offset: 0x01364620, size: 64 bytes, params: 3, frame: 16
const env0_0 = a0;
const binding = env0_9;
const get = binding.get;
const PLAYER_DEVICES = SpotifyEndpoints.PLAYER_DEVICES;
return Reflect.apply(get, binding, [a0, a1, {url: PLAYER_DEVICES}]).then(_fun54384);
}
function play_54385(a0, a1, a2, a3) { // fn#54385, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:2169, offset: 0x013646b8, size: 273 bytes, params: 5, frame: 25
let value = a4;
const env0_0 = a0;
const env0_1 = a1;
const env0_2 = a2;
const value2 = undefined;
const r2 = value !== value2 ? value : {};
const value3 = SpotifyEndpoints.PLAYER_OPEN(a3, a2, false);
const deviceId = r2.deviceId;
const position = r2.position;
const contextUri = r2.contextUri;
const env0_5 = r2.repeat;
const binding = env0_9;
const put = binding.put;
const PLAYER_PLAY = SpotifyEndpoints.PLAYER_PLAY;
value = Reflect.apply(put, binding, [a0, a1, {url: PLAYER_PLAY, query: {device_id: deviceId},
body: {context_uri: contextUri ?? value2, uris: contextUri == null ? [value3] : value2,
offset: contextUri != null ? {uri: value3} : value2, position_ms: position ?? 0}}]);
value = value.then(_fun54386);
return value.then(_fun54387);
}
function pause_54388(a0, a1) { // fn#54388, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:2644, offset: 0x0136487e, size: 61 bytes, params: 3, frame: 15
const binding = env0_9;
const put = binding.put;
const PLAYER_PAUSE = SpotifyEndpoints.PLAYER_PAUSE;
return Reflect.apply(put, binding, [a0, a1, {url: PLAYER_PAUSE}]).then(_fun54389);
}
function fetchIsSpotifyProtocolRegistered() { // fn#54390, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:2802, offset: 0x013648ef, size: 111 bytes, params: 1, frame: 13
var moduleValue;
if (!SpotifyProtocolStore.isProtocolRegistered()) {
moduleValue = require(477) /* metro dependency 477: PlatformUtils */;
if (moduleValue.isDesktop()) {
(importDefault(6871) /* metro dependency 6871: GameUtilsNative */).isProtocolRegistered(SPOTIFY_APP_PROTOCOL).then(_fun54391);
}
}
}
function setActiveDevice_54392(a0, a1) { // fn#54392, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:3031, offset: 0x01364997, size: 65 bytes, params: 3, frame: 13
(importDefault(694) /* metro dependency 694: Dispatcher */).dispatch({type: 'SPOTIFY_SET_ACTIVE_DEVICE',
accountId: a0, deviceId: a1});
}
function _fun54368(a0) { // fn#54368, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:364, offset: 0x01364136, size: 208 bytes, params: 2, frame: 14
var environment;
var r4;
var r0;
var value;
if (a0.status === 401) {
if (env0_3 > 0) {
if (a0.status === 202) {
value = environment.__proto__;
value = require(4041) /* metro dependency 4041: Timers */;
value = value.timeoutPromise(5000);
r4 = value;
} else {
r4 = global.Promise.resolve();
}
value = r4.then(function() {
return getAccessToken(require);
});
value = value.then(_fun54370);
value = value.then(_fun54371);
r0 = value;
} else {
r0 = global.Promise.reject(a0);
}
} else if (importAll.onlyRetryOnAuthorizationErrors !== true && a0.status === 202) {
if (env0_3 > 0) {
if (a0.status === 202) {
value = environment.__proto__;
value = require(4041) /* metro dependency 4041: Timers */;
value = value.timeoutPromise(5000);
r4 = value;
} else {
r4 = global.Promise.resolve();
}
value = r4.then(_fun54369);
value = value.then(_fun54370);
value = value.then(_fun54371);
r0 = value;
} else {
r0 = global.Promise.reject(a0);
}
} else {
r0 = global.Promise.reject(a0);
}
return r0;
}
function _fun54375(a0) { // fn#54375, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:920, offset: 0x0136431b, size: 274 bytes, params: 2, frame: 15
const code = a0.body?.code;
const CONNECTION_REVOKED = AbortCodes.CONNECTION_REVOKED;
if (code === CONNECTION_REVOKED) {
(importDefault(694) /* metro dependency 694: Dispatcher */).dispatch({type: 'SPOTIFY_ACCOUNT_ACCESS_TOKEN_REVOKE',
accountId: env0_0});
return global.Promise.reject(a0);
}
if (a0.status !== 429) {
return global.Promise.reject(a0);
}
const property = a0.headers['retry-after'];
const Millis = (importDefault(672) /* metro dependency 672: Durations */).Millis;
const SECOND = Millis.SECOND;
const value3 = property * SECOND;
const r5 = global.isNaN(value3) || value3 === 0 ? 5000 : value3;
value = require(4041) /* metro dependency 4041: Timers */;
value = value.timeoutPromise(r5);
return value.then(_fun54376);
}
function _fun54377(a0) { // fn#54377, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:1262, offset: 0x01364444, size: 80 bytes, params: 2, frame: 14
const access_token = a0.body.access_token;
const value = environment.__proto__;
(importDefault(694) /* metro dependency 694: Dispatcher */).dispatch({type: 'SPOTIFY_ACCOUNT_ACCESS_TOKEN',
accountId: env0_0, accessToken: access_token});
return a0;
}
function _fun54379(a0) { // fn#54379, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:1676, offset: 0x013644fd, size: 98 bytes, params: 2, frame: 12
var environment;
var r0;
var value;
if (env0_3 <= 0) {
r0 = global.Promise.reject(a0);
} else {
value = environment.__proto__;
value = require(4041) /* metro dependency 4041: Timers */;
value = value.timeoutPromise(5000);
value = value.then(_fun54380);
r0 = value;
}
return r0;
}
function _fun54382(a0) { // fn#54382, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:1868, offset: 0x013645c8, size: 88 bytes, params: 2, frame: 14
const value = environment.__proto__;
(importDefault(694) /* metro dependency 694: Dispatcher */).dispatch({type: 'SPOTIFY_PROFILE_UPDATE',
accountId: env0_0, isPremium: a0.body.product === 'premium'});
return a0;
}
function _fun54384(a0) { // fn#54384, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:2062, offset: 0x01364660, size: 88 bytes, params: 2, frame: 13
var value;
if (a0.body) {
value = environment.__proto__;
value = importDefault(694) /* metro dependency 694: Dispatcher */;
value.dispatch({type: 'SPOTIFY_SET_DEVICES', accountId: env0_0, devices: a0.body.devices});
}
return a0;
}
function _fun54386(a0) { // fn#54386, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:2455, offset: 0x013647c9, size: 97 bytes, params: 2, frame: 19
var r0;
var binding;
var put;
var binding2;
let value = a0;
let repeatBinding = repeat;
if (repeatBinding == null) {
r0 = value;
} else {
value = environment.__proto__;
binding = env1_9;
put = binding.put;
binding2 = env0_0;
repeatBinding = repeat;
value = 'off';
value = Reflect.apply(put, binding, [binding2, require, {url: SpotifyEndpoints.PLAYER_REPEAT,
query: {device_id: deviceId, state: repeatBinding ? 'context' : value}}]);
r0 = value;
}
return r0;
}
function _fun54387(a0) { // fn#54387, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:2553, offset: 0x0136482a, size: 84 bytes, params: 2, frame: 14
const value = environment.__proto__;
(importDefault(694) /* metro dependency 694: Dispatcher */).dispatch({type: 'SPOTIFY_PLAYER_PLAY',
id: importDefault, position: position ?? 0});
return a0;
}
function _fun54389(a0) { // fn#54389, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:2709, offset: 0x013648bb, size: 52 bytes, params: 2, frame: 12
const value = environment.__proto__;
(importDefault(694) /* metro dependency 694: Dispatcher */).dispatch({type: 'SPOTIFY_PLAYER_PAUSE'});
return a0;
}
function _fun54391(a0) { // fn#54391, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:2931, offset: 0x0136495e, size: 57 bytes, params: 2, frame: 13
const value = environment.__proto__;
(importDefault(694) /* metro dependency 694: Dispatcher */).dispatch({type: 'SPOTIFY_SET_PROTOCOL_REGISTERED',
isRegistered: a0});
}
function _fun54369() { // fn#54369, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:528, offset: 0x01364206, size: 23 bytes, params: 1, frame: 11
return getAccessToken(require);
}
function _fun54370({body}) { // fn#54370, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:558, offset: 0x0136421d, size: 55 bytes, params: 2, frame: 19
return apiRequest(env1_0, require, body.access_token, importAll, env1_3 - 1);
}
function _fun54371(a0) { // fn#54371, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:617, offset: 0x01364254, size: 44 bytes, params: 2, frame: 11
let env0_0 = a0;
const Promise = global.Promise;
const value = Object.create(Promise.prototype, {constructor: {value: Promise}});
const promise = new Promise(function(a0) {
var env0_0 = a0;
return global.setImmediate(_fun54373);
});
return promise instanceof Object ? promise : value;
}
function _fun54376() { // fn#54376, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:1204, offset: 0x0136442d, size: 23 bytes, params: 1, frame: 11
return getAccessToken(env1_0);
}
function _fun54380() { // fn#54380, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:1736, offset: 0x0136455f, size: 41 bytes, params: 1, frame: 17
return subscribePlayerStateNotifications(env1_0, require, importDefault, env1_3 - 1);
}
function _fun54372(a0) { // fn#54372, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:7047:633, offset: 0x01364280, size: 31 bytes, params: 2, frame: 11
const env0_0 = a0;
return global.setImmediate(_fun54373);
}