// Metro module 9548 (f9549). import { useMemo, useEffect } from "react"; import GatewayConnectionStore from "../gateway/GatewayConnectionStore"; import ChannelStore from "../../stores/ChannelStore"; import SummaryStore from "./SummaryStore"; import { Routes } from "../../Constants"; import Durations from "../../utils/Durations"; import Dispatcher from "../../Dispatcher"; import { HTTP } from "../../_bundle/sendRequest"; import { APIError } from "../../errors/index"; import Module12 from "../../_bundle/Module12"; import { canSeeChannelSummaries } from "../../experiments/ChannelSummariesExperiment"; import { useStateFromStores, useStateFromStoresArray } from "../../_bundle/defaultAreStatesEqual"; import { HermesBuiltin, $createGenerator } from "../../_hermes/prelude"; function $mk82716($env) { return () => $env[0].join(","); } function $mk82717($env) { return () => { let env26472 = { $parent: $env }; env26472[0] = function _fetch() { const r9 = (0, env26472.$parent.$parent[3])(function() { let c31504_0, c31504_2; let c31504_1 = 0; let c31504_4 = 0; let c31504_3 = 0; return $createGenerator(function() { let value2, value3; const r0 = c31504_4; if (r0 === 2) { c31504_4 = 3; HermesBuiltin.throwTypeError("Generator functions may not be called on executing generators"); throw new Error("unreachable"); } const value = arguments[1]; const r3 = arguments[0]; const r11 = env26472; const r10 = env26472.$parent.$parent; if (r0 === 3) { if (r3 === 1) { throw value; } if (r3 === 2) { return { value, done: true }; } return { value: void 0, done: true }; } while (true) { L26: { L24: { L20: { L16: { L14: { L9: { try { c31504_4 = 2; const r19 = c31504_1; if (r19 === 0) { if (r3 === 1) { c31504_4 = 3; throw value; } if (r3 === 2) { c31504_4 = 3; break L26; } c31504_0 = r11; c31504_3 = 1; value3 = (0, r10[15])(); c31504_1 = 3; c31504_4 = 1; break L24; } if (r19 === 1) { c31504_3 = 0; } else { if (r19 === 2) { if (r3 === 1) { c31504_4 = 3; throw value; } if (r3 === 2) { c31504_4 = 3; break L16; } c31504_4 = 3; break L14; } if (r3 === 1) { c31504_4 = 3; throw value; } if (r3 === 2) { c31504_3 = 0; c31504_4 = 3; break L9; } c31504_3 = 0; } const r28 = c31504_0; value2 = (0, r28.$parent.$parent[17])(r28.$parent[2].split(",")); c31504_1 = 2; c31504_4 = 1; break L20; } catch (r43) { c31504_2 = r43; if (c31504_3 === 0) { c31504_4 = 3; throw r43; } c31504_1 = 1; continue; } } return { value, done: true }; } return { value: void 0, done: true }; } return { value, done: true }; } return { value: value2, done: false }; } return { value: value3, done: false }; } return { value, done: true }; } }); }); env26472[0] = r9; return r9.apply(this, arguments); }; if ($env[1]) { (function() { return env26472[0].apply(this, arguments); })(); } }; } function $mk115491($env) { return (a0) => canSeeChannelSummaries(ChannelStore.getChannel(a0), false, true); } function $mk115492($env) { return (a0) => { const r8 = Date.now(); const r10 = SummaryStore.status(a0); if (r10?.fetching) { return false; } const lastReceivedAt = r10?.lastReceivedAt; return lastReceivedAt == null || r8 - lastReceivedAt > c6295_9; }; } let fetchChannelAffinities, fetchSummariesBulk, c6295_9, c6295_10, c6295_11; let $mk82715 = function() { return () => GatewayConnectionStore.isConnected(); }; let env6295 = {}; export async function fetchSummary(channelId, summaryId) { let c26468_4; let c26468_5 = 0; let c30108_0, c30108_1, c30108_2, c30108_3, c30108_4, c30108_5; L16: { try { c30108_0 = channelId; c30108_1 = void 0; c30108_2 = void 0; c30108_3 = void 0; c30108_4 = void 0; if (SummaryStore.shouldFetch(channelId, summaryId)) { const requestedAt = Date.now(); c30108_1 = requestedAt; Dispatcher.dispatch({ type: "REQUEST_CHANNEL_SUMMARY", channelId, summaryId, requestedAt }); c30108_2 = void 0; c30108_3 = void 0; c26468_5 = 1; c30108_4 = await HTTP.get({ url: Routes.CHANNEL_SUMMARY(channelId, summaryId), rejectWithError: false }); c30108_3 = c30108_4?.body; c26468_5 = 0; Dispatcher.dispatch({ type: "RECEIVE_CHANNEL_SUMMARY", channelId: c30108_0, summary: c30108_3, error: c30108_2, requestedAt: c30108_1, receivedAt: Date.now() }); break L16; } } catch ($e) { const r30 = $e; let r8 = r30; c26468_4 = r30; if (c26468_5 !== 0) { while (true) { try { const r100 = c26468_4; c26468_5 = 0; c30108_5 = r100; c30108_2 = new APIError(c30108_5); Dispatcher.dispatch({ type: "RECEIVE_CHANNEL_SUMMARY", channelId: c30108_0, summary: c30108_3, error: c30108_2, requestedAt: c30108_1, receivedAt: Date.now() }); break L16; } catch (r96) { r8 = r96; c26468_4 = r96; if (c26468_5 === 0) { break; } } } } throw r8; } return void 0; } } export async function fetchSummaries(channelId2) { let summaries, summaries2; let body, error, c26469_5; let c26469_6 = 0; let c30109_0, c30109_1, c30109_2, c30109_3, c30109_4, c30109_5; L26: { try { c30109_0 = channelId2; c30109_1 = void 0; c30109_2 = void 0; c30109_3 = void 0; c30109_4 = void 0; if (SummaryStore.shouldFetch(channelId2)) { const requestedAt = Date.now(); c30109_1 = requestedAt; Dispatcher.dispatch({ type: "REQUEST_CHANNEL_SUMMARIES", channelId: channelId2, requestedAt }); c30109_2 = void 0; c30109_3 = void 0; c26469_6 = 1; c30109_3 = await HTTP.get({ url: Routes.CHANNEL_SUMMARIES(channelId2), rejectWithError: false }); c26469_6 = 0; const r74 = c30109_3; const r78 = (r74 == null ? void 0 : r74.body?.summaries) instanceof Array; const r80 = c30109_3; if (r78) { summaries = r80.body.summaries; } else { const body2 = r80?.body; body = body2; if (body2 == null) { body = []; } summaries = body; } c30109_4 = summaries; c30109_4 = Module12.takeRight(c30109_4, 75); error = c30109_2; if (error == null) { error = void 0; } Dispatcher.dispatch({ type: "RECEIVE_CHANNEL_SUMMARIES", channelId: c30109_0, summaries: c30109_4, error, requestedAt: c30109_1, receivedAt: Date.now() }); break L26; } } catch ($e) { const r30 = $e; let r8 = r30; c26469_5 = r30; if (c26469_6 !== 0) { while (true) { try { const r121 = c26469_5; c26469_6 = 0; c30109_5 = r121; c30109_2 = new APIError(c30109_5); const r132 = c30109_3; const r136 = (r132 == null ? void 0 : r132.body?.summaries) instanceof Array; const r138 = c30109_3; if (r136) { summaries2 = r138.body.summaries; } else { const body3 = r138?.body; body = body3; if (body3 == null) { body = []; } summaries2 = body; } c30109_4 = summaries2; c30109_4 = Module12.takeRight(c30109_4, 75); error = c30109_2; if (error == null) { error = void 0; } Dispatcher.dispatch({ type: "RECEIVE_CHANNEL_SUMMARIES", channelId: c30109_0, summaries: c30109_4, error, requestedAt: c30109_1, receivedAt: Date.now() }); break L26; } catch (r117) { r8 = r117; c26469_5 = r117; if (c26469_6 === 0) { break; } } } } throw r8; } return void 0; } } export function setHighlightedSummary(a0, a1) { Dispatcher.dispatch({ type: "SET_HIGHLIGHTED_SUMMARY", channelId: a0, summaryId: a1 == null ? null : a1 }); } export function setSelectedSummary(a0, a1) { let summaryId2 = a1; if (a0 != null && a1 != null) { fetchSummary(a0, a1); } if (a1 == null) { summaryId2 = null; } Dispatcher.dispatch({ type: "SET_SELECTED_SUMMARY", channelId: a0, summaryId: summaryId2 }); } export function updateVisibleMessages(a0, a1) { Dispatcher.dispatch({ type: "UPDATE_VISIBLE_MESSAGES", topVisibleMessage: a0 == null ? null : a0, bottomVisibleMessage: a1 == null ? null : a1 }); } export function setSummaryFeedback(a0, a1) { Dispatcher.dispatch({ type: "SET_SUMMARY_FEEDBACK", summary: a0, rating: a1 }); } fetchChannelAffinities = async function fetchChannelAffinities() { let r50; let error2, c26470_3; let c26470_4 = 0; let c30110_0, c30110_1, c30110_2, c30110_3, c30110_4; L18: { try { c30110_0 = void 0; c30110_1 = void 0; c30110_2 = void 0; c30110_3 = void 0; if (SummaryStore.shouldFetchChannelAffinities()) { const requestedAt = Date.now(); c30110_0 = requestedAt; Dispatcher.dispatch({ type: "REQUEST_CHANNEL_AFFINITIES", requestedAt }); c30110_1 = void 0; c30110_2 = void 0; c26470_4 = 1; c30110_2 = await HTTP.get({ url: "/users/@me/affinities/channels", rejectWithError: false }); c26470_4 = 0; const r70 = c30110_2; c30110_3 = r70 == null ? void 0 : r70.body?.channel_affinities; error2 = c30110_1; if (error2 == null) { error2 = void 0; } Dispatcher.dispatch({ type: "RECEIVE_CHANNEL_AFFINITIES", affinities: c30110_3, error: error2, requestedAt: c30110_0, receivedAt: Date.now() }); break L18; } r50 = Promise.resolve(null); } catch ($e) { const r27 = $e; let r8 = r27; c26470_3 = r27; if (c26470_4 !== 0) { while (true) { try { const r100 = c26470_3; c26470_4 = 0; c30110_4 = r100; c30110_1 = new APIError(c30110_4); const r111 = c30110_2; c30110_3 = r111 == null ? void 0 : r111.body?.channel_affinities; error2 = c30110_1; if (error2 == null) { error2 = void 0; } Dispatcher.dispatch({ type: "RECEIVE_CHANNEL_AFFINITIES", affinities: c30110_3, error: error2, requestedAt: c30110_0, receivedAt: Date.now() }); break L18; } catch (r96) { r8 = r96; c26470_3 = r96; if (c26470_4 === 0) { break; } } } } throw r8; } return r50; } }; fetchSummariesBulk = async function fetchSummariesBulk(c26471_0, c26471_1) { let r86, useChannelAffinities; let c26471_2, c26471_3, c26471_4, c26471_5; let c26471_6 = 0; const r13 = env6295; L27: { L26: { try { let env30111; c26471_4 = r13; const r36 = env30111 = { $parent: r13 }; c26471_3 = r36; env30111[1] = void 0; env30111[2] = void 0; env30111[0] = c26471_0; let r37 = c26471_1; if (r37 === void 0) { r37 = {}; } L15: { L12: { const useQuickSwitcher = r37.useQuickSwitcher; if (useQuickSwitcher !== void 0) { env30111[1] = useQuickSwitcher; useChannelAffinities = r37.useChannelAffinities; if (useChannelAffinities !== void 0) { break L12; } } else { env30111[1] = true; useChannelAffinities = r37.useChannelAffinities; if (useChannelAffinities !== void 0) { break L12; } } env30111[2] = true; env30111[3] = void 0; env30111[4] = void 0; env30111[5] = void 0; env30111[6] = void 0; break L15; } env30111[2] = useChannelAffinities; env30111[3] = void 0; env30111[4] = void 0; env30111[5] = void 0; env30111[6] = void 0; } await void 0; const r61 = env30111[0]; c26471_2 = r61; if (r61 == null) { c26471_2 = []; } env30111[0] = c26471_2; env30111[3] = Date.now(); const r72 = env30111[0].concat(SummaryStore.defaultChannelIds({ withQuickSwitcher: env30111[1], withChannelAffinities: env30111[2] })); const r74 = env6295; const r81 = r72.filter($mk115491(r74)).filter($mk115492(r74)).slice(0, 50); env30111[0] = r81; if (r81.length === 0) { r86 = Promise.resolve(null); break L27; } Dispatcher.dispatch({ type: "REQUEST_CHANNEL_SUMMARIES_BULK", channelIds: env30111[0], requestedAt: env30111[3] }); env30111[4] = void 0; env30111[5] = void 0; c26471_6 = 1; env30111[5] = await HTTP.post({ url: Routes.USER_SUMMARIES, body: { channel_ids: env30111[0] }, rejectWithError: false }); c26471_6 = 0; const r133 = env30111[5]; env30111[6] = r133 == null ? void 0 : r133.body.summaries; Dispatcher.dispatch({ type: "RECEIVE_CHANNEL_SUMMARIES_BULK", requestedAt: env30111[3], receivedAt: Date.now(), summaries: env30111[6], requestArgs: { channelIds: env30111[0] }, error: env30111[4] }); } catch ($e) { const r34 = $e; let r8 = r34; c26471_5 = r34; if (c26471_6 !== 0) { while (true) { try { const r162 = c26471_5; c26471_6 = 0; env30111[7] = r162; env30111[4] = new APIError(env30111[7]); const r173 = env30111[5]; env30111[6] = r173 == null ? void 0 : r173.body.summaries; Dispatcher.dispatch({ type: "RECEIVE_CHANNEL_SUMMARIES_BULK", requestedAt: env30111[3], receivedAt: Date.now(), summaries: env30111[6], requestArgs: { channelIds: env30111[0] }, error: env30111[4] }); break L26; } catch (r158) { r8 = r158; c26471_5 = r158; if (c26471_6 === 0) { break; } } } } throw r8; } } return void 0; } return r86; }; export function useChannelSummaries({ channelIds }) { if (channelIds === void 0) { channelIds = []; } if (channelIds === void 0) { channelIds = []; } let env17285; const r4 = env17285 = { $parent: env6295 }; env17285[0] = channelIds; env17285[1] = void 0; env17285[2] = void 0; const stateFromStores = useStateFromStores([GatewayConnectionStore], $mk82715()); env17285[1] = stateFromStores; const memo = useMemo($mk82716(r4), [channelIds]); env17285[2] = memo; useEffect($mk82717(r4), [memo, stateFromStores]); return useStateFromStoresArray([SummaryStore], () => SummaryStore.topSummaries(), []); } export async function deleteSummary(c26473_0) { let c26473_3; let c26473_4 = 0; let c30112_0, c30112_1; try { c30112_0 = c26473_0; c26473_4 = 1; await HTTP.del({ url: Routes.CHANNEL_SUMMARY(c26473_0.channelId, c26473_0.id), rejectWithError: false }); Dispatcher.dispatch({ type: "DELETE_SUMMARY", summary: c30112_0 }); c26473_4 = 0; } catch ($e) { const r28 = $e; let r8 = r28; c26473_3 = r28; if (c26473_4 !== 0) { while (true) { try { const r72 = c26473_3; c26473_4 = 0; c30112_1 = r72; throw new APIError(c30112_1); } catch (r68) { r8 = r68; c26473_3 = r68; if (c26473_4 === 0) { break; } } } } throw r8; } } c6295_9 = 30 * Durations.Millis.SECOND; c6295_10 = {}; c6295_11 = {}; const r49 = { setSummaryFeedback, updateVisibleMessages, setSelectedSummary, setHighlightedSummary, fetchSummaries, fetchSummariesBulk, useChannelSummaries, deleteSummary }; export default r49; export function toggleTopicsBar() { Dispatcher.dispatch({ type: "TOGGLE_TOPICS_BAR" }); } export function stopPolling(a0) { if (c6295_10[a0] == null) { c6295_10[a0] = 0; } c6295_10[a0] = c6295_10[a0] + -1; if (c6295_10[a0] <= 0) { if (c6295_10[a0] == null) { c6295_10[a0] = 0; } c6295_10[a0] = c6295_10[a0] + 0; c6295_10[a0]; clearInterval(c6295_11[a0]); } } export { fetchChannelAffinities }; export { fetchSummariesBulk }; export function useMaybeFetchChannelAffinitiesAndSummaries(r2 = []) { let env17284; const r1 = env17284 = { $parent: env6295 }; env17284[0] = r2; env17284[1] = void 0; env17284[2] = void 0; const stateFromStores = useStateFromStores([GatewayConnectionStore], $mk82715()); env17284[1] = stateFromStores; const memo = useMemo($mk82716(r1), [r2]); env17284[2] = memo; useEffect($mk82717(r1), [memo, stateFromStores]); }