Files
discord-decomp/modules/badges/BadgeDirectoryActionCreators.tsx
T
2026-11-01 12:12:55 +02:00

156 lines
4.5 KiB
TypeScript

// Metro module 8112 (f8113).
import UserStore from "../../stores/UserStore";
import { Endpoints, ME } from "../../Constants";
import Dispatcher from "../../Dispatcher";
import { HTTP } from "../../_bundle/sendRequest";
import MonitoringAgent from "../monitoring/MonitoringAgent";
import { MetricEvents } from "../../_bundle/Module5872";
import SentryUtils_native from "../../utils/SentryUtils.native";
const urlUserId = function urlUserId(id2) {
return id2 === UserStore.getCurrentUser()?.id ? ME : id2;
};
export async function fetchBadgeDirectory(c26106_0, c26106_1) {
let id, c26106_5;
let c26106_6 = 0;
let c29890_1, c29890_0, c29890_2, c29890_3, c29890_4, c29890_5, c29890_6, c29890_7, c29890_8, c29890_9;
L17: {
try {
c29890_1 = void 0;
c29890_0 = c26106_0;
let r47 = c26106_1;
if (r47 === void 0) {
r47 = {};
}
c29890_1 = r47;
c29890_2 = void 0;
c29890_3 = void 0;
c29890_4 = void 0;
c29890_5 = void 0;
c29890_6 = void 0;
c29890_7 = void 0;
c29890_8 = void 0;
await void 0;
id = c29890_0;
if (id == null) {
id = UserStore.getCurrentUser()?.id;
}
c29890_2 = id;
if (c29890_2 != null) {
c29890_3 = UserStore.getCurrentUser()?.id;
c29890_4 = "viewed_user:" + (c29890_3 != null ? c29890_2 === c29890_3 ? "self" : "other" : "other");
c29890_5 = "attempt:" + (c29890_1.isRetry === true ? "retry" : "initial");
c29890_6 = Date.now();
Dispatcher.dispatch({
type: "BADGE_DIRECTORY_FETCH_START",
userId: c29890_2
});
c26106_6 = 1;
c29890_7 = (await HTTP.get({
url: Endpoints.USER_BADGES((0, urlUserId)(c29890_2)),
rejectWithError: true
})).body;
c29890_8 = [c29890_4, "result:success", "catalog_state:" + (c29890_7.badges.length === 0 ? "empty" : "non_empty"), c29890_5];
MonitoringAgent.distribution({
name: MetricEvents.BADGE_DIRECTORY_CATALOG_FETCH,
tags: c29890_8
}, Date.now() - c29890_6);
Dispatcher.dispatch({
type: "BADGE_DIRECTORY_FETCH_SUCCESS",
userId: c29890_2,
badges: c29890_7.badges
});
c26106_6 = 0;
}
} catch ($e) {
const r44 = $e;
let r8 = r44;
c26106_5 = r44;
if (c26106_6 !== 0) {
while (true) {
try {
const r211 = c26106_5;
c26106_6 = 0;
c29890_9 = r211;
MonitoringAgent.distribution({
name: MetricEvents.BADGE_DIRECTORY_CATALOG_FETCH,
tags: [c29890_4, "result:failure", "catalog_state:unknown", c29890_5]
}, Date.now() - c29890_6);
Dispatcher.dispatch({
type: "BADGE_DIRECTORY_FETCH_FAILURE",
userId: c29890_2
});
SentryUtils_native.captureException(c29890_9);
break L17;
} catch (r207) {
r8 = r207;
c26106_5 = r207;
if (c26106_6 === 0) {
break;
}
}
}
}
throw r8;
}
}
}
export async function fetchBadge(c26107_0, c26107_1) {
let id2, c26107_5;
let c26107_6 = 0;
let c29891_0, c29891_1, c29891_2;
L17: {
try {
c29891_0 = void 0;
c29891_1 = void 0;
id2 = c26107_1;
if (c26107_1 == null) {
id2 = UserStore.getCurrentUser()?.id;
}
c29891_0 = id2;
if (id2 != null) {
c26107_6 = 1;
c29891_1 = await HTTP.get({
url: Endpoints.USER_BADGE(urlUserId(id2), c26107_0),
rejectWithError: true
});
Dispatcher.dispatch({
type: "BADGE_FETCH_SUCCESS",
userId: c29891_0,
badge: c29891_1.body
});
c26107_6 = 0;
break L17;
}
} catch ($e) {
const r29 = $e;
let r8 = r29;
c26107_5 = r29;
if (c26107_6 !== 0) {
while (true) {
try {
const r83 = c26107_5;
c26107_6 = 0;
c29891_2 = r83;
SentryUtils_native.captureException(c29891_2);
break L17;
} catch (r79) {
r8 = r79;
c26107_5 = r79;
if (c26107_6 === 0) {
break;
}
}
}
}
throw r8;
}
return void 0;
}
}
export function markBadgeDirectoryBadgeIndicatorSeen(a0) {
Dispatcher.dispatch({
type: "BADGE_DIRECTORY_MARK_BADGE_INDICATOR_SEEN",
badgeId: a0
});
}