// Metro module 5795 (f5796). import FamilyCenterControlledSettingsStore from "./FamilyCenterControlledSettingsStore"; import { FamilyCenterAction } from "./FamilyCenterConstants"; import { AnalyticEvents, Endpoints } from "../../Constants"; import { maybeFetchCollectiblesProduct } from "../collectibles/CollectiblesActionCreators"; import Dispatcher from "../../Dispatcher"; import { HTTP, rejectWithMigratedError } from "../../_bundle/sendRequest"; import AnalyticsUtils from "../../utils/AnalyticsUtils"; import { getProtoFieldClass, createModifiedProto } from "../user_settings/UserSettingsProtoUtils"; import { PreloadedUserSettings } from "../../_bundle/Module1306"; import { protoToB64 } from "../user_settings/UserSettingsUtils"; let maybeFetchCollectiblesForGifts; const maybeFetchCollectiblesForInvoices = async function maybeFetchCollectiblesForInvoices(c25601_0) { const set = new Set(); let c29610_0 = set; c25601_0.forEach((item) => { if (item.invoice_items != null && item.invoice_items.length > 0) { const r8 = item.invoice_items[0]; if (r8.sku_id != null) { c29610_0.add(r8.sku_id); } } }); await Promise.all(Array.from(set).map((item) => maybeFetchCollectiblesProduct(item))); }; maybeFetchCollectiblesForGifts = async function maybeFetchCollectiblesForGifts(c25602_0) { const set = new Set(); let c29611_0 = set; c25602_0.forEach((item) => { if (item.sku_id != null) { c29611_0.add(item.sku_id); } }); await Promise.all(Array.from(set).map((item) => maybeFetchCollectiblesProduct(item))); }; const r32 = { initialPageLoad: async () => { let c25607_13; c25607_13 = void 0; Dispatcher.dispatch({ type: "FAMILY_CENTER_FETCH_START" }); let c29613_0 = (await HTTP.get({ url: Endpoints.FAMILY_CENTER_TEEN_ACTIVITY_ME, rejectWithError: rejectWithMigratedError() })).body; let c29613_1 = c29613_0.teen_audit_log; let c29613_2 = c29613_0.linked_users; let c29613_3 = c29613_0.users; let c29613_4 = c29613_0.age_group; const teen_user_id = c29613_1?.teen_user_id; const range_start_id = c29613_1?.range_start_id; const totals2 = c29613_1?.totals; let totals = totals2; if (totals2 == null) { totals = {}; } let actions = c29613_1?.actions; if (actions == null) { actions = []; } let users = c29613_1?.users; if (users == null) { users = []; } const guilds2 = c29613_1?.guilds; let guilds = guilds2; if (guilds2 == null) { guilds = []; } const top_user_activities4 = c29613_1?.top_user_activities; let top_user_activities = top_user_activities4; if (top_user_activities4 == null) { top_user_activities = []; } const top_guild_activities4 = c29613_1?.top_guild_activities; let top_guild_activities = top_guild_activities4; if (top_guild_activities4 == null) { top_guild_activities = []; } let amount = c29613_1 == null ? void 0 : c29613_1.total_spend?.amount; if (amount == null) { amount = null; } let currency = c29613_1 == null ? void 0 : c29613_1.total_spend?.currency; if (currency == null) { currency = null; } const spending_limit3 = c29613_0.spending_limit; let spending_limit = spending_limit3; if (spending_limit3 == null) { spending_limit = null; } const monthly_purchases3 = c29613_0.monthly_purchases; let monthly_purchases = monthly_purchases3; if (monthly_purchases3 == null) { monthly_purchases = null; } const invoices4 = c29613_1?.invoices; let invoices = invoices4; if (invoices4 == null) { invoices = []; } const gifts4 = c29613_1?.gifts; let gifts = gifts4; if (gifts4 == null) { gifts = []; } let c29613_5 = { teenId: teen_user_id, rangeStartId: range_start_id, totals, actions, users, guilds, topUserActivities: top_user_activities, topGuildActivities: top_guild_activities, totalSpendAmount: amount, totalSpendCurrency: currency, spendingLimit: spending_limit, monthlyPurchases: monthly_purchases, invoices, gifts }; if (c29613_5.invoices != null && c29613_5.invoices.length > 0) { await (0, maybeFetchCollectiblesForInvoices)(c29613_5.invoices); } if (c29613_5.gifts != null && c29613_5.gifts.length > 0) { await (0, maybeFetchCollectiblesForGifts)(c29613_5.gifts); } Dispatcher.dispatch({ type: "FAMILY_CENTER_INITIAL_LOAD", familyCenterTeenActivity: c29613_5, linkedUsers: c29613_2, users: c29613_3, ageGroup: c29613_4 }); if (c29613_0.restricted_schedule != null && c29613_5.teenId != null) { Dispatcher.dispatch({ type: "USER_RESTRICTED_SCHEDULE_UPDATE", userId: c29613_5.teenId, restrictedSchedule: c29613_0.restricted_schedule }); } return c29613_5; }, fetchLinkedUsers: async () => { let c25608_1; c25608_1 = void 0; let c29614_0 = (await HTTP.get({ url: Endpoints.FAMILY_CENTER_LINKED_USERS, rejectWithError: rejectWithMigratedError() })).body; let c29614_1 = { linkedUsers: c29614_0.linked_users, users: c29614_0.users }; Dispatcher.dispatch({ type: "FAMILY_CENTER_LINKED_USERS_FETCH_SUCCESS", ...c29614_1 }); return c29614_1; }, getConnectionPrerequisites: async (teen_id, link_code) => (await HTTP.get({ url: Endpoints.FAMILY_CENTER_CONNECTION_PREREQUISITES, query: { teen_id, link_code }, rejectWithError: true })).body, setPendingConnection: (a0, a1) => { Dispatcher.dispatch({ type: "FAMILY_CENTER_PENDING_CONNECTION_SET", teenId: a0, linkCode: a1 }); }, clearPendingConnection: () => { Dispatcher.dispatch({ type: "FAMILY_CENTER_PENDING_CONNECTION_CLEAR" }); }, requestLink: async (recipient_id, code) => { let c25610_1; c25610_1 = void 0; let c29615_0 = (await HTTP.post({ url: Endpoints.FAMILY_CENTER_LINKED_USERS, body: { recipient_id, code }, rejectWithError: rejectWithMigratedError() })).body; let c29615_1 = { linkedUsers: c29615_0.linked_users, users: c29615_0.users }; Dispatcher.dispatch({ type: "FAMILY_CENTER_REQUEST_LINK_SUCCESS", ...c29615_1 }); return c29615_1; }, fetchTeenActivity: async (c15182_0) => { let c25611_9; c25611_9 = void 0; Dispatcher.dispatch({ type: "FAMILY_CENTER_FETCH_START" }); let c29616_0 = (await HTTP.get({ url: Endpoints.FAMILY_CENTER_TEEN_ACTIVITY(c15182_0), rejectWithError: rejectWithMigratedError() })).body; let c29616_1 = c29616_0.teen_audit_log; const top_user_activities4 = c29616_1.top_user_activities; let top_user_activities2 = top_user_activities4; if (top_user_activities4 == null) { top_user_activities2 = []; } const top_guild_activities4 = c29616_1.top_guild_activities; let top_guild_activities2 = top_guild_activities4; if (top_guild_activities4 == null) { top_guild_activities2 = []; } const r94 = c29616_1 == null ? void 0 : c29616_1.total_spend?.amount; let amount2 = r94; if (r94 == null) { amount2 = null; } const r102 = c29616_1 == null ? void 0 : c29616_1.total_spend?.currency; let currency2 = r102; if (r102 == null) { currency2 = null; } const spending_limit3 = c29616_0.spending_limit; let spending_limit2 = spending_limit3; if (spending_limit3 == null) { spending_limit2 = null; } const monthly_purchases3 = c29616_0.monthly_purchases; let monthly_purchases2 = monthly_purchases3; if (monthly_purchases3 == null) { monthly_purchases2 = null; } const invoices4 = c29616_1?.invoices; let invoices2 = invoices4; if (invoices4 == null) { invoices2 = []; } const gifts4 = c29616_1?.gifts; let gifts2 = gifts4; if (gifts4 == null) { gifts2 = []; } let c29616_2 = { teenId: c29616_1.teen_user_id, rangeStartId: c29616_1.range_start_id, totals: c29616_1.totals, actions: c29616_1.actions, users: c29616_1.users, guilds: c29616_1.guilds, topUserActivities: top_user_activities2, topGuildActivities: top_guild_activities2, totalSpendAmount: amount2, totalSpendCurrency: currency2, spendingLimit: spending_limit2, monthlyPurchases: monthly_purchases2, invoices: invoices2, gifts: gifts2 }; if (c29616_2.invoices && c29616_2.invoices.length > 0) { await (0, maybeFetchCollectiblesForInvoices)(c29616_2.invoices); } if (c29616_2.gifts && c29616_2.gifts.length > 0) { await (0, maybeFetchCollectiblesForGifts)(c29616_2.gifts); } Dispatcher.dispatch({ type: "FAMILY_CENTER_TEEN_ACTIVITY_FETCH_SUCCESS", familyCenterTeenActivity: c29616_2 }); if (c29616_0.restricted_schedule != null) { Dispatcher.dispatch({ type: "USER_RESTRICTED_SCHEDULE_UPDATE", userId: c15182_0, restrictedSchedule: c29616_0.restricted_schedule }); } return c29616_2; }, fetchMoreTeenActivity: async (c15183_0, c15183_1, c15183_2, c15183_3) => { let c25612_7; c25612_7 = void 0; let c29617_0 = (await HTTP.get({ url: Endpoints.FAMILY_CENTER_TEEN_ACTIVITY_MORE(c15183_0, c15183_1, c15183_2, c15183_3), rejectWithError: rejectWithMigratedError() })).body.teen_audit_log; const top_user_activities4 = c29617_0.top_user_activities; let top_user_activities3 = top_user_activities4; if (top_user_activities4 == null) { top_user_activities3 = []; } const top_guild_activities4 = c29617_0.top_guild_activities; let top_guild_activities3 = top_guild_activities4; if (top_guild_activities4 == null) { top_guild_activities3 = []; } const r86 = c29617_0 == null ? void 0 : c29617_0.total_spend?.amount; let amount3 = r86; if (r86 == null) { amount3 = null; } const r94 = c29617_0 == null ? void 0 : c29617_0.total_spend?.currency; let currency3 = r94; if (r94 == null) { currency3 = null; } const invoices4 = c29617_0?.invoices; let invoices3 = invoices4; if (invoices4 == null) { invoices3 = []; } const gifts4 = c29617_0?.gifts; let gifts3 = gifts4; if (gifts4 == null) { gifts3 = []; } let c29617_1 = { teenId: c29617_0.teen_user_id, rangeStartId: c29617_0.range_start_id, actions: c29617_0.actions, users: c29617_0.users, guilds: c29617_0.guilds, topUserActivities: top_user_activities3, topGuildActivities: top_guild_activities3, totalSpendAmount: amount3, totalSpendCurrency: currency3, invoices: invoices3, gifts: gifts3 }; AnalyticsUtils.track(AnalyticEvents.FAMILY_CENTER_ACTION, { action: FamilyCenterAction.LoadMore, selected_teen_id: c15183_0, action_display_type: c15183_1 }); Dispatcher.dispatch({ type: "FAMILY_CENTER_TEEN_ACTIVITY_MORE_FETCH_SUCCESS", familyCenterTeenActivity: c29617_1 }); return c29617_0; }, selectTab: (a0) => { Dispatcher.dispatch({ type: "FAMILY_CENTER_HANDLE_TAB_SELECT", tab: a0 }); }, fetchTeenSettingsAndConsents: (a0) => { const userId = a0; return HTTP.get({ url: Endpoints.FAMILY_CENTER_TEEN_SETTINGS_AND_CONSENTS(a0), rejectWithError: rejectWithMigratedError() }).then(({ body }) => { Dispatcher.dispatch({ type: "FAMILY_CENTER_TEEN_SETTINGS_AND_CONSENTS_FETCH_SUCCESS", userId, settings: body.settings, consents: body.consents }); }); }, updateTeenSettings: async (c15185_0, c15185_1, c15185_2) => { let c25613_1; let c29618_0; L15: { c25613_1 = void 0; c29618_0 = void 0; const protoFieldClass = getProtoFieldClass(PreloadedUserSettings, c15185_1); const settings = FamilyCenterControlledSettingsStore.getSettings(c15185_0); const modifiedProto = createModifiedProto(settings == null ? void 0 : settings[c15185_1], c15185_2, protoFieldClass, PreloadedUserSettings, c15185_1); if (modifiedProto != null) { c29618_0 = (await HTTP.patch({ url: Endpoints.FAMILY_CENTER_TEEN_SETTINGS(c15185_0), body: { settings: protoToB64(PreloadedUserSettings, modifiedProto) }, rejectWithError: rejectWithMigratedError() })).body.settings; Dispatcher.dispatch({ type: "FAMILY_CENTER_TEEN_UPDATE_SETTINGS_SUCCESS", userId: c15185_0, settings: c29618_0 }); break L15; } return void 0; } }, updateTeenConsents: (a0, a1, a2) => { const userId2 = a0; return HTTP.patch({ url: Endpoints.FAMILY_CENTER_TEEN_CONSENTS(a0), body: { grant: a1, revoke: a2 }, rejectWithError: rejectWithMigratedError() }).then((result) => { Dispatcher.dispatch({ type: "FAMILY_CENTER_TEEN_CONSENTS_UPDATE_SUCCESS", userId: userId2, consents: result.body }); }); } }; export default r32; export async function updateLinkForUserId(linked_user_id, link_status) { await HTTP.patch({ url: Endpoints.FAMILY_CENTER_LINKED_USERS, body: { linked_user_id, link_status }, rejectWithError: rejectWithMigratedError() }).then(({ body }) => { Dispatcher.dispatch({ type: "FAMILY_CENTER_REQUEST_LINK_UPDATE_SUCCESS", linkedUsers: body }); return body; }); } export async function removeLinkForUserId(linked_user_id2) { const deletedUserId = linked_user_id2; await HTTP.del({ url: Endpoints.FAMILY_CENTER_LINKED_USERS, body: { linked_user_id: linked_user_id2 }, rejectWithError: rejectWithMigratedError() }).then(({ body }) => { Dispatcher.dispatch({ type: "FAMILY_CENTER_REQUEST_LINK_REMOVE_SUCCESS", linkedUsers: body, deletedUserId }); return body; }); } export async function getLinkCodeForCurrentUser() { await HTTP.get({ url: Endpoints.FAMILY_CENTER_LINK_CODE, rejectWithError: rejectWithMigratedError() }).then(({ body }) => { const link_code2 = body.link_code; Dispatcher.dispatch({ type: "FAMILY_CENTER_LINK_CODE_FETCH_SUCCESS", linkCode: link_code2, expiresAt: body.expires_at }); return link_code2; }); } export async function shareIarWithParents() { await HTTP.post({ url: Endpoints.FAMILY_CENTER_SHARE_IAR_WITH_PARENTS, rejectWithError: true }); }