171 lines
7.8 KiB
TypeScript
171 lines
7.8 KiB
TypeScript
// Metro module 8321 (f8322).
|
|
import { useMemo, useState, useEffect } from "react";
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import PermissionStore from "../../stores/PermissionStore";
|
|
import GuildScheduledEventStore, { StaticGuildEventIndexes, isGuildScheduledEventActive } from "./GuildScheduledEventStore";
|
|
import UpcomingEventNoticesStore from "./UpcomingEventNoticesStore";
|
|
import { GuildScheduledEventEntityTypes, GuildScheduledEventStatus } from "./GuildScheduledEventsConstants";
|
|
import { Permissions, GuildFeatures } from "../../Constants";
|
|
import Durations from "../../utils/Durations";
|
|
import { useStateFromStoresArray, useStateFromStores, useStateFromStoresObject } from "../../_bundle/Module589";
|
|
import { getNextRecurrenceIdInEvent, getEventTimeData } from "./utils/ScheduleUtils";
|
|
import { getNextShownUpcomingEventNoticeType } from "./GuildScheduledEventUtils";
|
|
import { getEventSchedule } from "./useEventSchedule";
|
|
function $mk80422($env) {
|
|
return () => {
|
|
const r0 = $env.$parent;
|
|
return r0[9].getGuildScheduledEventsByIndex(r0[8].GUILD_EVENT_UPCOMING($env[0])).filter($mk105831(r0));
|
|
};
|
|
}
|
|
function $mk105831($env) {
|
|
return (a0) => {
|
|
const r1 = $env;
|
|
if (a0.entity_type !== r1[11].NONE && a0.status === r1[12].SCHEDULED) {
|
|
if (a0.channel_id == null) {
|
|
return true;
|
|
}
|
|
return r1[6].can(r1[14].VIEW_CHANNEL, r1[4].getChannel(a0.channel_id));
|
|
}
|
|
return false;
|
|
};
|
|
}
|
|
let env5307 = {};
|
|
const c5307_15 = [];
|
|
const c5307_16 = 15 * Durations.Millis.MINUTE;
|
|
export default function useGuildEvents(a0, a1) {
|
|
return useStateFromStoresArray([GuildStore, GuildScheduledEventStore, PermissionStore, ChannelStore], () => {
|
|
let r16;
|
|
const guild = GuildStore.getGuild(a0);
|
|
if (guild == null) {
|
|
r16 = c5307_15;
|
|
} else {
|
|
let r11 = a1;
|
|
if (r11 == null) {
|
|
r11 = StaticGuildEventIndexes.GUILD_EVENT_UPCOMING(guild.id);
|
|
}
|
|
r16 = GuildScheduledEventStore.getGuildScheduledEventsByIndex(r11).filter(({ channel_id }) => {
|
|
if (channel_id == null) {
|
|
return true;
|
|
}
|
|
return PermissionStore.can(Permissions.VIEW_CHANNEL, ChannelStore.getChannel(channel_id));
|
|
});
|
|
}
|
|
return r16;
|
|
}, [a1, a0]);
|
|
};
|
|
export function useActiveEvent(a0) {
|
|
return useStateFromStores([GuildScheduledEventStore, ChannelStore, PermissionStore], () => {
|
|
const channel = ChannelStore.getChannel(a0);
|
|
if (PermissionStore.can(Permissions.VIEW_CHANNEL, channel)) {
|
|
if (channel?.guild_id == null) {
|
|
return null;
|
|
}
|
|
const guildScheduledEventsByIndex = GuildScheduledEventStore.getGuildScheduledEventsByIndex(StaticGuildEventIndexes.CHANNEL_EVENT_ACTIVE(a0));
|
|
return guildScheduledEventsByIndex.length > 0 ? guildScheduledEventsByIndex[0] : null;
|
|
}
|
|
return null;
|
|
}, [a0]);
|
|
}
|
|
export function useActiveEventsByChannel(a0) {
|
|
const stateFromStoresArray = useStateFromStoresArray([GuildScheduledEventStore], () => GuildScheduledEventStore.getGuildScheduledEventsForGuild(a0), [a0]);
|
|
return useMemo(() => {
|
|
const map = new Map();
|
|
let c26187_0 = map;
|
|
stateFromStoresArray.forEach((item) => {
|
|
const channel_id = item.channel_id;
|
|
if (channel_id != null) {
|
|
c26187_0.set(channel_id, item);
|
|
}
|
|
});
|
|
return map;
|
|
}, [stateFromStoresArray]);
|
|
}
|
|
export function useGuildUpcomingEvents(a0) {
|
|
let env16494;
|
|
const r1 = env16494 = {
|
|
$parent: env5307
|
|
};
|
|
env16494[0] = a0;
|
|
return useStateFromStoresArray([GuildScheduledEventStore, ChannelStore, PermissionStore], $mk80422(r1), [a0]);
|
|
}
|
|
export function useGuildUpcomingEventsNotice(a0) {
|
|
let env16499;
|
|
const r11 = env16499 = {
|
|
$parent: env5307
|
|
};
|
|
env16499[0] = a0;
|
|
const stateFromStoresArray2 = useStateFromStoresArray([GuildScheduledEventStore, ChannelStore, PermissionStore], $mk80422(r11), [a0]);
|
|
const stateFromStoresObject = useStateFromStoresObject([UpcomingEventNoticesStore], () => UpcomingEventNoticesStore.getAllEventDismissals());
|
|
const stateFromStoresObject2 = useStateFromStoresObject([UpcomingEventNoticesStore], () => UpcomingEventNoticesStore.getAllUpcomingNoticeSeenTimes());
|
|
const stateFromStoresObject3 = useStateFromStoresObject([GuildScheduledEventStore], () => stateFromStoresArray2 == null ? {} : stateFromStoresArray2.reduce((acc, item) => {
|
|
const nextRecurrenceIdInEvent = getNextRecurrenceIdInEvent(item);
|
|
const r12 = {
|
|
...acc
|
|
};
|
|
r12[item.id] = GuildScheduledEventStore.isInterestedInEventRecurrence(item.id, nextRecurrenceIdInEvent);
|
|
return r12;
|
|
}, {}), [stateFromStoresArray2]);
|
|
const stateFromStores2 = useStateFromStores([GuildStore], () => GuildStore.getGuild(a0));
|
|
const r55 = stateFromStores2 != null && !stateFromStores2.features.has(GuildFeatures.COMMUNITY) && stateFromStores2.features.has(GuildFeatures.INTERNAL_EMPLOYEE_ONLY);
|
|
if (stateFromStoresArray2 != null && stateFromStoresObject3 != null && r55) {
|
|
const length = stateFromStoresArray2.length;
|
|
let r0 = 0;
|
|
if (0 < length) {
|
|
do {
|
|
const upcomingEvent = stateFromStoresArray2[r0];
|
|
const r68 = stateFromStoresObject[upcomingEvent.id];
|
|
const r70 = stateFromStoresObject2[upcomingEvent.id];
|
|
let r72 = stateFromStoresObject3[upcomingEvent.id];
|
|
const r1 = r0;
|
|
if (r72 == null) {
|
|
r72 = false;
|
|
}
|
|
const nextShownUpcomingEventNoticeType = getNextShownUpcomingEventNoticeType(upcomingEvent, r68, r70, r72);
|
|
if (nextShownUpcomingEventNoticeType != null) {
|
|
return {
|
|
upcomingEvent,
|
|
noticeType: nextShownUpcomingEventNoticeType
|
|
};
|
|
}
|
|
r0 = r1 + 1;
|
|
} while (r0 < stateFromStoresArray2.length);
|
|
}
|
|
}
|
|
}
|
|
export function useGuildActiveEvent(a0) {
|
|
return useStateFromStores([GuildScheduledEventStore, ChannelStore, PermissionStore], () => GuildScheduledEventStore.getGuildScheduledEventsByIndex(StaticGuildEventIndexes.GUILD_EVENT_ACTIVE(a0)).find((item) => {
|
|
if (item.entity_type !== GuildScheduledEventEntityTypes.NONE && (0, isGuildScheduledEventActive)(item)) {
|
|
if (item.channel_id == null) {
|
|
return true;
|
|
}
|
|
return PermissionStore.can(Permissions.VIEW_CHANNEL, ChannelStore.getChannel(item.channel_id));
|
|
}
|
|
return false;
|
|
}), [a0]);
|
|
}
|
|
export function useGuildChannelScheduledEvents(a0) {
|
|
return useStateFromStores([GuildScheduledEventStore], () => GuildScheduledEventStore.getGuildScheduledEventsByIndex(StaticGuildEventIndexes.CHANNEL_EVENT_UPCOMING(a0)), [a0]);
|
|
}
|
|
export function useFirstActiveEventChannel(a0) {
|
|
return useStateFromStores([ChannelStore, GuildScheduledEventStore], () => ChannelStore.getChannel(GuildScheduledEventStore.getGuildScheduledEventsByIndex(StaticGuildEventIndexes.GUILD_EVENT_ACTIVE(a0)).find((item) => ChannelStore.getChannel(item.channel_id) != null)?.channel_id), [a0]);
|
|
}
|
|
export function useImminentUpcomingGuildEvents(a0) {
|
|
let stateFromStores;
|
|
const [state, setState] = useState(() => Date.now());
|
|
useEffect(() => {
|
|
let c26188_0 = setInterval(() => {
|
|
setState(Date.now());
|
|
}, c5307_16);
|
|
return () => clearInterval(c26188_0);
|
|
}, []);
|
|
stateFromStores = useStateFromStores([GuildScheduledEventStore], () => a0 == null ? [] : GuildScheduledEventStore.getGuildScheduledEventsByIndex(StaticGuildEventIndexes.CHANNEL_EVENT_UPCOMING(a0)), [a0, state]);
|
|
return useMemo(() => stateFromStores.filter((stateFromStore) => {
|
|
const eventSchedule = getEventSchedule(stateFromStore);
|
|
const { startTime, endTime } = eventSchedule;
|
|
const eventTimeData = getEventTimeData(startTime.toISOString(), endTime == null ? void 0 : endTime.toISOString());
|
|
const { withinStartWindow, diffMinutes } = eventTimeData;
|
|
return stateFromStore.status !== GuildScheduledEventStatus.ACTIVE && withinStartWindow && diffMinutes < 15;
|
|
}), [stateFromStores]);
|
|
}
|