218 lines
6.3 KiB
TypeScript
218 lines
6.3 KiB
TypeScript
// Metro module 9415 (f9416).
|
|
import EmojiStore from "../modules/emojis/EmojiStore";
|
|
import GatewayConnectionStore from "../modules/gateway/GatewayConnectionStore";
|
|
import GuildAvailabilityStore from "../stores/GuildAvailabilityStore";
|
|
import { Endpoints } from "../Constants";
|
|
import { MAX_FAVORITES, UserSettingsDelay } from "../modules/user_settings/UserSettingsConstants";
|
|
import { PreloadedUserSettingsActionCreators, FrecencyUserSettingsActionCreators } from "../modules/user_settings/UserSettingsProtoActionCreators";
|
|
import { StringValue } from "../_bundle/Module1337";
|
|
import Dispatcher from "../Dispatcher";
|
|
import { HTTP, rejectWithMigratedError } from "../_bundle/sendRequest";
|
|
import InlineUploader from "../lib/uploader_inline/InlineUploader";
|
|
import { AccessibilityAnnouncer } from "../design/shared";
|
|
import { intl, t } from "../intl/index.native";
|
|
import APIError from "../errors/APIError";
|
|
import UnicodeEmojis from "../modules/emojis/UnicodeEmojis";
|
|
import { isNotNullish } from "../utils/GlobalUtils";
|
|
import dedupeEmojisByNameOrId from "../modules/emojis/utils/dedupeEmojisByNameOrId";
|
|
import Module12 from "../_bundle/Module12";
|
|
import AlertActionCreators from "./AlertActionCreators";
|
|
let $mk82452 = function() {
|
|
return (a0) => {
|
|
let r5 = EmojiStore.getCustomEmojiById(a0);
|
|
if (r5 == null) {
|
|
r5 = UnicodeEmojis.getByName(a0);
|
|
}
|
|
return r5;
|
|
};
|
|
};
|
|
export function setDiversityColor(value) {
|
|
PreloadedUserSettingsActionCreators.updateAsync("textAndImages", (a0) => {
|
|
a0.diversitySurrogate = StringValue.create();
|
|
a0.diversitySurrogate.value = value;
|
|
}, UserSettingsDelay.FREQUENT_USER_ACTION);
|
|
}
|
|
export function fetchEmoji(a0) {
|
|
const guildId = a0;
|
|
Dispatcher.dispatch({
|
|
type: "EMOJI_FETCH",
|
|
guildId: a0
|
|
});
|
|
HTTP.get({
|
|
url: Endpoints.GUILD_EMOJIS(a0),
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
}).then((result) => Dispatcher.dispatch({
|
|
type: "EMOJI_FETCH_SUCCESS",
|
|
guildId,
|
|
emojis: result.body
|
|
}), () => Dispatcher.dispatch({
|
|
type: "EMOJI_FETCH_FAILURE",
|
|
guildId
|
|
}));
|
|
}
|
|
export function uploadEmoji({ guildId: guildId2, image, name: name3, roles, analyticsLocation, originalMd5 }) {
|
|
Dispatcher.dispatch({
|
|
type: "EMOJI_UPLOAD_START",
|
|
guildId: guildId2
|
|
});
|
|
return HTTP.post({
|
|
url: Endpoints.GUILD_EMOJIS(guildId2),
|
|
body: {
|
|
image,
|
|
name: name3,
|
|
roles
|
|
},
|
|
headers: InlineUploader.buildHeadersForMd5(originalMd5),
|
|
context: {
|
|
client_event_source: analyticsLocation?.page
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: rejectWithMigratedError()
|
|
}).then((result) => {
|
|
Dispatcher.dispatch({
|
|
type: "EMOJI_UPLOAD_STOP",
|
|
guildId: guildId2
|
|
});
|
|
return result.body;
|
|
}, (a0) => {
|
|
Dispatcher.dispatch({
|
|
type: "EMOJI_UPLOAD_STOP",
|
|
guildId: guildId2
|
|
});
|
|
return Promise.reject(a0);
|
|
});
|
|
}
|
|
export function deleteEmoji(a0, a1, a2) {
|
|
Dispatcher.dispatch({
|
|
type: "EMOJI_DELETE",
|
|
guildId: a0,
|
|
emojiId: a1
|
|
});
|
|
return HTTP.del({
|
|
url: Endpoints.GUILD_EMOJI(a0, a1),
|
|
body: a2 != null ? {
|
|
replaced_by: a2
|
|
} : void 0,
|
|
oldFormErrors: true,
|
|
rejectWithError: rejectWithMigratedError()
|
|
}).then(() => {
|
|
AccessibilityAnnouncer.announce(intl.string(t.L3UUha));
|
|
});
|
|
}
|
|
export async function updateEmoji(c26435_0) {
|
|
let r70;
|
|
let c26435_3;
|
|
let c26435_4 = 0;
|
|
let c30087_0, c30087_1, c30087_2, c30087_3, c30087_4;
|
|
try {
|
|
c30087_0 = void 0;
|
|
c30087_1 = void 0;
|
|
c30087_2 = void 0;
|
|
c30087_3 = void 0;
|
|
c30087_0 = c26435_0.guildId;
|
|
c30087_1 = c26435_0.emojiId;
|
|
c30087_2 = c26435_0.name;
|
|
c30087_3 = c26435_0.roles;
|
|
await void 0;
|
|
c26435_4 = 1;
|
|
r70 = await HTTP.patch({
|
|
url: Endpoints.GUILD_EMOJI(c30087_0, c30087_1),
|
|
body: {
|
|
name: c30087_2,
|
|
roles: c30087_3
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
});
|
|
c26435_4 = 0;
|
|
} catch ($e) {
|
|
const r31 = $e;
|
|
let r8 = r31;
|
|
c26435_3 = r31;
|
|
if (c26435_4 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r88 = c26435_3;
|
|
c26435_4 = 0;
|
|
c30087_4 = r88;
|
|
throw new APIError(c30087_4);
|
|
} catch (r84) {
|
|
r8 = r84;
|
|
c26435_3 = r84;
|
|
if (c26435_4 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r70;
|
|
}
|
|
export function favoriteEmoji(a0) {
|
|
const r2 = a0 == null;
|
|
let r5 = null;
|
|
if (!r2) {
|
|
let id = a0.id;
|
|
if (id == null) {
|
|
id = UnicodeEmojis.convertSurrogateToBase(a0.surrogates)?.name;
|
|
}
|
|
if (id == null) {
|
|
id = a0.name;
|
|
}
|
|
r5 = id;
|
|
}
|
|
const name = r5;
|
|
if (name != null) {
|
|
FrecencyUserSettingsActionCreators.updateAsync("favoriteEmojis", (a0) => {
|
|
let r47;
|
|
const emojis = a0.emojis;
|
|
a0.emojis = GuildAvailabilityStore.totalUnavailableGuilds > 0 ? emojis : GatewayConnectionStore.isConnected() ? [...dedupeEmojisByNameOrId(emojis.map($mk82452()).filter(isNotNullish)).keys()] : emojis;
|
|
if (Module12.size(a0.emojis) >= MAX_FAVORITES) {
|
|
AlertActionCreators.show({
|
|
title: intl.string(t["+XYXtZ"]),
|
|
body: intl.formatToPlainString(t.JaIyFi, {
|
|
count: MAX_FAVORITES
|
|
})
|
|
});
|
|
r47 = false;
|
|
} else {
|
|
const r46 = a0.emojis.includes(name);
|
|
r47 = !r46;
|
|
if (!r46) {
|
|
a0.emojis.push(name);
|
|
r47 = void 0;
|
|
}
|
|
}
|
|
return r47;
|
|
}, UserSettingsDelay.INFREQUENT_USER_ACTION);
|
|
}
|
|
}
|
|
export function unfavoriteEmoji(a0) {
|
|
const r2 = a0 == null;
|
|
let r5 = null;
|
|
if (!r2) {
|
|
let id = a0.id;
|
|
if (id == null) {
|
|
id = UnicodeEmojis.convertSurrogateToBase(a0.surrogates)?.name;
|
|
}
|
|
if (id == null) {
|
|
id = a0.name;
|
|
}
|
|
r5 = id;
|
|
}
|
|
const name2 = r5;
|
|
if (name2 != null) {
|
|
FrecencyUserSettingsActionCreators.updateAsync("favoriteEmojis", (a0) => {
|
|
const emojis = a0.emojis;
|
|
a0.emojis = GuildAvailabilityStore.totalUnavailableGuilds > 0 ? emojis : GatewayConnectionStore.isConnected() ? [...dedupeEmojisByNameOrId(emojis.map($mk82452()).filter(isNotNullish)).keys()] : emojis;
|
|
if (a0.emojis.includes(name2)) {
|
|
a0.emojis = a0.emojis.filter((emoji) => name2 !== emoji);
|
|
return void 0;
|
|
}
|
|
return false;
|
|
}, UserSettingsDelay.INFREQUENT_USER_ACTION);
|
|
}
|
|
}
|