295 lines
8.6 KiB
TypeScript
295 lines
8.6 KiB
TypeScript
// Metro module 9226 (f9227).
|
|
import { DEVICE_TOKEN, DEVICE_VOIP_TOKEN, Endpoints, Routes } from "../Constants";
|
|
import { DEVICE_PUSH_VOIP_PROVIDER, getDevicePushProvider } from "../modules/push_notifications/PushNotificationConstants";
|
|
import Dispatcher from "../Dispatcher";
|
|
import { HTTP, rejectWithMigratedError } from "../_bundle/sendRequest";
|
|
import AuthenticationActionCreators from "./AuthenticationActionCreators";
|
|
import { transitionTo } from "../modules/routing/router_utils";
|
|
import { Storage } from "../_bundle/Module595";
|
|
import InlineUploader from "../lib/uploader_inline/InlineUploader";
|
|
import { SafetyScannedUploadSurface } from "../lib/uploader_inline/safetyScannedUploadSurfaces";
|
|
import { trackUserAvatarUpdated } from "../modules/user_profile/utils/trackUserAvatarUpdated";
|
|
import UserSettingsModalActionCreators from "./UserSettingsModalActionCreators";
|
|
const saveProfileAndAccountRequest = async function saveProfileAndAccountRequest(c26397_0, c26397_1) {
|
|
let c26397_3;
|
|
let c30065_4;
|
|
c26397_3 = void 0;
|
|
let c30065_0 = c26397_0;
|
|
let r30 = c26397_1;
|
|
if (r30 === void 0) {
|
|
r30 = {};
|
|
}
|
|
let c30065_1 = r30;
|
|
c30065_4 = void 0;
|
|
await void 0;
|
|
let c30065_2 = await HTTP.patch({
|
|
url: Endpoints.ME,
|
|
oldFormErrors: true,
|
|
body: c30065_0,
|
|
headers: c30065_1.headers,
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
let c30065_3 = c30065_2.body;
|
|
if (c30065_3.token) {
|
|
c30065_4 = c30065_3.token;
|
|
delete c30065_3["token"];
|
|
Dispatcher.dispatch({
|
|
type: "UPDATE_TOKEN",
|
|
token: c30065_4,
|
|
userId: c30065_3.id
|
|
});
|
|
if (c30065_0?.password != null && c30065_0?.new_password != null) {
|
|
Dispatcher.dispatch({
|
|
type: "PASSWORD_UPDATED",
|
|
userId: c30065_3.id
|
|
});
|
|
}
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "CURRENT_USER_UPDATE",
|
|
user: c30065_3
|
|
});
|
|
return c30065_2;
|
|
};
|
|
export function accountDetailsInit() {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_INIT"
|
|
});
|
|
}
|
|
export function accountDetailsClose() {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_CLOSE"
|
|
});
|
|
}
|
|
export function disableAccount(a0, a1) {
|
|
return HTTP.post({
|
|
url: a1 ? Endpoints.DELETE_ACCOUNT : Endpoints.DISABLE_ACCOUNT,
|
|
body: {
|
|
password: a0
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: rejectWithMigratedError()
|
|
}).then(() => {
|
|
AuthenticationActionCreators.logoutInternal();
|
|
transitionTo(Routes.DEFAULT_LOGGED_OUT);
|
|
});
|
|
}
|
|
export { saveProfileAndAccountRequest };
|
|
export function saveProfileAndAccountChanges({ username, discriminator, email, emailToken, password: password2, avatar, avatarDescription, avatarId, avatarDecoration, newPassword: newPassword2, globalName, legacyUsername, nameplate, primaryGuildId, displayNameStyles, avatarOriginalMd5 }) {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_SUBMIT"
|
|
});
|
|
const r30 = {
|
|
username,
|
|
email,
|
|
email_token: emailToken,
|
|
password: password2,
|
|
avatar,
|
|
avatar_description: avatarDescription,
|
|
avatar_id: avatarId,
|
|
discriminator,
|
|
global_name: globalName,
|
|
legacy_username: legacyUsername,
|
|
new_password: newPassword2
|
|
};
|
|
if (avatarDecoration !== void 0) {
|
|
let avatar_decoration_sku_id = avatarDecoration?.skuId;
|
|
if (avatar_decoration_sku_id == null) {
|
|
avatar_decoration_sku_id = null;
|
|
}
|
|
r30.avatar_decoration_sku_id = avatar_decoration_sku_id;
|
|
}
|
|
if (nameplate !== void 0) {
|
|
let nameplate_sku_id = nameplate?.skuId;
|
|
if (nameplate_sku_id == null) {
|
|
nameplate_sku_id = null;
|
|
}
|
|
r30.nameplate_sku_id = nameplate_sku_id;
|
|
}
|
|
if (primaryGuildId !== void 0) {
|
|
r30.primary_guild_id = primaryGuildId;
|
|
}
|
|
if (displayNameStyles != null) {
|
|
r30.display_name_font_id = displayNameStyles.fontId;
|
|
r30.display_name_effect_id = displayNameStyles.effectId;
|
|
r30.display_name_colors = displayNameStyles.colors;
|
|
} else if (displayNameStyles === null) {
|
|
r30.display_name_font_id = null;
|
|
r30.display_name_effect_id = null;
|
|
r30.display_name_colors = null;
|
|
}
|
|
const push_token = Storage.get(DEVICE_TOKEN);
|
|
const devicePushProvider = getDevicePushProvider();
|
|
if (devicePushProvider != null && push_token != null) {
|
|
r30.push_provider = devicePushProvider;
|
|
r30.push_token = push_token;
|
|
}
|
|
const push_voip_token = Storage.get(DEVICE_VOIP_TOKEN);
|
|
if (DEVICE_PUSH_VOIP_PROVIDER != null && push_voip_token != null) {
|
|
r30.push_voip_provider = DEVICE_PUSH_VOIP_PROVIDER;
|
|
r30.push_voip_token = push_voip_token;
|
|
}
|
|
const r61 = {};
|
|
r61[SafetyScannedUploadSurface.USER_DEFAULT_PROFILE_AVATAR] = avatarOriginalMd5;
|
|
return saveProfileAndAccountRequest(r30, {
|
|
headers: InlineUploader.buildHeadersForMd5(r61)
|
|
}).then((result) => {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_SUBMIT_SUCCESS"
|
|
});
|
|
if (!(avatar == null && avatarId == null)) {
|
|
Dispatcher.dispatch({
|
|
type: "RECENT_AVATARS_UPDATE"
|
|
});
|
|
}
|
|
return result;
|
|
}, (a0) => {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_SUBMIT_FAILURE",
|
|
errors: a0.body
|
|
});
|
|
return a0;
|
|
});
|
|
}
|
|
export function getHarvestStatus() {
|
|
return HTTP.get({
|
|
url: Endpoints.USER_HARVEST,
|
|
oldFormErrors: true,
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
}
|
|
export function requestHarvest(a0) {
|
|
return HTTP.post({
|
|
url: Endpoints.USER_HARVEST,
|
|
body: {
|
|
backends: a0
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
}
|
|
export function clearErrors() {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_CLEAR_ERRORS"
|
|
});
|
|
}
|
|
export function resetPendingAccountChanges() {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_RESET_PENDING_ACCOUNT_CHANGES"
|
|
});
|
|
}
|
|
export function resetAllPending() {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_RESET_PENDING_CHANGES"
|
|
});
|
|
}
|
|
export function resetAllTryItOut() {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_RESET_TRY_IT_OUT_CHANGES"
|
|
});
|
|
}
|
|
export function resetAndCloseUserProfileForm() {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_RESET_AND_CLOSE_FORM"
|
|
});
|
|
}
|
|
export function resetPendingLegacyUsernameDisabled() {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_RESET_PENDING_LEGACY_USERNAME_DISABLED"
|
|
});
|
|
}
|
|
export function resetPendingPrimaryGuildChanges() {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PROFILE_SETTINGS_RESET_PENDING_PRIMARY_GUILD_CHANGES"
|
|
});
|
|
}
|
|
export function updateAccount(a0) {
|
|
Dispatcher.dispatch({
|
|
type: "USER_SETTINGS_MODAL_UPDATE_ACCOUNT",
|
|
settings: a0
|
|
});
|
|
}
|
|
export function resetAccount() {
|
|
Dispatcher.dispatch({
|
|
type: "USER_SETTINGS_MODAL_RESET"
|
|
});
|
|
}
|
|
export function saveAccountChanges(a0, a1) {
|
|
Dispatcher.dispatch({
|
|
type: "USER_SETTINGS_MODAL_SUBMIT"
|
|
});
|
|
const { username, email, emailToken, password, avatar: avatar2, newPassword, discriminator } = a0;
|
|
const close = a1.close;
|
|
const body = {
|
|
username,
|
|
email,
|
|
email_token: emailToken,
|
|
password,
|
|
avatar: avatar2,
|
|
new_password: newPassword,
|
|
discriminator: discriminator != null ? discriminator !== "" ? discriminator : void 0 : void 0
|
|
};
|
|
const push_token = Storage.get(DEVICE_TOKEN);
|
|
const devicePushProvider = getDevicePushProvider();
|
|
if (devicePushProvider != null && push_token != null) {
|
|
body.push_provider = devicePushProvider;
|
|
body.push_token = push_token;
|
|
}
|
|
const push_voip_token = Storage.get(DEVICE_VOIP_TOKEN);
|
|
if (DEVICE_PUSH_VOIP_PROVIDER != null && push_voip_token != null) {
|
|
body.push_voip_provider = DEVICE_PUSH_VOIP_PROVIDER;
|
|
body.push_voip_token = push_voip_token;
|
|
}
|
|
return HTTP.patch({
|
|
url: Endpoints.ME,
|
|
oldFormErrors: true,
|
|
body,
|
|
rejectWithError: rejectWithMigratedError()
|
|
}).then((result) => {
|
|
const body = result.body;
|
|
const token = body.token;
|
|
delete body["token"];
|
|
Dispatcher.dispatch({
|
|
type: "UPDATE_TOKEN",
|
|
token,
|
|
userId: body.id
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "CURRENT_USER_UPDATE",
|
|
user: body
|
|
});
|
|
if (avatar2 !== void 0) {
|
|
trackUserAvatarUpdated({
|
|
avatarHash: body.avatar
|
|
});
|
|
}
|
|
if (newPassword != null) {
|
|
Dispatcher.dispatch({
|
|
type: "USER_PASSWORD_UPDATE",
|
|
user: body,
|
|
newPassword
|
|
});
|
|
}
|
|
if (password != null && newPassword != null) {
|
|
Dispatcher.dispatch({
|
|
type: "PASSWORD_UPDATED",
|
|
userId: body.id
|
|
});
|
|
}
|
|
if (close) {
|
|
UserSettingsModalActionCreators.close();
|
|
} else {
|
|
Dispatcher.dispatch({
|
|
type: "USER_SETTINGS_MODAL_SUBMIT_COMPLETE"
|
|
});
|
|
}
|
|
return result;
|
|
}, (a0) => {
|
|
Dispatcher.dispatch({
|
|
type: "USER_SETTINGS_MODAL_SUBMIT_FAILURE",
|
|
errors: a0.body
|
|
});
|
|
return a0;
|
|
});
|
|
}
|