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

166 lines
4.6 KiB
TypeScript

// Metro module 5123 (f5124).
import ChannelStore from "../../stores/ChannelStore";
import ConnectedAppsStore from "../../stores/ConnectedAppsStore";
import MessageStore from "../../stores/MessageStore";
import { isObjectEntryNotNullish } from "../../utils/GlobalUtils";
import Module589 from "../../_bundle/Module589";
import Dispatcher from "../../Dispatcher";
function $mk75499() {
return (a0) => a0.application.parent_id == null;
}
let c3085_6, c3085_7, c3085_8, c3085_9, NOT_FETCHED, c3085_11, c3085_12, updateFetchStates;
const recomputeFromAppTokens = function recomputeFromAppTokens() {
const r5 = [...c3085_7.values()];
c3085_8 = r5;
c3085_9 = r5.filter($mk75499());
};
updateFetchStates = function updateFetchStates(a0, applicationIds) {
if (applicationIds == null) {
NOT_FETCHED = a0;
c3085_11.clear();
c3085_12 = c3085_12 + 1;
} else {
for (const item of applicationIds) {
c3085_11.set(item, a0);
}
c3085_12 = c3085_12 + 1;
}
};
c3085_6 = {
NOT_FETCHED: "NOT_FETCHED",
FETCHING: "FETCHING",
FETCHED: "FETCHED"
};
c3085_7 = new Map();
c3085_8 = [];
c3085_9 = [];
NOT_FETCHED = c3085_6.NOT_FETCHED;
c3085_11 = new Map();
c3085_12 = 0;
class AuthorizedAppsStore extends Module589.Store {
static displayName = "AuthorizedAppsStore";
initialize() {
this.waitFor(ChannelStore, ConnectedAppsStore, MessageStore);
}
getNewestTokenForApplication(a0) {
const r1 = a0 == null;
let r2 = null;
if (!r1) {
let r7 = c3085_7.get(a0);
if (r7 == null) {
r7 = null;
}
r2 = r7;
}
return r2;
}
getNewestTokens() {
return c3085_8;
}
getNewestTokensForNonChildrenApplications() {
return c3085_9;
}
getFetchState() {
return NOT_FETCHED;
}
getFetchStateForApplication(a0) {
let r10;
L6: {
if (NOT_FETCHED !== c3085_6.FETCHING && NOT_FETCHED !== c3085_6.FETCHED) {
r10 = c3085_11.get(a0);
if (r10 != null) {
break L6;
}
r10 = NOT_FETCHED;
} else {
r10 = NOT_FETCHED;
}
}
return r10;
}
getApplicationFetchStateVersion() {
return c3085_12;
}
}
const authorizedAppsStore = new AuthorizedAppsStore(Dispatcher, {
USER_AUTHORIZED_APPS_REQUEST: function handleUserAuthorizedAppsRequest(a0) {
if (a0.request.type === "full") {
updateFetchStates(c3085_6.FETCHING);
} else {
updateFetchStates(c3085_6.FETCHING, a0.request.applicationIds);
}
},
USER_AUTHORIZED_APPS_REQUEST_CANCELLED: function handleUserAuthorizedAppsRequestCancelled(a0) {
let r1 = false;
for (const applicationId of a0.applicationIds) {
if (c3085_11.get(applicationId) === c3085_6.FETCHING) {
c3085_11.delete(applicationId);
r1 = true;
}
}
if (r1) {
c3085_12 = c3085_12 + 1;
}
},
USER_AUTHORIZED_APPS_REQUEST_FAILED: function handleUserAuthorizedAppsRequestFailed(a0) {
if (a0.request.type === "full") {
updateFetchStates(c3085_6.FETCHED);
} else {
updateFetchStates(c3085_6.FETCHED, a0.request.applicationIds);
}
},
USER_AUTHORIZED_APPS_UPDATE: function handleAuthorizedAppsUpdate(a0) {
const isFullFetch = a0.isFullFetch;
const FETCHED = c3085_6.FETCHED;
if (isFullFetch) {
updateFetchStates(FETCHED);
c3085_7 = new Map(Object.entries(a0.tokens).filter(isObjectEntryNotNullish));
recomputeFromAppTokens();
} else {
updateFetchStates(FETCHED, Object.keys(a0.tokens));
for (const item of Object.entries(a0.tokens)) {
const [r44, r45] = item;
if (r45 == null) {
c3085_7.delete(r44);
} else {
c3085_7.set(r44, r45);
}
}
recomputeFromAppTokens();
}
},
OAUTH2_TOKEN_CREATE: function handleOAuth2TokenCreate(a0) {
const { id, application } = a0;
c3085_7.set(application.id, {
id,
application,
scopes: a0.scopes
});
const r17 = [...c3085_7.values()];
c3085_8 = r17;
c3085_9 = r17.filter($mk75499());
},
OAUTH2_TOKEN_DELETE: function handleOAuth2TokenDelete(a0) {
const id = a0.id;
const r11 = c3085_7.get(a0.applicationId);
if (r11 != null && r11.id === id) {
c3085_7.delete(r11.application.id);
const r20 = [...c3085_7.values()];
c3085_8 = r20;
c3085_9 = r20.filter($mk75499());
return void 0;
}
return false;
},
LOGOUT: function handleLogout() {
c3085_7 = new Map();
c3085_8 = [];
c3085_9 = [];
NOT_FETCHED = c3085_6.NOT_FETCHED;
c3085_11.clear();
c3085_12 = c3085_12 + 1;
}
});
export default authorizedAppsStore;
export { c3085_6 as FetchState };