225 lines
7.6 KiB
TypeScript
225 lines
7.6 KiB
TypeScript
// Metro module 11078 (f11079).
|
|
import AuthenticationStore from "../../stores/AuthenticationStore";
|
|
import SafetyHubStore from "./SafetyHubStore";
|
|
import { AGE_CHECK_MAX_POLL_ATTEMPTS, AGE_CHECK_POLL_INTERVAL_MS } from "./SafetyHubConstants";
|
|
import { Endpoints } from "../../Constants";
|
|
import Dispatcher from "../../Dispatcher";
|
|
import { HTTP, rejectWithMigratedError } from "../../_bundle/sendRequest";
|
|
import { isImageFile, isVideoFile } from "../messages/MediaFormatTesters";
|
|
import { isFlaggedContentEmpty } from "./SafetyHubUtils";
|
|
function $mk86345($env) {
|
|
return ({ filename }) => isImageFile(filename) || isVideoFile(filename);
|
|
}
|
|
let env7474 = {};
|
|
export async function checkSuspendedUserAgeVerification() {
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_CHECK_AUTOMATED_UNDERAGE_APPEAL_START"
|
|
});
|
|
const suspendedUserToken = AuthenticationStore.getSuspendedUserToken();
|
|
const ageCheckAttempts = SafetyHubStore.getAgeCheckAttempts();
|
|
await HTTP.post({
|
|
url: Endpoints.SAFETY_HUB_CHECK_SUSPENDED_AGE_VERIFICATION,
|
|
body: {
|
|
token: suspendedUserToken
|
|
},
|
|
rejectWithError: rejectWithMigratedError()
|
|
}).then((result) => {
|
|
const success = result.body.success;
|
|
if (success ? !success : ageCheckAttempts < AGE_CHECK_MAX_POLL_ATTEMPTS) {
|
|
setTimeout(() => checkSuspendedUserAgeVerification(), AGE_CHECK_POLL_INTERVAL_MS);
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_CHECK_AUTOMATED_UNDERAGE_APPEAL_SUCCESS",
|
|
success
|
|
});
|
|
}).catch((a0) => {
|
|
let error = a0 == null ? void 0 : a0.body?.message;
|
|
if (error == null) {
|
|
error = "Unknown error";
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_CHECK_AUTOMATED_UNDERAGE_APPEAL_FAILURE",
|
|
error
|
|
});
|
|
});
|
|
}
|
|
export async function getSafetyHubData() {
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_FETCH_START"
|
|
});
|
|
const suspendedUserToken = AuthenticationStore.getSuspendedUserToken();
|
|
const url = suspendedUserToken != null ? Endpoints.SAFETY_HUB_SUSPENDED : Endpoints.SAFETY_HUB;
|
|
await (suspendedUserToken != null ? HTTP.post({
|
|
url,
|
|
body: {
|
|
token: suspendedUserToken
|
|
},
|
|
rejectWithError: rejectWithMigratedError()
|
|
}) : HTTP.get({
|
|
url,
|
|
rejectWithError: rejectWithMigratedError()
|
|
})).then(({ body }) => {
|
|
const classifications = body.classifications;
|
|
let guild_classifications = body.guild_classifications;
|
|
const { account_standing, is_dsa_eligible, username, is_appeal_eligible } = body;
|
|
let appeal_eligibility = body.appeal_eligibility;
|
|
const r11 = classifications.map((classification) => {
|
|
if (classification.flagged_content != null && classification.flagged_content.length > 0) {
|
|
const r10 = env7474;
|
|
const r11 = classification.flagged_content[0];
|
|
r11.attachments = r11.attachments.filter($mk86345(r10));
|
|
classification.flagged_content = isFlaggedContentEmpty(r11) ? [] : [r11];
|
|
}
|
|
return classification;
|
|
});
|
|
if (guild_classifications == null) {
|
|
guild_classifications = [];
|
|
}
|
|
const r22 = {
|
|
type: "SAFETY_HUB_FETCH_SUCCESS",
|
|
classifications: r11.concat(guild_classifications),
|
|
accountStanding: account_standing,
|
|
isDsaEligible: is_dsa_eligible,
|
|
username,
|
|
isAppealEligible: is_appeal_eligible,
|
|
appealEligibility: null
|
|
};
|
|
if (appeal_eligibility == null) {
|
|
appeal_eligibility = [];
|
|
}
|
|
r22.appealEligibility = appeal_eligibility;
|
|
Dispatcher.dispatch(r22);
|
|
}).catch((a0) => {
|
|
let error = a0 == null ? void 0 : a0.body?.message;
|
|
if (error == null) {
|
|
error = "Unknown error";
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_FETCH_FAILURE",
|
|
error
|
|
});
|
|
});
|
|
}
|
|
export async function getSafetyHubDataForClassification(classificationId) {
|
|
const classificationId2 = classificationId;
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_FETCH_CLASSIFICATION_START",
|
|
classificationId
|
|
});
|
|
const suspendedUserToken = AuthenticationStore.getSuspendedUserToken();
|
|
const url = suspendedUserToken != null ? Endpoints.SAFETY_HUB_SUSPENDED : Endpoints.SAFETY_HUB;
|
|
await (suspendedUserToken != null ? HTTP.post({
|
|
url,
|
|
body: {
|
|
token: suspendedUserToken
|
|
},
|
|
rejectWithError: rejectWithMigratedError()
|
|
}) : HTTP.get({
|
|
url,
|
|
rejectWithError: rejectWithMigratedError()
|
|
})).then(({ body }) => {
|
|
const { classifications, account_standing, is_dsa_eligible, username, is_appeal_eligible } = body;
|
|
const classification = classifications.find((classification) => classification.id === classificationId2);
|
|
if (classification != null) {
|
|
const r24 = env7474;
|
|
if (classification.flagged_content != null && classification.flagged_content.length > 0) {
|
|
const r29 = classification.flagged_content[0];
|
|
r29.attachments = r29.attachments.filter($mk86345(r24));
|
|
classification.flagged_content = isFlaggedContentEmpty(r29) ? [] : [r29];
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_FETCH_CLASSIFICATION_SUCCESS",
|
|
classification,
|
|
accountStanding: account_standing,
|
|
isDsaEligible: is_dsa_eligible,
|
|
username,
|
|
isAppealEligible: is_appeal_eligible
|
|
});
|
|
} else {
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_FETCH_CLASSIFICATION_FAILURE",
|
|
error: "Classification not found.",
|
|
classificationId: classificationId2
|
|
});
|
|
}
|
|
}).catch((a0) => {
|
|
let error = a0 == null ? void 0 : a0.body?.message;
|
|
if (error == null) {
|
|
error = "Unknown error";
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_FETCH_CLASSIFICATION_FAILURE",
|
|
error,
|
|
classificationId: classificationId2
|
|
});
|
|
});
|
|
}
|
|
export async function requestReview(c26933_0, signal, user_input) {
|
|
const classificationId3 = c26933_0;
|
|
const suspendedUserToken = AuthenticationStore.getSuspendedUserToken();
|
|
const url = suspendedUserToken != null ? Endpoints.SAFETY_HUB_REQUEST_SUSPENDED_USER_REVIEW(classificationId3) : Endpoints.SAFETY_HUB_REQUEST_REVIEW(classificationId3);
|
|
const r46 = suspendedUserToken != null ? HTTP.put({
|
|
url,
|
|
body: {
|
|
signal,
|
|
user_input,
|
|
token: suspendedUserToken
|
|
},
|
|
rejectWithError: rejectWithMigratedError()
|
|
}) : HTTP.put({
|
|
url,
|
|
body: {
|
|
signal,
|
|
user_input
|
|
},
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_REQUEST_REVIEW_START"
|
|
});
|
|
await r46.then(() => {
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_REQUEST_REVIEW_SUCCESS",
|
|
classificationId: classificationId3
|
|
});
|
|
}).catch((a0) => {
|
|
let error = a0 == null ? void 0 : a0.body?.message;
|
|
if (error == null) {
|
|
error = "Unknown error";
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_REQUEST_REVIEW_FAILURE",
|
|
error
|
|
});
|
|
throw a0;
|
|
});
|
|
}
|
|
export async function requestSuspendedUserAgeVerification(from_classification_id) {
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_REQUEST_AUTOMATED_UNDERAGE_APPEAL_START"
|
|
});
|
|
await HTTP.post({
|
|
url: Endpoints.SAFETY_HUB_REQUEST_SUSPENDED_AGE_VERIFICATION,
|
|
body: {
|
|
token: AuthenticationStore.getSuspendedUserToken(),
|
|
from_classification_id
|
|
},
|
|
rejectWithError: rejectWithMigratedError()
|
|
}).then(({ body }) => {
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_REQUEST_AUTOMATED_UNDERAGE_APPEAL_SUCCESS",
|
|
verificationRequestId: body.verification_request_id,
|
|
verificationWebviewUrl: body.verification_webview_url
|
|
});
|
|
}).catch((a0) => {
|
|
let error = a0 == null ? void 0 : a0.body?.message;
|
|
if (error == null) {
|
|
error = "Unknown error";
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "SAFETY_HUB_REQUEST_AUTOMATED_UNDERAGE_APPEAL_FAILURE",
|
|
error
|
|
});
|
|
});
|
|
}
|