// Metro module 10087 (f10088). import QuickSwitcherStore from "../modules/quickswitcher/QuickSwitcherStore"; import UserAffinitiesV2Store from "../modules/user_affinities/UserAffinitiesV2Store"; import ChannelStore from "./ChannelStore"; import PermissionStore from "./PermissionStore"; import RelationshipStore from "./RelationshipStore"; import { ChannelTypes, Permissions } from "../Constants"; import { InviteTargetTypes } from "../modules/instant_invite/Constants"; import { getMostRecentDMedUser, generateRowsForQuery, getUsersAlreadyJoined } from "../utils/InstantInviteUtils"; import { isNotNullish } from "../utils/GlobalUtils"; import Module589 from "../_bundle/Module589"; import Dispatcher from "../Dispatcher"; let length, isFiltered, guild, channel, applicationId, inviteTargetType, omitUserIds, rows, c6713_18, counts, $mk83908 = function() { return (a0, a1) => { c6713_18.set(a0, { index: a1 }); }; }; const _computeRows = function _computeRows(a0) { const set = new Set(); const type = channel?.type; const GUILD_VOICE = ChannelTypes.GUILD_VOICE; const omitGuildId = guild == null || inviteTargetType === InviteTargetTypes.EMBEDDED_APPLICATION || type === GUILD_VOICE ? null : guild.id; const mostRecentDMedUser = getMostRecentDMedUser(omitUserIds, omitGuildId); const r38 = mostRecentDMedUser == null || RelationshipStore.isBlockedOrIgnored(mostRecentDMedUser.id); if (!r38) { set.add(mostRecentDMedUser.id); } for (const item of UserAffinitiesV2Store.getUserAffinities()) { set.add(item.otherUserId); } const set2 = new Set(); let c17677_0 = set2; if (inviteTargetType === InviteTargetTypes.EMBEDDED_APPLICATION) { QuickSwitcherStore.getChannelHistory().map((item) => ChannelStore.getChannel(item)).filter(isNotNullish).filter((item) => item.type === ChannelTypes.GUILD_TEXT).filter((item) => PermissionStore.can(Permissions.SEND_MESSAGES, item)).slice(0, 3).forEach((item) => c17677_0.add(item.id)); } return generateRowsForQuery({ query: a0, omitUserIds, suggestedUserIds: set, maxRowsWithoutQuery: 100, omitGuildId, suggestedChannelIds: set2, inviteTargetType }); }; omitUserIds = new Set(); rows = []; c6713_18 = new Map(); counts = { numFriends: 0, numDms: 0, numGroupDms: 0, numChannels: 0 }; class InviteSuggestionsStore extends Module589.Store { static displayName = "InviteSuggestionsStore"; initialize() { this.waitFor(ChannelStore, PermissionStore, QuickSwitcherStore, RelationshipStore, UserAffinitiesV2Store); } getInviteSuggestionRows() { return rows; } getTotalSuggestionsCount() { return length; } getInitialCounts() { return counts; } getSelectedInviteMetadata(a0) { const r6 = c6713_18.get(a0); const r12 = UserAffinitiesV2Store.getUserAffinities().map((item) => item.otherUserId); if (r6 != null) { return { rowNum: r6.index, isAffinitySuggestion: a0.isSuggested, numTotal: rows.length, numAffinityConnections: r12.length, isFiltered }; } } } const inviteSuggestionsStore = new InviteSuggestionsStore(Dispatcher, { LOAD_INVITE_SUGGESTIONS: function refreshInviteSuggestions({ omitUserIds: omitUserIds2, guild: guild2, channel: channel2, applicationId: applicationId2, inviteTargetType: inviteTargetType2 }) { guild = channel2 != null ? guild2 : null; channel = channel2; applicationId = applicationId2; inviteTargetType = inviteTargetType2; omitUserIds = new Set([...omitUserIds2, ...RelationshipStore.getBlockedOrIgnoredIDs(), ...getUsersAlreadyJoined({ channel, applicationId, inviteTargetType })]); isFiltered = false; const r44 = _computeRows(""); const { rows: rows2, counts: counts2 } = r44; rows = rows2; c6713_18 = new Map(); rows2.forEach($mk83908()); counts = counts2; length = rows.length; }, INVITE_SUGGESTIONS_SEARCH: function handleSearch({ query }) { isFiltered = query !== ""; const rows2 = _computeRows(query).rows; rows2.sort((a, b) => a.score != null ? b.score != null ? a.score - b.score : 0 : 0); rows = rows2; c6713_18 = new Map(); rows2.forEach($mk83908()); } }); export default inviteSuggestionsStore;