Files
discord-decomp/stores/NowPlayingStore.tsx
T
2026-11-01 12:12:55 +02:00

234 lines
6.1 KiB
TypeScript

// Metro module 12800 (f12801).
import UserAffinitiesV2Store from "../modules/user_affinities/UserAffinitiesV2Store";
import PresenceStore from "./PresenceStore";
import UserStore from "./UserStore";
import { ActivityTypes } from "../Constants";
import getApplicationIdForActivity from "../modules/now_playing/getApplicationIdForActivity";
import Module589 from "../_bundle/Module589";
import Dispatcher from "../Dispatcher";
function $mk90427($env) {
return (a0) => {
const r3 = $env;
r3[0] = (0, $env.$parent[9])(a0) !== false || r3[0];
};
}
let handleUserAffinitiesV2StoreUpdate, c8827_11;
let env8827 = {};
const _handlePresenceUpdate = function _handlePresenceUpdate({ user, activities }) {
let c20223_1;
c20223_1 = void 0;
if (user == null) {
return false;
}
const r13 = activities.filter((activity) => activity.type !== ActivityTypes.CUSTOM_STATUS);
if (r13.length === 0) {
const id = user.id;
const r22 = env8827[8][id];
const r3 = r22 == null;
let r23 = false;
if (!r3) {
const gameId = r22.gameId;
if (env8827[7][gameId] != null) {
const r27 = {
...env8827[7]
};
env8827[7] = r27;
delete r27[gameId][id];
if (Object.values(env8827[7][gameId]).length === 0) {
delete env8827[7][gameId];
}
}
const r40 = {
...env8827[8]
};
env8827[8] = r40;
delete r40[id];
r23 = true;
}
return r23;
}
c20223_1 = false;
r13.forEach((item) => {
let r70;
const applicationIdForActivity = getApplicationIdForActivity(item);
if (applicationIdForActivity == null) {
const id2 = user.id;
const r73 = env8827[8][id2];
const r5 = r73 == null;
let r2 = false;
if (!r5) {
const gameId2 = r73.gameId;
if (env8827[7][gameId2] != null) {
const r77 = {
...env8827[7]
};
env8827[7] = r77;
delete r77[gameId2][id2];
if (Object.values(env8827[7][gameId2]).length === 0) {
delete env8827[7][gameId2];
}
}
const r93 = {
...env8827[8]
};
env8827[8] = r93;
delete r93[id2];
r2 = true;
}
r70 = r2;
} else {
const r22 = env8827[8][user.id];
if (r22 != null && r22.gameId !== applicationIdForActivity) {
const id = user.id;
const r26 = env8827[8][id];
if (r26 != null) {
const gameId = r26.gameId;
if (env8827[7][gameId] != null) {
const r29 = {
...env8827[7]
};
env8827[7] = r29;
delete r29[gameId][id];
if (Object.values(env8827[7][gameId]).length === 0) {
delete env8827[7][gameId];
}
}
const r40 = {
...env8827[8]
};
env8827[8] = r40;
delete r40[id];
}
}
let startedPlaying = item.timestamps?.start;
if (startedPlaying == null) {
startedPlaying = Date.now();
}
const r52 = {
userId: user.id,
activity: item,
startedPlaying
};
const r53 = {
...env8827[7]
};
const r57 = {
...env8827[7][applicationIdForActivity]
};
r57[r52.userId] = r52;
r53[applicationIdForActivity] = r57;
env8827[7] = r53;
const r63 = {
...env8827[8]
};
r63[r52.userId] = {
gameId: applicationIdForActivity,
startedPlaying: r52.startedPlaying
};
env8827[8] = r63;
r70 = true;
}
if (r70) {
c20223_1 = true;
}
});
return c20223_1;
};
handleUserAffinitiesV2StoreUpdate = function handleUserAffinitiesV2StoreUpdate() {
const r8 = UserAffinitiesV2Store.shouldFetch() || env8827[6];
let r0 = false;
if (!r8) {
env8827[7] = {};
env8827[8] = {};
let c20224_0 = false;
PresenceStore.getUserIds().forEach((item) => {
const user2 = UserStore.getUser(item);
if (user2 != null) {
c20224_0 = _handlePresenceUpdate({
user: user2,
activities: PresenceStore.getActivities(item)
}) || c20224_0;
}
});
r0 = c20224_0;
}
env8827[6] = !UserAffinitiesV2Store.shouldFetch();
return r0;
};
env8827[6] = false;
env8827[7] = {};
env8827[8] = {};
class NowPlayingStore extends Module589.Store {
static displayName = "NowPlayingStore";
constructor() {
super(...arguments);
}
initialize() {
this.waitFor(PresenceStore, UserAffinitiesV2Store, UserStore);
this.syncWith([UserAffinitiesV2Store], handleUserAffinitiesV2StoreUpdate);
}
get games() {
return env8827[7];
}
get usersPlaying() {
return env8827[8];
}
get gameIds() {
return Object.keys(env8827[7]);
}
getNowPlaying(a0) {
return env8827[7][a0];
}
getUserGame(a0) {
return env8827[8][a0];
}
}
c8827_11 = NowPlayingStore;
const r56 = new NowPlayingStore(Dispatcher, {
CONNECTION_OPEN: function handleConnectionOpen() {
env8827[7] = {};
env8827[8] = {};
},
CONNECTION_OPEN_SUPPLEMENTAL: function handleConnectionOpenSupplemental({ guilds, presences }) {
let env20226;
let c20225_0 = false;
guilds.forEach(({ presences }) => {
let env27368;
const r6 = env27368 = {
$parent: env8827
};
env27368[0] = false;
presences.forEach($mk90427(r6));
if (env27368[0]) {
c20225_0 = true;
}
});
const r8 = env20226 = {
$parent: env8827
};
env20226[0] = false;
presences.forEach($mk90427(r8));
if (env20226[0]) {
c20225_0 = true;
}
return c20225_0;
},
LOGOUT: function handleLogout() {
env8827[7] = {};
env8827[8] = {};
},
PRESENCE_UPDATES: function handlePresenceUpdates(a0) {
return a0.updates.map((update) => _handlePresenceUpdate(update)).some((item) => item);
},
PRESENCES_REPLACE: function handlePresencesReplace({ presences }) {
let env20227;
const r5 = env20227 = {
$parent: env8827
};
env20227[0] = false;
presences.forEach($mk90427(r5));
return env20227[0];
}
});
export default r56;