// Metro module 12759 (f12760). import ChannelStore from "../../stores/ChannelStore"; import SelectedGuildStore from "../../stores/SelectedGuildStore"; import { isGuildHomeChannel } from "../channel/ChannelConstants"; import SnowflakeUtils from "../../utils/SnowflakeUtils"; import Module12 from "../../_bundle/Module12"; import Module589 from "../../_bundle/Module589"; import Dispatcher from "../../Dispatcher"; let c8791_5, c8791_6, c8791_7, c8791_8, c8791_9; const truncateOldMessageData = function truncateOldMessageData(a0) { const r10 = c8791_7[a0]; if (r10 != null) { let c20198_0 = SnowflakeUtils.fromTimestamp(Date.now() - c8791_5); const r23 = Module12.findIndex(r10, (a0) => SnowflakeUtils.compare(a0.id, c20198_0) > 0); if (r23 === -1) { c8791_7[a0] = []; } else { c8791_7[a0] = Module12.slice(r10, Math.max(r23, r10.length - 26)); } c8791_8[a0] = Date.now(); } }; const handleChannelDelete = function handleChannelDelete({ channel }) { delete c8791_7[channel.id]; delete c8791_8[channel.id]; }; c8791_5 = 900000; c8791_6 = {}; c8791_7 = {}; c8791_8 = {}; c8791_9 = {}; class ActiveChannelsStore extends Module589.Store { static displayName = "ActiveChannelsStore"; initialize() { this.waitFor(ChannelStore, SelectedGuildStore); } getActiveChannelsFetchStatus(a0) { return c8791_9[a0]; } getActiveChannelIds(a0) { return c8791_6[a0]; } getChannelMessageData(a0) { return c8791_7[a0]; } shouldFetch(a0) { return c8791_6[a0] == null && !c8791_9[a0]?.loading; } } const activeChannelsStore = new ActiveChannelsStore(Dispatcher, { CHANNEL_SELECT: function handleRefreshChannels({ channelId, guildId: guildId2 }) { if (isGuildHomeChannel(channelId) && guildId2 != null) { const r9 = c8791_6[guildId2]; if (r9 == null) { return false; } r9.forEach((item) => { truncateOldMessageData(item); if (c8791_7[item]?.length === 0) { delete c8791_7[item]; } }); c8791_6[guildId2] = new Set(Module12.chain(Array.from(r9)).filter((item) => item in c8791_7).sortBy((item) => { let r7 = c8791_7[item]?.length; if (r7 == null) { r7 = 0; } return -r7; }).value()); return void 0; } return false; }, MESSAGE_CREATE: function handleMessageCreate({ channelId, message, optimistic, isPushNotification }) { if (!optimistic && !isPushNotification) { const channel = ChannelStore.getChannel(channelId); if (channel == null) { return false; } const guild_id = channel.guild_id; let r2 = guild_id != null; if (r2) { let r3 = c8791_6[guild_id] != null; if (r3) { const id = message.id; const id2 = message.author?.id; c8791_6[guild_id].add(channelId); const r28 = c8791_8[channelId]; if (r28 == null || r28 + 300000 > Date.now()) { truncateOldMessageData(channelId); } if (c8791_7[channelId] == null) { c8791_7[channelId] = []; } c8791_7[channelId].push({ id, userId: id2 }); r3 = void 0; } r2 = r3; } return r2; } return false; }, GUILD_DELETE: function handleGuildDelete(a0) { delete c8791_6[a0.guild.id]; }, CHANNEL_DELETE: handleChannelDelete, THREAD_DELETE: handleChannelDelete, ACTIVE_CHANNELS_FETCH_START: function handleActiveChannelsFetchStart(a0) { c8791_9[a0.guildId] = { loading: true, error: null, fetchedAt: Date.now() }; }, ACTIVE_CHANNELS_FETCH_SUCCESS: function handleActiveChannelsFetchSuccess({ guildId, channels }) { c8791_9[guildId] = { loading: false, error: null, fetchedAt: Date.now() }; c8791_6[guildId] = new Set(); channels.forEach((channel) => { const channel_id = channel.channel_id; channel.messages.forEach(({ message_id, user_id }) => { c8791_6[guildId].add(channel_id); const r18 = c8791_8[channel_id]; if (r18 == null || r18 + 300000 > Date.now()) { truncateOldMessageData(channel_id); } if (c8791_7[channel_id] == null) { c8791_7[channel_id] = []; } c8791_7[channel_id].push({ id: message_id, userId: user_id }); }); }); }, ACTIVE_CHANNELS_FETCH_FAILURE: function handleActiveChannelsFetchFailure(a0) { c8791_9[a0.guildId] = { loading: false, error: a0.error, fetchedAt: null }; }, CONNECTION_OPEN: function handleConnectionOpen() { const guildId2 = SelectedGuildStore.getGuildId(); if (guildId2 != null) { const r8 = c8791_9[guildId2]; const r6 = c8791_6[guildId2]; const r10 = Array; let r21 = r6; if (r21 == null) { r21 = []; } const r25 = r10.from(r21).reduce((acc, item) => { let r2 = c8791_7[item]; if (r2 == null) { r2 = []; } acc[item] = r2; return acc; }, {}); c8791_6 = {}; c8791_7 = {}; c8791_8 = {}; c8791_9 = {}; const r32 = Date.now(); let r33 = r8?.fetchedAt; if (r33 == null) { r33 = 0; } if (r32 - r33 < c8791_5) { const r36 = {}; r36[guildId2] = r8; c8791_9 = r36; const r37 = {}; r37[guildId2] = r6; c8791_6 = r37; c8791_7 = { ...r25 }; } } else { c8791_6 = {}; c8791_7 = {}; c8791_8 = {}; c8791_9 = {}; } } }); export default activeChannelsStore; export const MAX_STORED_MESSAGES = 26;