Files
discord-decomp/modules/premium/powerups/hooks/useGuildPowerupsNotifications.tsx
T
2026-11-01 12:12:55 +02:00

445 lines
20 KiB
TypeScript

// Metro module 11583 (f11584).
import { useMemo, useEffect } from "react";
import GuildStore from "../../../../stores/GuildStore";
import GameServerStore from "../../game_server/GameServerStore";
import GuildPowerupsNotificationStore from "../GuildPowerupsNotificationStore";
import GuildPowerupsStore from "../GuildPowerupsStore";
import { GUILD_POWERUP_NEW_PERK_GROUPS, POWERUPS_INCLUDED_IN_LEVEL, BOOSTING_TIER_TO_LEVEL_UNLOCKED_DC, BOOSTING_TIER_TO_LEVEL_SKU_ID, GuildPowerupNewPerkMarketingVersion, NEW_PERK_MARKETING_VERSION_TO_POWERUP_SKU_ID_SET } from "../constants/GuildPowerupsConstants";
import { BoostedGuildTiers, GuildFeatures } from "../../../../Constants";
import { ContentDismissActionType } from "../../../dismissible_content/DismissibleContentConstants";
import { ReverseOrderedTiers } from "../../../../utils/GuildBoostingUtils";
import * as _GuildDismissibleContentUtils from "../../../guild_dismissible_content/GuildDismissibleContentUtils";
import { markContentAsDismissed } from "../../../guild_dismissible_content/GuildDismissibleContentUtils";
import { GuildPowerupNotificationPopoutType, GuildPowerupNotificationIndicatorType } from "../constants/GuildPowerupsNotification";
import { GUILD_POWERUP_GUILD_THEME_SKU_ID } from "../../../../_bundle/Module4080";
import { isGuildPowerupRollbackEnabled } from "./useGuildPowerupRollbackEnabled";
import { isNotNullish } from "../../../../utils/GlobalUtils";
import { DismissibleGuildContent, DismissibleContent } from "../../../../_bundle/Module1358";
import { getGameServerEnabled } from "../../game_server/GameServerExperiment";
import useGuildPowerupsBoostCount from "./useGuildPowerupsBoostCount";
import useGuildPowerupRollbackNotificationConfig from "./useGuildPowerupRollbackNotificationConfig";
import { useIsSingleUseGuildDismissibleContentDismissed } from "../../../dismissible_content/DismissibleContentUtils";
import { useStateFromStores } from "../../../../_bundle/defaultAreStatesEqual";
import { getExpiringGuildEntitlements } from "../utils/getExpiringGuildEntitlements";
import { usePerksCoachmarkDCF, useNewPerkAvailableCoachmarkDCF, useBoostToUnlockCoachmarkDCF, useExpiringPowerupCoachmarkDCF, useNewGamesCoachmarkDC, useGameServerPricingCoachmarkDCF, useGuildPowerupNotificationDCF } from "./GuildPowerupsNotificationsDCF.native";
import { useServerThemeEnabled } from "../experiments/ServerThemeExperiment";
import { useServerThemeUserEnabled } from "../experiments/ServerThemeUserExperiment";
import useGuildPowerupNewPerkMarketingVersion from "./useGuildPowerupNewPerkMarketingVersion";
import useBoostToUnlockFeaturedPowerup from "./useBoostToUnlockFeaturedPowerup";
import useCanPurchaseBoosts from "./useCanPurchaseBoosts";
import useFeaturedExpiringPowerup from "./useFeaturedExpiringPowerup";
import { useIsNewGamesCoachmarkEnabled } from "../../game_server/experiments/NewGamesCoachmarkExperiment";
import { useIsGameServerPricingEnabled } from "../../game_server/experiments/GameServerPricingExperiment";
import { useAutoDismissGuildPowerupsNewBadge } from "./useGuildPowerupsNewBadge";
import { guildPowerupsAckNotification } from "../GuildPowerupsActionCreators";
import { HermesBuiltin } from "../../../../_hermes/prelude";
function $mk87671($env) {
return (a0) => {
const r2 = $env.$parent;
const r5 = r2[9][a0];
const r6 = r5 != null ? $env[1].unlockedPowerups[r5] : void 0;
return r6 != null && r6.user_id !== r2[11];
};
}
function $mk87672($env) {
return (a0) => {
const r2 = $env;
const r3 = $env.$parent;
(0, r3[0])(r3[2][10]).markContentAsDismissed(r2[2], r2[0], true, a0);
};
}
function $mk87676($env) {
return (a0) => {
const r2 = $env.$parent;
const r3 = r2[0];
const r12 = r2[2];
r3(r12[10]).markContentAsDismissed(r3(r12[15]).DismissibleGuildContent.GAME_SERVER_HOSTING_GUILD_ELIGIBLE_COACHMARK, $env[0], true, a0);
};
}
function $mk87683($env) {
return () => $env.$parent[7].getNotificationStateForGuild($env[0]);
}
function $mk87684($env) {
return () => $env.$parent[8].getStateForGuild($env[0]);
}
let useGuildPowerupsNotificationIndicator, useGuildPowerupsChannelListPopout;
let env7902 = {};
export function maybeGetPerkPurchaseablePopoutDCF(a0, c19004_1, c19004_2, c19004_3) {
let c19004_0 = a0;
let r18 = GuildStore.getGuild(a0)?.premiumTier;
if (r18 == null) {
r18 = BoostedGuildTiers.NONE;
}
const NONE = r18;
const powerups = Array.from(GUILD_POWERUP_NEW_PERK_GROUPS.values()).flatMap((a0) => !(a0.length <= 0) && !a0.some((item) => {
if (c19004_1.unlockedPowerups[item] != null) {
return true;
}
const r9 = POWERUPS_INCLUDED_IN_LEVEL[item];
return r9 != null && NONE >= r9;
}) ? a0.map((item) => {
if (item === GUILD_POWERUP_GUILD_THEME_SKU_ID && !c19004_3) {
return null;
}
const r5 = c19004_1.allPowerups[item];
return r5 == null ? null : c19004_2 < r5.cost ? null : r5.dependencies.every((dependency) => c19004_1.unlockedPowerups[dependency] != null) ? isGuildPowerupRollbackEnabled(c19004_0, r5, "maybeGetPerkPurchaseablePopoutDCF") ? null : r5 : null;
}) : []).filter(isNotNullish);
if (powerups.length !== 0) {
return powerups.length === 1 && !_GuildDismissibleContentUtils.isContentDismissed(DismissibleGuildContent.GUILD_POWERUP_SINGLE_SKU_PURCHASE_COACHMARK, a0) ? {
type: GuildPowerupNotificationPopoutType.PERKS_PURCHASABLE,
powerups,
markAsDismissed: (a0) => {
markContentAsDismissed(DismissibleGuildContent.GUILD_POWERUP_SINGLE_SKU_PURCHASE_COACHMARK, c19004_0, true, a0);
}
} : powerups.length > 1 ? _GuildDismissibleContentUtils.isContentDismissed(DismissibleGuildContent.GUILD_POWERUP_CHOICE_SKU_PURCHASE_COACHMARK, a0) ? void 0 : {
type: GuildPowerupNotificationPopoutType.PERKS_PURCHASABLE,
powerups,
markAsDismissed: (a0) => {
markContentAsDismissed(DismissibleGuildContent.GUILD_POWERUP_CHOICE_SKU_PURCHASE_COACHMARK, c19004_0, true, a0);
}
} : void 0;
}
}
useGuildPowerupsNotificationIndicator = function useGuildPowerupsNotificationIndicator(a0, a1, a2) {
const available = useGuildPowerupsBoostCount(a0).available;
const guildPowerupRollbackNotificationConfig = useGuildPowerupRollbackNotificationConfig(a0, "useGuildPowerupsNotificationIndicator");
const isSingleUseGuildDismissibleContentDismissed = useIsSingleUseGuildDismissibleContentDismissed(guildPowerupRollbackNotificationConfig != null ? guildPowerupRollbackNotificationConfig.dismissibleContent : null, a0);
const r25 = guildPowerupRollbackNotificationConfig != null && !isSingleUseGuildDismissibleContentDismissed;
let c19006_4 = r25;
const stateFromStores = useStateFromStores([GameServerStore], () => GameServerStore.getStateForGuild(a0));
return useMemo(() => {
let r56;
if (a1 == null) {
return {
indicator: void 0,
showUnread: false
};
}
const r17 = Object.values(a1.unlockedPowerups);
const r23 = [];
const r0 = HermesBuiltin.arraySpread(r23, r17, 0);
const r14 = Object;
let r25 = stateFromStores?.entitlements;
if (r25 == null) {
r25 = {};
}
HermesBuiltin.arraySpread(r23, r14.values(r25), r0);
const expiringGuildEntitlements = getExpiringGuildEntitlements(r23);
let r33 = a2?.lastSeenWarningNotification;
if (r33 == null) {
r33 = Date.now();
}
const time = new Date(expiringGuildEntitlements[expiringGuildEntitlements.length - 1]?.ends_at).getTime();
let r50 = a2?.lastBoostCount;
if (r50 == null) {
r50 = 0;
}
const r52 = expiringGuildEntitlements.length > 0 && r33 < time;
L25: {
const count = available - r50;
if (!r52 && !c19006_4) {
if (available !== r50 && count > 0) {
r56 = {
indicator: {
type: GuildPowerupNotificationIndicatorType.UNREAD,
count
},
showUnread: true
};
break L25;
}
r56 = {
indicator: void 0,
showUnread: false
};
} else {
r56 = {
indicator: {
type: GuildPowerupNotificationIndicatorType.WARNING
},
showUnread: true
};
}
}
return r56;
}, [available, a2?.lastBoostCount, a2?.lastSeenWarningNotification, a1, r25, stateFromStores?.entitlements]);
};
useGuildPowerupsChannelListPopout = function useGuildPowerupsChannelListPopout(a0, a1) {
let stateFromStores3, serverThemeUserEnabled, c19007_8, c19007_10, powerup, c19007_13, featuredExpiringPowerup, c19007_16, c19007_18, c19007_20, memo, c19007_22, c19007_23;
let c19007_0 = a0;
const [r14, markAsDismissed2] = usePerksCoachmarkDCF(a1 != null);
const r4 = r14 === DismissibleContent.GUILD_POWERUP_PERKS_COACHMARK;
let c19007_3 = r4;
const available2 = useGuildPowerupsBoostCount(a0).available;
const stateFromStores2 = useStateFromStores([GuildStore], () => {
const guild = GuildStore.getGuild(c19007_0);
let r8 = guild == null ? void 0 : guild.features.has(GuildFeatures.GAME_SERVERS);
if (r8 == null) {
r8 = false;
}
return r8;
});
stateFromStores3 = useStateFromStores([GameServerStore], () => GameServerStore.getLowestGameCostForGuild(c19007_0));
let r22 = useServerThemeEnabled(a0, "useGuildPowerupsChannelListPopout");
const serverThemeUserEnabled2 = useServerThemeUserEnabled("useGuildPowerupsChannelListPopout");
if (r22) {
r22 = serverThemeUserEnabled2;
}
serverThemeUserEnabled = r22;
const guildPowerupNewPerkMarketingVersion = useGuildPowerupNewPerkMarketingVersion(a0, a1);
c19007_8 = guildPowerupNewPerkMarketingVersion;
let [r69, markAsDismissed3] = useNewPerkAvailableCoachmarkDCF(a1 != null && !r4, guildPowerupNewPerkMarketingVersion);
const r5 = r69 === DismissibleContent.GUILD_POWERUP_NEW_PERK_AVAILABLE_COACHMARK;
c19007_10 = r5;
powerup = useBoostToUnlockFeaturedPowerup(a0);
const canPurchaseBoosts = useCanPurchaseBoosts();
let [r85, markAsDismissed4] = useBoostToUnlockCoachmarkDCF(a1 != null && !r4 && !r5 && powerup != null && canPurchaseBoosts, a0);
const r6 = r85 === DismissibleContent.BOOST_TO_UNLOCK_COACHMARK;
c19007_13 = r6;
featuredExpiringPowerup = useFeaturedExpiringPowerup(a0);
let [r100, markAsDismissed5] = useExpiringPowerupCoachmarkDCF(a1 != null && !r4 && !r5 && !r6 && featuredExpiringPowerup != null, a0);
const r7 = r100 === DismissibleContent.EXPIRING_POWERUP_COACHMARK;
c19007_16 = r7;
const gameServerEnabled = getGameServerEnabled(a0, "useGuildPowerupsChannelListPopout");
const isNewGamesCoachmarkEnabled = useIsNewGamesCoachmarkEnabled("useGuildPowerupsChannelListPopout");
let [r117, markAsDismissed6] = useNewGamesCoachmarkDC(a1 != null && gameServerEnabled && isNewGamesCoachmarkEnabled);
const r8 = r117 === DismissibleContent.GAME_SERVER_NEW_GAMES_COACHMARK;
c19007_18 = r8;
const isGameServerPricingEnabled = useIsGameServerPricingEnabled(a0, "useGuildPowerupsChannelListPopout");
let [r133, markAsDismissed7] = useGameServerPricingCoachmarkDCF(a1 != null && !stateFromStores2 && gameServerEnabled && isGameServerPricingEnabled);
const r139 = r133 === DismissibleContent.GAME_SERVER_PRICING_CHANGE_COACHMARK;
c19007_20 = r139;
memo = useMemo(() => {
if (a1 != null && !c19007_3 && !c19007_10 && !c19007_18 && !c19007_20 && !c19007_13 && !c19007_16) {
let env27113;
const r6 = env7902;
const r7 = env27113 = {
$parent: r6
};
env27113[0] = c19007_0;
env27113[1] = a1;
const r28 = ReverseOrderedTiers.find($mk87671(r7));
const r2 = r28 != null;
let r29 = void 0;
if (r2) {
const r14 = BOOSTING_TIER_TO_LEVEL_UNLOCKED_DC[r28];
env27113[2] = r14;
const r31 = r14 != null;
r29 = void 0;
if (r31) {
const isContentDismissed = _GuildDismissibleContentUtils.isContentDismissed(r14, c19007_0);
r29 = void 0;
if (!isContentDismissed) {
const r36 = BOOSTING_TIER_TO_LEVEL_SKU_ID[r28];
const powerup2 = r36 != null ? a1.allPowerups[r36] : void 0;
r29 = powerup2 != null ? {
type: GuildPowerupNotificationPopoutType.LEVEL_REACHED,
powerup: powerup2,
markAsDismissed: $mk87672(r7)
} : void 0;
}
}
}
if (r29 != null) {
return r29;
}
const r49 = maybeGetPerkPurchaseablePopoutDCF(c19007_0, a1, available2, serverThemeUserEnabled);
if (r49 != null) {
return r49;
}
let env27114;
const r52 = env27114 = {
$parent: r6
};
env27114[0] = c19007_0;
const r58 = getGameServerEnabled(c19007_0, "maybeGetGameServerHostingGuildEligiblePopoutDCF") ? stateFromStores2 ? void 0 : stateFromStores3 != null ? available2 >= stateFromStores3 ? _GuildDismissibleContentUtils.isContentDismissed(DismissibleGuildContent.GAME_SERVER_HOSTING_GUILD_ELIGIBLE_COACHMARK, c19007_0) ? void 0 : {
type: GuildPowerupNotificationPopoutType.GAME_SERVER_HOSTING_GUILD_ELIGIBLE,
markAsDismissed: $mk87676(r52)
} : void 0 : void 0 : void 0;
return r58 ?? void 0;
}
}, [a0, a1, r4, r5, r8, r139, r6, r7, available2, stateFromStores2, stateFromStores3, serverThemeUserEnabled]);
const [r151, r152] = useGuildPowerupNotificationDCF(memo != null);
c19007_22 = r151;
c19007_23 = r152;
return useMemo(() => {
if (a1 != null) {
if (c19007_3) {
return {
type: GuildPowerupNotificationPopoutType.PERKS_AVAILABLE,
markAsDismissed: markAsDismissed2
};
}
if (c19007_10) {
if (c19007_8 === GuildPowerupNewPerkMarketingVersion.GAME_SERVER_HOSTING) {
return {
type: GuildPowerupNotificationPopoutType.GAME_SERVER_HOSTING_AVAILABLE,
markAsDismissed: markAsDismissed3
};
}
let c27115_0 = NEW_PERK_MARKETING_VERSION_TO_POWERUP_SKU_ID_SET[c19007_8];
const powerups = Object.values(a1.allPowerups).filter((item) => c27115_0.has(item.skuId));
if (powerups.length === 0) {
return void 0;
}
return {
powerups,
type: GuildPowerupNotificationPopoutType.NEW_PERK_AVAILABLE,
markAsDismissed: markAsDismissed3
};
}
return c19007_13 && powerup != null ? {
type: GuildPowerupNotificationPopoutType.BOOST_TO_UNLOCK,
powerup,
markAsDismissed: markAsDismissed4
} : c19007_16 && featuredExpiringPowerup != null ? {
type: GuildPowerupNotificationPopoutType.EXPIRING_PERK,
featuredExpiringPowerup,
markAsDismissed: markAsDismissed5
} : c19007_18 ? {
type: GuildPowerupNotificationPopoutType.GAME_SERVER_NEW_GAMES,
markAsDismissed: markAsDismissed6
} : c19007_20 ? {
type: GuildPowerupNotificationPopoutType.GAME_SERVER_PRICING_CHANGE,
markAsDismissed: markAsDismissed7
} : c19007_22 === DismissibleContent.GUILD_POWERUP_NOTIFICATION ? memo != null ? {
...memo,
markAsDismissed: (a0) => {
c19007_23(a0);
memo.markAsDismissed(a0);
}
} : void 0 : void 0;
}
}, [a1, r4, markAsDismissed2, memo, r151, r152, r5, markAsDismissed3, guildPowerupNewPerkMarketingVersion, r6, powerup, markAsDismissed4, r7, featuredExpiringPowerup, markAsDismissed5, r8, markAsDismissed6, r139, markAsDismissed7]);
};
export default function useGuildPowerupsNotifications(a0) {
let env19008;
const r2 = env19008 = {
$parent: env7902
};
env19008[0] = a0;
const stateFromStores5 = useStateFromStores([GuildPowerupsNotificationStore], $mk87683(r2), [a0]);
const stateFromStores6 = useStateFromStores([GuildPowerupsStore], $mk87684(r2));
const guildPowerupsNotificationIndicator = useGuildPowerupsNotificationIndicator(a0, stateFromStores6 == null ? void 0 : stateFromStores6, stateFromStores5);
const { indicator, showUnread } = guildPowerupsNotificationIndicator;
let r28 = stateFromStores6;
if (r28 == null) {
r28 = void 0;
}
L8: {
const popout = useGuildPowerupsChannelListPopout(a0, r28);
if (stateFromStores6 !== null) {
if (indicator == null && !showUnread && popout == null) {
break L8;
}
return {
indicator,
showUnread,
popout
};
}
}
};
export function maybeGetLevelUnlockedPopoutDCF(a0, a1) {
let env19003;
const r4 = env19003 = {
$parent: env7902
};
env19003[0] = a0;
env19003[1] = a1;
const r15 = ReverseOrderedTiers.find($mk87671(r4));
if (r15 != null) {
const r11 = BOOSTING_TIER_TO_LEVEL_UNLOCKED_DC[r15];
env19003[2] = r11;
if (r11 != null && !_GuildDismissibleContentUtils.isContentDismissed(r11, a0)) {
const r22 = BOOSTING_TIER_TO_LEVEL_SKU_ID[r15];
const powerup2 = r22 != null ? a1.allPowerups[r22] : void 0;
if (powerup2 != null) {
return {
type: GuildPowerupNotificationPopoutType.LEVEL_REACHED,
powerup: powerup2,
markAsDismissed: $mk87672(r4)
};
}
}
}
}
export function maybeGetGameServerHostingGuildEligiblePopoutDCF(a0, a1, a2, a3) {
let env19005;
const r3 = env19005 = {
$parent: env7902
};
env19005[0] = a0;
if (getGameServerEnabled(a0, "maybeGetGameServerHostingGuildEligiblePopoutDCF") && !a1 && a3 != null && a2 >= a3 && !_GuildDismissibleContentUtils.isContentDismissed(DismissibleGuildContent.GAME_SERVER_HOSTING_GUILD_ELIGIBLE_COACHMARK, a0)) {
return {
type: GuildPowerupNotificationPopoutType.GAME_SERVER_HOSTING_GUILD_ELIGIBLE,
markAsDismissed: $mk87676(r3)
};
}
}
export { useGuildPowerupsNotificationIndicator };
export { useGuildPowerupsChannelListPopout };
export function useAutoDismissGuildPowerupsNotifications(a0) {
let r37;
let c19009_2;
let env19010;
const stateFromStores4 = useStateFromStores([GuildPowerupsStore], () => GuildPowerupsStore.getStateForGuild(a0));
const r17 = env19010 = {
$parent: env7902
};
env19010[0] = a0;
const stateFromStores5 = useStateFromStores([GuildPowerupsNotificationStore], $mk87683(r17), [a0]);
const stateFromStores6 = useStateFromStores([GuildPowerupsStore], $mk87684(r17));
const guildPowerupsNotificationIndicator = useGuildPowerupsNotificationIndicator(a0, stateFromStores6 == null ? void 0 : stateFromStores6, stateFromStores5);
const { indicator, showUnread } = guildPowerupsNotificationIndicator;
let r35 = stateFromStores6;
if (r35 == null) {
r35 = void 0;
}
L9: {
const popout = useGuildPowerupsChannelListPopout(a0, r35);
r37 = void 0;
if (stateFromStores6 !== null) {
if (indicator == null && !showUnread) {
const r38 = popout != null;
r37 = void 0;
if (!r38) {
break L9;
}
}
r37 = {
indicator,
showUnread,
popout
};
}
}
c19009_2 = r37;
useAutoDismissGuildPowerupsNewBadge(a0);
useEffect(() => {
guildPowerupsAckNotification(a0);
}, [a0]);
useEffect(() => {
const set = new Set([GuildPowerupNotificationPopoutType.BOOST_TO_UNLOCK, GuildPowerupNotificationPopoutType.EXPIRING_PERK]);
if (!((c19009_2 == null ? void 0 : c19009_2.popout?.type) != null && set.has(c19009_2.popout.type)) && c19009_2 != null) {
const popout = c19009_2.popout;
if (popout != null) {
popout.markAsDismissed(ContentDismissActionType.AUTO_DISMISS);
}
}
}, [r37]);
useEffect(() => {
if (stateFromStores4 != null) {
ReverseOrderedTiers.forEach((reverseOrderedTier) => {
const r5 = BOOSTING_TIER_TO_LEVEL_SKU_ID[reverseOrderedTier];
if (r5 != null && stateFromStores4.unlockedPowerups[r5] != null) {
const r15 = BOOSTING_TIER_TO_LEVEL_UNLOCKED_DC[reverseOrderedTier];
if (r15 != null) {
markContentAsDismissed(r15, a0, false, ContentDismissActionType.AUTO_DISMISS);
}
}
});
}
}, [a0, stateFromStores4]);
}