// Metro module 15284 (f15285). import NotificationCenterItemsStore from "./NotificationCenterItemsStore"; import { Endpoints } from "../../Constants"; import Dispatcher from "../../Dispatcher"; import TrackedHTTPUtils from "../../utils/TrackedHTTPUtils"; import { NetworkActionNames } from "../../_bundle/Module503"; import { exact } from "../../_bundle/Module1385"; import { isMentionItem, isRemoteAcked } from "./NotificationCenterUtils"; import { HTTP } from "../../_bundle/sendRequest"; import { NotificationCenterAckedBeforeId } from "../user_settings/UserSettings"; function $mk116909($env) { return (a0) => { const r4 = a0.body?.items || []; const r6 = $env; const items = r4.map((item) => item.type); return exact({ page: r6[2], items, item_count: items.length }); }; } let env10861 = {}; export async function markNotificationCenterRemoteItemAcked(c27983_0) { let c27983_4 = 0; let c30859_0; L10: { try { c30859_0 = c27983_0; c27983_4 = 1; Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_ITEMS_ACK", optimistic: true, ids: [c27983_0] }); await HTTP.post({ url: Endpoints.NOTIF_CENTER_ITEMS_ACK(c27983_0), rejectWithError: true }); c27983_4 = 0; } catch ($e) { let r8 = $e; if (c27983_4 !== 0) { while (true) { try { c27983_4 = 0; Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_ITEMS_ACK_FAILURE", ids: [c30859_0] }); break L10; } catch ($e) { r8 = $e; if (c27983_4 === 0) { break; } } } } throw r8; } } } export function setNotificationCenterActive(a0) { Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_SET_ACTIVE", active: a0 }); } export function setNotificationCenterTabFocused(a0) { Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_TAB_FOCUSED", focused: a0 }); } export function resetNotificationCenter() { Dispatcher.dispatch({ type: "RESET_NOTIFICATION_CENTER" }); } export async function fetchNotificationCenterItems(c27982_0, c27982_1) { let c27982_2, c27982_3, c27982_4; let c27982_5 = 0; const r14 = env10861; L19: { try { let env30858; c27982_3 = r14; const r39 = env30858 = { $parent: r14 }; c27982_2 = r39; env30858[0] = c27982_0; env30858[1] = c27982_1; env30858[2] = void 0; env30858[3] = void 0; if (NotificationCenterItemsStore.loading) { break L19; } await Dispatcher.dispatch({ type: "LOAD_NOTIFICATION_CENTER_ITEMS" }); env30858[2] = Math.ceil(NotificationCenterItemsStore.items.length / env30858[0].limit); const r78 = c27982_2; c27982_5 = 1; env30858[3] = await TrackedHTTPUtils.get({ url: Endpoints.NOTIF_CENTER_ITEMS(), trackedActionData: { event: NetworkActionNames.NOTIFICATION_CENTER_PAGE_FETCH, properties: $mk116909(r78) }, query: { ...env30858[0] }, rejectWithError: true }); const r118 = env30858[1]; if (r118 != null) { r118(); } await Dispatcher.dispatch({ type: "LOAD_NOTIFICATION_CENTER_ITEMS_SUCCESS", items: env30858[3].body.items, cursor: env30858[3].body.cursor, hasMore: env30858[3].body.has_more }); c27982_5 = 0; } catch ($e) { const r37 = $e; let r8 = r37; c27982_4 = r37; if (c27982_5 !== 0) { while (true) { try { c27982_5 = 0; const r165 = env30858[1]; if (r165 != null) { r165(); } await Dispatcher.dispatch({ type: "LOAD_NOTIFICATION_CENTER_ITEMS_FAILURE" }); } catch (r161) { r8 = r161; c27982_4 = r161; if (c27982_5 === 0) { break; } continue; } return void 0; } } throw r8; } return void 0; } } export function markNotificationCenterItemAcked(a0) { if (a0.local_id != null) { Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_ITEMS_LOCAL_ACK", localIds: [a0.local_id] }); } else if (isMentionItem(a0)) { Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_ITEMS_ACK", optimistic: true, ids: [a0.id] }); } else { markNotificationCenterRemoteItemAcked(a0.id); } } export function markNotificationCenterLocalItemsAcked(a0) { Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_ITEMS_LOCAL_ACK", localIds: a0 }); } export function markNotificationCenterMentionAcked(a0) { Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_ITEMS_ACK", optimistic: true, ids: [a0] }); } export async function bulkMarkNotificationCenterItemsAcked(c27984_0) { let c27984_1, c27984_2, c27984_3; let c27984_4 = 0; const r11 = env10861; L10: { try { let env30860; c27984_2 = r11; const r26 = env30860 = { $parent: r11 }; c27984_1 = r26; env30860[0] = void 0; const ids = c27984_0.map((item) => item.id); env30860[0] = ids; c27984_4 = 1; Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_ITEMS_ACK", optimistic: true, ids }); await HTTP.post({ url: Endpoints.NOTIF_CENTER_ITEMS_BULK_ACK, query: { item_ids: c27984_0.filter((item) => item.local_id == null || isMentionItem(item)).map((item) => item.id) }, rejectWithError: true }); c27984_4 = 0; } catch ($e) { const r24 = $e; let r8 = r24; c27984_3 = r24; if (c27984_4 !== 0) { while (true) { try { c27984_4 = 0; Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_ITEMS_ACK_FAILURE", ids: env30860[0] }); break L10; } catch (r70) { r8 = r70; c27984_3 = r70; if (c27984_4 === 0) { break; } } } } throw r8; } } } export async function deleteNotificationCenterItem(c27985_0) { let c27985_3; let c27985_4 = 0; let c30861_0, c30861_1; try { c30861_0 = c27985_0; const setting = NotificationCenterAckedBeforeId.getSetting(); c27985_4 = 1; Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_ITEM_DELETE", id: c27985_0.id }); await TrackedHTTPUtils.delete({ url: Endpoints.NOTIF_CENTER_ITEMS(c27985_0.id), body: { item_type: isMentionItem(c27985_0) ? "mention" : "regular" }, trackedActionData: { event: NetworkActionNames.NOTIFICATION_CENTER_ITEM_DELETE, properties: { notification_center_id: c27985_0.id, acked: isRemoteAcked(c27985_0, setting), item_type: c27985_0.type } }, rejectWithError: false }); c27985_4 = 0; } catch ($e) { const r31 = $e; let r8 = r31; c27985_3 = r31; if (c27985_4 !== 0) { while (true) { try { const r99 = c27985_3; c27985_4 = 0; c30861_1 = r99; Dispatcher.dispatch({ type: "NOTIFICATION_CENTER_ITEM_DELETE_FAILURE", item: c30861_0 }); throw c30861_1; } catch (r95) { r8 = r95; c27985_3 = r95; if (c27985_4 === 0) { break; } } } } throw r8; } }