223 lines
6.8 KiB
TypeScript
223 lines
6.8 KiB
TypeScript
// Metro module 9620 (f9621).
|
|
import GatewayConnectionStore from "../gateway/GatewayConnectionStore";
|
|
import LocaleStore from "../user_settings/LocaleStore";
|
|
import GuildAvailabilityStore from "../../stores/GuildAvailabilityStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import StickersStore from "./StickersStore";
|
|
import { Endpoints } from "../../Constants";
|
|
import { MAX_FAVORITES, UserSettingsDelay } from "../user_settings/UserSettingsConstants";
|
|
import { httpGetWithCountryCodeQuery } from "../../utils/StoreUtils";
|
|
import { rejectWithMigratedError, HTTP } from "../../_bundle/sendRequest";
|
|
import Dispatcher from "../../Dispatcher";
|
|
import { isGuildSticker, isStandardSticker } from "./StickersUtils";
|
|
import InlineUploader from "../../lib/uploader_inline/InlineUploader";
|
|
import { FrecencyUserSettingsActionCreators } from "../user_settings/UserSettingsProtoActionCreators";
|
|
import Module12 from "../../_bundle/Module12";
|
|
import AlertActionCreators from "../../actions/AlertActionCreators";
|
|
import { intl, t } from "../../intl/index.native";
|
|
function $mk115512($env) {
|
|
return () => {
|
|
Dispatcher.dispatch({
|
|
type: "STICKER_PACKS_FETCH_START"
|
|
});
|
|
};
|
|
}
|
|
let $mk82917 = function() {
|
|
return (a0) => StickersStore.getStickerById(a0) != null;
|
|
};
|
|
let env6360 = {};
|
|
export async function fetchStickerPack(c26485_0, c26485_1) {
|
|
let c30123_0 = c26485_0;
|
|
let c30123_1 = c26485_1;
|
|
let c30123_2 = (await httpGetWithCountryCodeQuery({
|
|
url: Endpoints.STICKER_PACK(c26485_0),
|
|
rejectWithError: rejectWithMigratedError()
|
|
})).body;
|
|
Dispatcher.dispatch({
|
|
type: "STICKER_PACK_FETCH_SUCCESS",
|
|
packId: c30123_0,
|
|
pack: c30123_2,
|
|
ingestStickers: c30123_1
|
|
});
|
|
return c30123_2;
|
|
}
|
|
export async function fetchStickerPacks(c26486_0) {
|
|
let env30124;
|
|
const r12 = env6360;
|
|
let c26486_2 = r12;
|
|
const r10 = env30124 = {
|
|
$parent: r12
|
|
};
|
|
let c26486_1 = r10;
|
|
env30124[0] = void 0;
|
|
let r11 = c26486_0;
|
|
if (r11 === void 0) {
|
|
r11 = {};
|
|
}
|
|
let locale = r11.locale;
|
|
if (locale === void 0) {
|
|
locale = LocaleStore.locale;
|
|
}
|
|
env30124[0] = locale;
|
|
env30124[1] = void 0;
|
|
await void 0;
|
|
if (!StickersStore.isFetchingStickerPacks && !StickersStore.hasLoadedStickerPacks) {
|
|
Dispatcher.wait($mk115512(env6360));
|
|
env30124[1] = (await HTTP.get({
|
|
url: Endpoints.STICKER_PACKS,
|
|
query: {
|
|
locale: env30124[0]
|
|
},
|
|
rejectWithError: rejectWithMigratedError()
|
|
})).body.sticker_packs;
|
|
Dispatcher.dispatch({
|
|
type: "STICKER_PACKS_FETCH_SUCCESS",
|
|
packs: env30124[1]
|
|
});
|
|
}
|
|
}
|
|
export async function fetchSticker(c26487_0) {
|
|
let c30125_0 = (await HTTP.get({
|
|
url: Endpoints.STICKER(c26487_0),
|
|
rejectWithError: rejectWithMigratedError()
|
|
})).body;
|
|
if (isGuildSticker(c30125_0)) {
|
|
Dispatcher.dispatch({
|
|
type: "GUILD_STICKER_FETCH_SUCCESS",
|
|
sticker: c30125_0
|
|
});
|
|
} else {
|
|
if (!isStandardSticker(c30125_0)) {
|
|
throw new Error("Invalid sticker type");
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "PACK_STICKER_FETCH_SUCCESS",
|
|
sticker: c30125_0
|
|
});
|
|
}
|
|
}
|
|
export async function fetchGuildStickersWithCreator(c26488_0, signal) {
|
|
let env30126;
|
|
let c26488_3 = env6360;
|
|
const r28 = env30126 = {};
|
|
let c26488_2 = r28;
|
|
env30126[0] = c26488_0;
|
|
env30126[1] = void 0;
|
|
env30126[1] = (await HTTP.get({
|
|
url: Endpoints.GUILD_STICKER_PACKS(c26488_0),
|
|
rejectWithError: rejectWithMigratedError(),
|
|
signal
|
|
})).body;
|
|
Dispatcher.dispatch({
|
|
type: "GUILD_STICKERS_FETCH_SUCCESS",
|
|
guildId: env30126[0],
|
|
stickers: env30126[1].map((item) => item.user != null ? {
|
|
...item,
|
|
user_id: item.user.id,
|
|
user: item.user
|
|
} : item)
|
|
});
|
|
}
|
|
export async function deleteGuildSticker(c26489_0) {
|
|
await HTTP.del({
|
|
url: Endpoints.GUILD_STICKER(c26489_0.guild_id, c26489_0.id),
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
}
|
|
export async function createGuildSticker(c26490_0) {
|
|
const guildId = c26490_0.guildId;
|
|
let c30127_0 = guildId;
|
|
let c30127_1 = await HTTP.post({
|
|
url: Endpoints.GUILD_STICKER_PACKS(guildId),
|
|
body: c26490_0.platform === "web" ? c26490_0.body : void 0,
|
|
fields: c26490_0.platform === "mobile" ? [{
|
|
name: "name",
|
|
value: c26490_0.name
|
|
}, {
|
|
name: "tags",
|
|
value: c26490_0.tags
|
|
}, {
|
|
name: "description",
|
|
value: c26490_0.description
|
|
}] : void 0,
|
|
attachments: c26490_0.platform === "mobile" ? [{
|
|
name: "file",
|
|
file: {
|
|
uri: c26490_0.uri,
|
|
name: c26490_0.name,
|
|
type: c26490_0.mimeType
|
|
}
|
|
}] : void 0,
|
|
headers: InlineUploader.buildHeadersForMd5(c26490_0.originalMd5),
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
let user_id = void 0;
|
|
const currentUser = UserStore.getCurrentUser();
|
|
if (currentUser != null) {
|
|
user_id = currentUser.id;
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "GUILD_STICKERS_CREATE_SUCCESS",
|
|
guildId: c30127_0,
|
|
sticker: {
|
|
...c30127_1.body,
|
|
user_id
|
|
}
|
|
});
|
|
return c30127_1.body;
|
|
}
|
|
export async function updateGuildSticker(c26491_0, c26491_1, body) {
|
|
return (await HTTP.patch({
|
|
url: Endpoints.GUILD_STICKER(c26491_0, c26491_1),
|
|
body,
|
|
rejectWithError: rejectWithMigratedError()
|
|
})).body;
|
|
}
|
|
export function addStickerPreview(a0, a1, a2) {
|
|
Dispatcher.dispatch({
|
|
type: "ADD_STICKER_PREVIEW",
|
|
channelId: a0,
|
|
sticker: a1,
|
|
draftType: a2
|
|
});
|
|
}
|
|
export function clearStickerPreview(a0, a1) {
|
|
Dispatcher.dispatch({
|
|
type: "CLEAR_STICKER_PREVIEW",
|
|
channelId: a0,
|
|
draftType: a1
|
|
});
|
|
}
|
|
export function favoriteSticker(c17357_0) {
|
|
FrecencyUserSettingsActionCreators.updateAsync("favoriteStickers", (a0) => {
|
|
let r1;
|
|
const stickerIds = a0.stickerIds;
|
|
a0.stickerIds = GuildAvailabilityStore.totalUnavailableGuilds > 0 ? stickerIds : GatewayConnectionStore.isConnected() ? stickerIds.filter($mk82917()) : stickerIds;
|
|
if (Module12.size(a0.stickerIds) >= MAX_FAVORITES) {
|
|
AlertActionCreators.show({
|
|
title: intl.string(t["+XYXtZ"]),
|
|
body: intl.formatToPlainString(t.JaIyFi, {
|
|
count: MAX_FAVORITES
|
|
})
|
|
});
|
|
r1 = false;
|
|
} else {
|
|
const stickerIds2 = a0.stickerIds;
|
|
const r29 = stickerIds2.includes(c17357_0);
|
|
r1 = !r29;
|
|
if (!r29) {
|
|
a0.stickerIds.push(c17357_0);
|
|
r1 = void 0;
|
|
}
|
|
}
|
|
return r1;
|
|
}, UserSettingsDelay.INFREQUENT_USER_ACTION);
|
|
}
|
|
export function unfavoriteSticker(c17358_0) {
|
|
FrecencyUserSettingsActionCreators.updateAsync("favoriteStickers", (a0) => {
|
|
a0.stickerIds = a0.stickerIds.filter((stickerId) => stickerId !== c17358_0);
|
|
const stickerIds = a0.stickerIds;
|
|
a0.stickerIds = GuildAvailabilityStore.totalUnavailableGuilds > 0 ? stickerIds : GatewayConnectionStore.isConnected() ? stickerIds.filter($mk82917()) : stickerIds;
|
|
}, UserSettingsDelay.INFREQUENT_USER_ACTION);
|
|
}
|