// Metro module 5785 (f5786). import UserSettingsProtoStore from "../user_settings/UserSettingsProtoStore"; import AuthenticationStore from "../../stores/AuthenticationStore"; import ChannelStore from "../../stores/ChannelStore"; import GuildChannelStore, { GUILD_SELECTABLE_CHANNELS_KEY } from "../../stores/GuildChannelStore"; import GuildMemberStore from "../../stores/GuildMemberStore"; import GuildStore from "../../stores/GuildStore"; import ReadStateStore from "../../stores/ReadStateStore"; import UserGuildSettingsStore from "../../stores/UserGuildSettingsStore"; import { GuildFeatures } from "../../Constants"; import Durations from "../../utils/Durations"; import { SidebarType } from "../sidebar/SidebarActionTypes"; import Dispatcher from "../../Dispatcher"; import SnowflakeUtils from "../../utils/SnowflakeUtils"; import Module589 from "../../_bundle/Module589"; function $mk77042($env) { return () => { const r6 = $env.$parent; const r3 = r6[0]; const r1 = r6[2]; const r5 = r3(r1[12]); const r15 = $env[0]; return r5.ack(r15, { object: r6[12].ACK_RECENT_CHANNEL_NEW_CHANNEL_VIEWED, objectType: r6[13].ACK_AUTOMATIC }, true, true, (0, r6[1])(r1[13]).atPreviousMillisecond(r15)); }; } let initializeNewChannels, pruneNewChannels, c3601_15, c3601_16, c3601_17, c3601_18, c3601_22; let env3601 = {}; const guildHasCommunity = function guildHasCommunity(a0) { const guild = GuildStore.getGuild(a0); return (guild == null ? void 0 : guild.features.has(GuildFeatures.COMMUNITY)) === true; }; const seedCommunityBaseline = function seedCommunityBaseline() { c3601_18.clear(); for (const item of GuildStore.getGuildIds()) { if (guildHasCommunity(item)) { c3601_18.add(item); } } return false; }; initializeNewChannels = function initializeNewChannels(a0) { let time; if (c3601_16[a0] == null) { const r9 = GuildChannelStore.getChannels(a0)[GUILD_SELECTABLE_CHANNELS_KEY]; let r11 = void 0; const r10 = r9.map((item) => item.channel.id); const member = GuildMemberStore.getMember(a0, AuthenticationStore.getId()); if (member != null) { r11 = member.joinedAt; } if (r11 != null) { c3601_16[a0] = new Set(); time = new Date(r11).getTime(); if (r10.length !== 0) { c3601_16[a0] = new Set(r10.filter((item) => { const r10 = SnowflakeUtils.extractTimestamp(item); return ReadStateStore.getTrackedAckMessageId(item) == null && r10 > Date.now() - Durations.Millis.WEEK && r10 > UserSettingsProtoStore.getGuildRecentsDismissedAt(a0) && r10 > time && !UserGuildSettingsStore.isChannelOrParentOptedIn(a0, item); })); c3601_17[a0] = Date.now(); } } } }; pruneNewChannels = function pruneNewChannels() { SnowflakeUtils.keys(c3601_16).forEach((item) => { let c25600_0 = item; c3601_16[item] = new Set([...c3601_16[item]].filter((item) => !UserGuildSettingsStore.isChannelOrParentOptedIn(c25600_0, item))); }); }; c3601_15 = new Set(); c3601_16 = {}; c3601_17 = {}; c3601_18 = new Set(); class NewChannelsStore extends Module589.Store { static displayName = "NewChannelsStore"; constructor() { super(...arguments); } initialize() { this.waitFor(AuthenticationStore, ChannelStore, GuildChannelStore, GuildMemberStore, GuildStore, ReadStateStore, UserGuildSettingsStore, UserSettingsProtoStore); this.syncWith([UserGuildSettingsStore], pruneNewChannels); } getNewChannelIds(a0) { let r11; if (a0 != null && c3601_16[a0] == null) { initializeNewChannels(a0); } if (a0 != null) { let r12 = c3601_16[a0]; if (r12 == null) { r12 = c3601_15; } r11 = r12; } else { r11 = c3601_15; } return r11; } shouldIndicateNewChannel(a0, a1) { if (a0 == null) { return false; } const guild = GuildStore.getGuild(a0); const r1 = guild == null || !guild.features.has(GuildFeatures.COMMUNITY); let r15 = !r1; if (!r1) { if (a0 != null && c3601_16[a0] == null) { initializeNewChannels(a0); } const r9 = c3601_16[a0]; r15 = (r9 == null ? void 0 : r9.has(a1)) && ReadStateStore.getTrackedAckMessageId(a1) == null; } return r15; } } c3601_22 = NewChannelsStore; const r80 = new NewChannelsStore(Dispatcher, { BULK_CLEAR_RECENTS: function handleBulkClearRecents({ guildId, channelIds }) { if (c3601_16[guildId] == null) { return false; } channelIds.forEach((channelId) => c3601_16[guildId].delete(channelId)); if (c3601_16[guildId].size === 0) { delete c3601_16[guildId]; } }, CHANNEL_ACK: () => true, CHANNEL_SELECT: function handleChannelSelect({ guildId: guildId2, channelId }) { let r1; let r2 = guildId2 != null; if (r2) { L19: { if (c3601_16[guildId2] != null) { if (!(c3601_17[guildId2] < Date.now() - Durations.Millis.HOUR)) { const r6 = channelId != null; r1 = false; if (!r6) { break L19; } let env15167; const r27 = env15167 = { $parent: env3601 }; env15167[0] = channelId; const r28 = c3601_16[guildId2]; let r29 = r28 != null && channelId != null && r28.has(channelId) && UserGuildSettingsStore.isOptInEnabled(guildId2); if (r29) { const channel = ChannelStore.getChannel(channelId); r29 = !(channel == null ? void 0 : channel.isThread()); } if (r29) { r29 = ReadStateStore.ackMessageId(channelId) == null; } r1 = false; if (!r29) { break L19; } Dispatcher.wait($mk77042(r27)); r1 = false; } else { initializeNewChannels(guildId2); r1 = true; } } else { initializeNewChannels(guildId2); r1 = true; } } r2 = r1; } return r2; }, SIDEBAR_VIEW_CHANNEL: function handleSidebarViewChannel({ guildId: guildId2, channelId, sidebarType }) { if (!(guildId2 == null || sidebarType !== SidebarType.VIEW_CHANNEL)) { let env15168; const r15 = env15168 = { $parent: env3601 }; env15168[0] = channelId; const r7 = c3601_16[guildId2]; let r17 = r7 != null && channelId != null && r7.has(channelId) && UserGuildSettingsStore.isOptInEnabled(guildId2); if (r17) { const channel = ChannelStore.getChannel(channelId); r17 = !(channel == null ? void 0 : channel.isThread()); } if (r17) { r17 = ReadStateStore.ackMessageId(channelId) == null; } if (r17) { Dispatcher.wait($mk77042(r15)); } } return false; }, SIDEBAR_VIEW_GUILD: function handleSidebarViewGuild({ guildId: guildId2, baseChannelId }) { if (guildId2 != null) { let env15169; const r9 = env15169 = { $parent: env3601 }; env15169[0] = baseChannelId; const r6 = c3601_16[guildId2]; let r10 = r6 != null && baseChannelId != null && r6.has(baseChannelId) && UserGuildSettingsStore.isOptInEnabled(guildId2); if (r10) { const channel = ChannelStore.getChannel(baseChannelId); r10 = !(channel == null ? void 0 : channel.isThread()); } if (r10) { r10 = ReadStateStore.ackMessageId(baseChannelId) == null; } if (r10) { Dispatcher.wait($mk77042(r9)); } } return false; }, CONNECTION_OPEN: seedCommunityBaseline, CACHE_LOADED: seedCommunityBaseline, GUILD_CREATE: function handleGuildCreate({ guild }) { const guild2 = GuildStore.getGuild(guild.id); if ((guild2 == null ? void 0 : guild2.features.has(GuildFeatures.COMMUNITY)) === true) { c3601_18.add(guild.id); } return false; }, GUILD_UPDATE: function handleGuildUpdate({ guild }) { let c15170_0, c15170_1; let r6 = void 0; c15170_0 = void 0; c15170_1 = void 0; const guild2 = GuildStore.getGuild(guild.id); if (guild2 != null) { r6 = guild2.features.has(GuildFeatures.COMMUNITY); } const r20 = r6 === true; if (r20) { if (!c3601_18.has(guild.id)) { c3601_18.add(guild.id); const r30 = c3601_16[guild.id]; c15170_0 = r30; const guild3 = GuildStore.getGuild(guild.id); const set = new Set(); c15170_1 = set; if (guild3 != null && r30 != null) { [guild3.rulesChannelId, guild3.publicUpdatesChannelId].forEach((item) => { if (item != null && c15170_0.has(item)) { c15170_1.add(item); } }); } c3601_16[guild.id] = set; c3601_17[guild.id] = Date.now(); return true; } } if (!r20) { c3601_18.delete(guild.id); } return false; }, GUILD_DELETE: function handleGuildDelete({ guild }) { delete c3601_16[guild.id]; c3601_18.delete(guild.id); }, CHANNEL_CREATE: function handleChannelCreate({ channel }) { if (!channel.isVocal()) { const guild_id = channel.guild_id; let r13 = c3601_16[channel.guild_id]; if (r13 == null) { r13 = new Set(); } c3601_16[guild_id] = r13; c3601_16[channel.guild_id].add(channel.id); } } }); export default r80;