Fix ProfileSets gradient and server profile preset apply (#780)
This commit is contained in:
parent
14a0932c2e
commit
d0c9dce310
1 changed files with 41 additions and 14 deletions
|
|
@ -58,6 +58,10 @@ type ProfileCollectible = {
|
||||||
};
|
};
|
||||||
|
|
||||||
type ImageInput = string | { imageUri: string; } | null | undefined;
|
type ImageInput = string | { imageUri: string; } | null | undefined;
|
||||||
|
type DisplayNameStylesLike = DisplayNameStyles & {
|
||||||
|
fontId?: number;
|
||||||
|
effectId?: number;
|
||||||
|
};
|
||||||
|
|
||||||
function dispatch(type: string, payload: Record<string, unknown>) {
|
function dispatch(type: string, payload: Record<string, unknown>) {
|
||||||
FluxDispatcher.dispatch({ type, ...payload });
|
FluxDispatcher.dispatch({ type, ...payload });
|
||||||
|
|
@ -73,6 +77,22 @@ function hasImageInput(value: ImageInput): boolean {
|
||||||
return typeof value === "object" && "imageUri" in value && isNonEmptyString(value.imageUri);
|
return typeof value === "object" && "imageUri" in value && isNonEmptyString(value.imageUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeDisplayNameStyles(value: DisplayNameStylesLike | null | undefined): DisplayNameStylesLike | null {
|
||||||
|
if (!value) return null;
|
||||||
|
const fontId = value.fontId ?? value.font_id;
|
||||||
|
const effectId = value.effectId ?? value.effect_id;
|
||||||
|
if (typeof fontId !== "number" || typeof effectId !== "number") return null;
|
||||||
|
const colors = Array.isArray(value.colors) ? [...value.colors] : [];
|
||||||
|
|
||||||
|
return {
|
||||||
|
fontId,
|
||||||
|
effectId,
|
||||||
|
font_id: fontId,
|
||||||
|
effect_id: effectId,
|
||||||
|
colors
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function imageUrlToBase64(url: string): Promise<string | null> {
|
export async function imageUrlToBase64(url: string): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|
@ -208,12 +228,11 @@ export async function getCurrentProfile(guildId?: string, options: CurrentProfil
|
||||||
type: nameplateToUse.type || 2
|
type: nameplateToUse.type || 2
|
||||||
} : null;
|
} : null;
|
||||||
|
|
||||||
const displayNameStylesToUse = pendingChanges.pendingDisplayNameStyles ?? userAny.displayNameStyles;
|
const savedDisplayNameStyles = isGuildProfile
|
||||||
const displayNameStyles = displayNameStylesToUse ? {
|
? (guildMember?.displayNameStyles ?? userAny.displayNameStyles)
|
||||||
font_id: displayNameStylesToUse.font_id ?? 0,
|
: userAny.displayNameStyles;
|
||||||
effect_id: displayNameStylesToUse.effect_id ?? 0,
|
const displayNameStylesToUse = pendingChanges.pendingDisplayNameStyles ?? savedDisplayNameStyles;
|
||||||
colors: Array.isArray(displayNameStylesToUse.colors) ? displayNameStylesToUse.colors : []
|
const displayNameStyles = normalizeDisplayNameStyles(displayNameStylesToUse as DisplayNameStylesLike | null | undefined);
|
||||||
} : null;
|
|
||||||
|
|
||||||
const pendingAvatar = pendingChanges.pendingAvatar ?? pendingChanges.avatar;
|
const pendingAvatar = pendingChanges.pendingAvatar ?? pendingChanges.avatar;
|
||||||
const avatarToUse: ImageInput = hasImageInput(pendingAvatar)
|
const avatarToUse: ImageInput = hasImageInput(pendingAvatar)
|
||||||
|
|
@ -245,7 +264,7 @@ export async function getCurrentProfile(guildId?: string, options: CurrentProfil
|
||||||
globalName: isGuildProfile
|
globalName: isGuildProfile
|
||||||
? (pendingChanges.pendingNickname ?? guildMember?.nick ?? null)
|
? (pendingChanges.pendingNickname ?? guildMember?.nick ?? null)
|
||||||
: (pendingChanges.pendingGlobalName ?? currentUser.globalName ?? null),
|
: (pendingChanges.pendingGlobalName ?? currentUser.globalName ?? null),
|
||||||
pronouns: pendingChanges.pendingPronouns ?? userProfile?.pronouns ?? null,
|
pronouns: isGuildProfile ? null : (pendingChanges.pendingPronouns ?? userProfile?.pronouns ?? null),
|
||||||
avatarDecoration,
|
avatarDecoration,
|
||||||
profileEffect,
|
profileEffect,
|
||||||
nameplate,
|
nameplate,
|
||||||
|
|
@ -278,11 +297,16 @@ export async function loadPresetAsPending(preset: ProfilePreset, guildId?: strin
|
||||||
const current = await getCurrentProfile(guildId, {
|
const current = await getCurrentProfile(guildId, {
|
||||||
isGuildProfile: isGuild
|
isGuildProfile: isGuild
|
||||||
});
|
});
|
||||||
const profilePrefix = "USER_SETTINGS_ACCOUNT";
|
const profilePrefix = isGuild ? "GUILD_IDENTITY_SETTINGS" : "USER_SETTINGS_ACCOUNT";
|
||||||
const dispatchProfile = (type: string, payload: Record<string, unknown>) => {
|
const dispatchProfile = (type: string, payload: Record<string, unknown>) => {
|
||||||
dispatch(type, isGuild ? { ...payload, guildId } : payload);
|
dispatch(type, isGuild ? { ...payload, guildId } : payload);
|
||||||
};
|
};
|
||||||
const setPending = (type: string, payload: Record<string, unknown>) => dispatchProfile(type, payload);
|
const setPending = (type: string, payload: Record<string, unknown>) => {
|
||||||
|
dispatchProfile(type, payload);
|
||||||
|
if (isGuild && type.startsWith("GUILD_IDENTITY_SETTINGS_")) {
|
||||||
|
dispatchProfile(type.replace("GUILD_IDENTITY_SETTINGS_", "USER_SETTINGS_ACCOUNT_"), payload);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if ("avatarDataUrl" in preset) {
|
if ("avatarDataUrl" in preset) {
|
||||||
const avatarValue = preset.avatarDataUrl;
|
const avatarValue = preset.avatarDataUrl;
|
||||||
|
|
@ -300,14 +324,14 @@ export async function loadPresetAsPending(preset: ProfilePreset, guildId?: strin
|
||||||
setPending(`${profilePrefix}_SET_PENDING_BIO`, { bio: bioValue });
|
setPending(`${profilePrefix}_SET_PENDING_BIO`, { bio: bioValue });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.skipPronouns && "pronouns" in preset && preset.pronouns !== current.pronouns) {
|
if (!isGuild && !options.skipPronouns && "pronouns" in preset && preset.pronouns !== current.pronouns) {
|
||||||
const pronounsValue = preset.pronouns === null ? "" : preset.pronouns;
|
const pronounsValue = preset.pronouns === null ? "" : preset.pronouns;
|
||||||
setPending(`${profilePrefix}_SET_PENDING_PRONOUNS`, { pronouns: pronounsValue });
|
setPending(`${profilePrefix}_SET_PENDING_PRONOUNS`, { pronouns: pronounsValue });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.skipGlobalName && preset.globalName !== undefined && preset.globalName !== current.globalName) {
|
if (!options.skipGlobalName && preset.globalName !== undefined && preset.globalName !== current.globalName) {
|
||||||
if (isGuild) {
|
if (isGuild) {
|
||||||
setPending("USER_SETTINGS_ACCOUNT_SET_PENDING_NICKNAME", { nickname: preset.globalName });
|
setPending("GUILD_IDENTITY_SETTINGS_SET_PENDING_NICKNAME", { nickname: preset.globalName });
|
||||||
} else {
|
} else {
|
||||||
setPending("USER_SETTINGS_ACCOUNT_SET_PENDING_GLOBAL_NAME", { globalName: preset.globalName });
|
setPending("USER_SETTINGS_ACCOUNT_SET_PENDING_GLOBAL_NAME", { globalName: preset.globalName });
|
||||||
}
|
}
|
||||||
|
|
@ -331,8 +355,11 @@ export async function loadPresetAsPending(preset: ProfilePreset, guildId?: strin
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preset.displayNameStyles !== undefined && !jsonEq(preset.displayNameStyles, current.displayNameStyles)) {
|
if (preset.displayNameStyles !== undefined) {
|
||||||
setPending(`${profilePrefix}_SET_PENDING_DISPLAY_NAME_STYLES`, { displayNameStyles: preset.displayNameStyles });
|
const presetDisplayNameStyles = normalizeDisplayNameStyles(preset.displayNameStyles as DisplayNameStylesLike | null | undefined);
|
||||||
|
if (!jsonEq(presetDisplayNameStyles, current.displayNameStyles)) {
|
||||||
|
setPending(`${profilePrefix}_SET_PENDING_DISPLAY_NAME_STYLES`, { displayNameStyles: presetDisplayNameStyles });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preset.themeColors !== undefined && !jsonEq(preset.themeColors, current.themeColors)) {
|
if (preset.themeColors !== undefined && !jsonEq(preset.themeColors, current.themeColors)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue