// Metro module 9882 (f9883). import ChannelPinsStore, { FetchState } from "../stores/ChannelPinsStore"; import { AbortCodes, MAX_PINS_PER_CHANNEL, Endpoints } from "../Constants"; import ThreadActionCreators from "../modules/threads/ThreadActionCreators"; import { HTTP } from "../_bundle/sendRequest"; import { APIError } from "../errors/index"; import { intl, t } from "../intl/index.native"; import AlertActionCreators from "./AlertActionCreators"; import Dispatcher from "../Dispatcher"; function $mk115563($env) { return (a0) => { const aPIError = new APIError(a0); const code = aPIError.code; const r28 = intl.string(t.j2d6Km); let body = intl.string(t.fEptJP); let title = r28; if (code != null) { if (AbortCodes.TOO_MANY_PINS_IN_CHANNEL === code) { const r151 = intl.string(t.HI88Q3); body = $env.$parent[0].isPrivate() ? intl.formatToPlainString(t.Q89oQU, { maxPins: MAX_PINS_PER_CHANNEL }) : intl.formatToPlainString(t.NnO1S5, { maxPins: MAX_PINS_PER_CHANNEL, channelName: $env[1] }); title = r151; } else if (AbortCodes.INVALID_ACCESS === code) { title = intl.string(t["25gfQX"]); body = intl.string(t.QNnTwN); } else if (AbortCodes.INVALID_PIN_MESSAGE_CHANNEL === code) { title = intl.string(t["Q5G6+m"]); body = intl.string(t["5hgPfC"]); } else if (AbortCodes.INVALID_THREAD_ARCHIVE_STATE === code) { title = intl.string(t.fu6Lbl); body = intl.string(t.FmrcZM); } else if (AbortCodes.INVALID_ACTION_SYSTEM_MESSAGE === code) { title = intl.string(t["zV0/FC"]); body = intl.string(t.C4a7xI); } else if (AbortCodes.UNKNOWN_MESSAGE === code) { title = intl.string(t.fkqPro); body = intl.string(t.H6fRIg); } else { const r53 = intl.string(t.HI88Q3); let r55 = aPIError.getAnyErrorMessage(); if (r55 == null) { r55 = intl.string(t.fEptJP); } body = r55; title = r53; } } AlertActionCreators.show({ title, body, confirmText: intl.string(t.BddRzS) }); }; } function $mk115564($env) { return () => { const r18 = { title: intl.string(t.xFjByk), body: intl.string(t["0R/Toc"]), confirmText: intl.string(t["7NqTJn"]), cancelText: intl.string(t["ETE/oC"]), onConfirm: null }; r18.onConfirm = c6553_9.unpinMessage.bind(c6553_9, c17531_0, c17531_1); return AlertActionCreators.show(r18); }; } let env6553 = {}; const c6553_9 = { pinMessage: async (a0, a1) => { let env17530 = { $parent: env6553 }; env17530[0] = a0; env17530[1] = a1; let env30153; const r10 = env17530; let c26556_1 = r10; const r13 = env30153 = { $parent: r10 }; let c26556_0 = r13; env30153[0] = void 0; env30153[1] = void 0; const r26 = env17530[0]; env30153[0] = r26.id; env30153[1] = r26.name; await ThreadActionCreators.unarchiveThreadIfNecessary(r26.id); HTTP.put({ url: Endpoints.PIN(env30153[0], env17530[1]), rejectWithError: true }).catch($mk115563(c26556_0)); }, unpinMessage: async (c17531_0, c17531_1) => { const r26 = void 0; let c26557_1 = r26; let c26557_0 = r26; await ThreadActionCreators.unarchiveThreadIfNecessary(c17531_0.id); HTTP.del({ url: Endpoints.PIN(c17531_0.id, c17531_1), oldFormErrors: true, rejectWithError: true }).catch($mk115564(c26557_0)); }, ackPins: (a0) => { Dispatcher.dispatch({ type: "CHANNEL_PINS_ACK", channelId: a0 }); }, fetchPins: (a0, a1) => { const channelId = a0; let reset = a1?.reset; if (reset == null) { reset = false; } let limit = a1?.limit; if (limit == null) { limit = 25; } const before = a1?.before; let r19 = reset; if (!r19) { const pins = ChannelPinsStore.getPins(a0); const r5 = pins == null; let r21 = true; if (!r5) { const state = pins.state; r21 = FetchState.FAILED !== state ? FetchState.LOADING !== state ? FetchState.LOADED_FINISHED !== state ? FetchState.LOADED_HAS_MORE === state ? before == null ? pins.items.length === 0 : pins.items.at(-1).pinnedAt === before : void 0 : false : false : true; } r19 = r21; } if (r19) { Dispatcher.dispatch({ type: "LOAD_PINNED_MESSAGES", channelId: a0, reset }); HTTP.get({ url: Endpoints.PINS(a0), query: { limit, before: before == null ? void 0 : before.toISOString() }, retries: 2, oldFormErrors: true, rejectWithError: true }).then((result) => { Dispatcher.dispatch({ type: "LOAD_PINNED_MESSAGES_SUCCESS", pins: result.body.items, channelId, hasMore: result.body.has_more }); }, () => { Dispatcher.dispatch({ type: "LOAD_PINNED_MESSAGES_FAILURE", channelId }); }); } } }; export default c6553_9;