379 lines
13 KiB
TypeScript
379 lines
13 KiB
TypeScript
// Metro module 12807 (f12808).
|
|
import ExperimentStore from "../modules/experiments/ExperimentStore";
|
|
import UserAffinitiesV2Store from "../modules/user_affinities/UserAffinitiesV2Store";
|
|
import { PrivateChannelRecord } from "../records/ChannelRecord";
|
|
import ChannelStore from "./ChannelStore";
|
|
import ConsentStore from "./ConsentStore";
|
|
import FrecencyStore from "./FrecencyStore";
|
|
import GuildMemberStore from "./GuildMemberStore";
|
|
import GuildStore from "./GuildStore";
|
|
import RelationshipStore from "./RelationshipStore";
|
|
import UserStore from "./UserStore";
|
|
import { NEW_GROUP_DM_POPOUT_ID, Consents } from "../Constants";
|
|
import { getFrictionlessGDMsEnabled } from "../modules/header_bar/FrictionlessGDMsExperiment";
|
|
import GuildUtils from "../utils/GuildUtils";
|
|
import { stripDiacritics } from "../utils/StringUtils";
|
|
import UserUtils from "../utils/UserUtils";
|
|
import { RestrictedGuildIds } from "../modules/user_settings/UserSettings";
|
|
import UserSearchManager from "../modules/autocompleter/UserSearchManager";
|
|
import Module589 from "../_bundle/Module589";
|
|
import Dispatcher from "../Dispatcher";
|
|
let userSearchContext, c8834_15, query, row, results, hasFriends2, isLoading, selectedUsers, channelId, updateHasFriends, sortUserList, getMutualGuildsWithCurrentUser, parseUserResults, performQueryOnAffinityChange, c8834_29;
|
|
const performQuery = function performQuery() {
|
|
if (c8834_15) {
|
|
const channel2 = ChannelStore.getChannel(channelId);
|
|
if (query.trim().length === 0) {
|
|
if (userSearchContext != null) {
|
|
userSearchContext.clearQuery();
|
|
}
|
|
let c20229_3;
|
|
const channel = channel2;
|
|
const currentUser = UserStore.getCurrentUser();
|
|
const frictionlessGDMsEnabled = getFrictionlessGDMsEnabled("PrivateChannelRecipientsInviteStore");
|
|
const r89 = [...RelationshipStore.getFriendIDs()];
|
|
const r96 = (currentUser == null ? void 0 : currentUser.isStaff()) ? Array.from(new Set([...r89, ...UserStore.filter((item) => item.isStaff() && item.id !== currentUser.id, false).map((item) => item.id)])) : r89;
|
|
c20229_3 = null;
|
|
let r120 = r96;
|
|
if (frictionlessGDMsEnabled) {
|
|
c20229_3 = new Set(GuildStore.getGuildIds());
|
|
r120 = Array.from(new Set([...r96, ...UserAffinitiesV2Store.getUserAffinities().map((item) => item.otherUserId).filter((item) => item !== currentUser?.id).filter((item) => !RelationshipStore.isBlockedOrIgnored(item)).filter((item) => !RelationshipStore.isFriend(item))]));
|
|
}
|
|
results = ((channel == null ? void 0 : channel.isGroupDM()) ? r120.filter((item) => !channel.recipients.includes(item)) : r120).reduce((acc, item) => {
|
|
let mutualGuildsWithCurrentUser;
|
|
L19: {
|
|
const user = UserStore.getUser(item);
|
|
if (user != null && !user.isProvisional) {
|
|
if (user.bot) {
|
|
if (!user.isStaff()) {
|
|
break L19;
|
|
}
|
|
if (!(currentUser == null ? void 0 : currentUser.isStaff())) {
|
|
break L19;
|
|
}
|
|
}
|
|
const r26 = {
|
|
user,
|
|
comparator: UserUtils.getName(user)
|
|
};
|
|
if (frictionlessGDMsEnabled) {
|
|
if (c20229_3 != null && !RelationshipStore.isFriend(user.id)) {
|
|
L16: {
|
|
mutualGuildsWithCurrentUser = getMutualGuildsWithCurrentUser(user.id, c20229_3);
|
|
if (mutualGuildsWithCurrentUser.length === 0) {
|
|
if (user.isStaff() && (currentUser == null ? void 0 : currentUser.isStaff())) {
|
|
break L16;
|
|
}
|
|
return acc;
|
|
}
|
|
}
|
|
if (mutualGuildsWithCurrentUser.length > 0) {
|
|
r26.mutualGuilds = mutualGuildsWithCurrentUser;
|
|
}
|
|
}
|
|
}
|
|
acc.push(r26);
|
|
return acc;
|
|
}
|
|
}
|
|
return acc;
|
|
}, []).sort(sortUserList);
|
|
if (isLoading !== false) {
|
|
isLoading = false;
|
|
}
|
|
return true;
|
|
}
|
|
const currentUser2 = UserStore.getCurrentUser();
|
|
let staff = currentUser2 == null ? void 0 : currentUser2.isStaff();
|
|
if (staff == null) {
|
|
staff = false;
|
|
}
|
|
const frictionlessGDMsEnabled2 = getFrictionlessGDMsEnabled("PrivateChannelRecipientsInviteStore");
|
|
if (frictionlessGDMsEnabled2) {
|
|
GuildUtils.requestMembers(null, query);
|
|
}
|
|
const blacklist = channel2 != null ? channel2.recipients : [];
|
|
if (userSearchContext != null) {
|
|
const filters = frictionlessGDMsEnabled2 ? void 0 : {
|
|
friends: true,
|
|
staff,
|
|
provisional: false
|
|
};
|
|
let c20228_0, c20228_1;
|
|
const r54 = FrecencyStore.getFrequentlyWithoutFetchingLatest().filter((item) => item instanceof PrivateChannelRecord && item.isDM());
|
|
const r14 = Math;
|
|
c20228_0 = r14.max.apply(r14, [...r54.map((item) => FrecencyStore.getScoreWithoutFetchingLatest(item.id))]);
|
|
const boosters = {};
|
|
c20228_1 = boosters;
|
|
r54.forEach((item) => {
|
|
const scoreWithoutFetchingLatest = FrecencyStore.getScoreWithoutFetchingLatest(item.id);
|
|
const recipientId = item.getRecipientId();
|
|
c20228_1[recipientId] = 1 + scoreWithoutFetchingLatest / c20228_0 + (RelationshipStore.isFriend(recipientId) ? 0.2 : 0) + (ChannelStore.getDMFromUserId(recipientId) != null ? 0.1 : 0);
|
|
});
|
|
userSearchContext.setQuery({
|
|
query,
|
|
filters,
|
|
blacklist,
|
|
boosters
|
|
});
|
|
}
|
|
return false;
|
|
}
|
|
return false;
|
|
};
|
|
updateHasFriends = function updateHasFriends() {
|
|
if (c8834_15) {
|
|
const r2 = hasFriends2;
|
|
const r8 = RelationshipStore.getFriendCount() > 0;
|
|
hasFriends2 = r8;
|
|
return r8 !== r2;
|
|
}
|
|
return false;
|
|
};
|
|
sortUserList = function sortUserList(a0, a1) {
|
|
return stripDiacritics(UserUtils.getName(a0.user).toLocaleLowerCase()).localeCompare(stripDiacritics(UserUtils.getName(a1.user).toLocaleLowerCase()));
|
|
};
|
|
getMutualGuildsWithCurrentUser = function getMutualGuildsWithCurrentUser(id, a1) {
|
|
const setting = RestrictedGuildIds.getSetting();
|
|
const r29 = [];
|
|
for (const item of a1) {
|
|
if (!setting.includes(item) && GuildMemberStore.isMember(item, id)) {
|
|
const guild = GuildStore.getGuild(item);
|
|
if (guild != null) {
|
|
r29.push(guild);
|
|
}
|
|
}
|
|
}
|
|
return r29;
|
|
};
|
|
parseUserResults = function parseUserResults({ results: results2 }) {
|
|
let mutualGuilds;
|
|
if (c8834_15 && query !== "") {
|
|
const currentUser2 = UserStore.getCurrentUser();
|
|
const frictionlessGDMsEnabled2 = getFrictionlessGDMsEnabled("PrivateChannelRecipientsInviteStore");
|
|
const r6 = frictionlessGDMsEnabled2 ? new Set(GuildStore.getGuildIds()) : null;
|
|
const r45 = [];
|
|
for (const item of results2) {
|
|
const { id, comparator } = item;
|
|
if (currentUser2 != null && id === currentUser2.id) {
|
|
continue;
|
|
}
|
|
const user = UserStore.getUser(id);
|
|
const user2 = user;
|
|
if (user != null && !user2.isProvisional) {
|
|
if (user2.bot) {
|
|
if (!user2.isStaff()) {
|
|
continue;
|
|
}
|
|
if (!(currentUser2 == null ? void 0 : currentUser2.isStaff())) {
|
|
continue;
|
|
}
|
|
}
|
|
const r72 = {
|
|
user: user2,
|
|
comparator
|
|
};
|
|
if (frictionlessGDMsEnabled2 && r6 != null && !RelationshipStore.isFriend(user2.id)) {
|
|
L24: {
|
|
const mutualGuildsWithCurrentUser = getMutualGuildsWithCurrentUser(user2.id, r6);
|
|
mutualGuilds = mutualGuildsWithCurrentUser;
|
|
if (mutualGuildsWithCurrentUser.length === 0) {
|
|
if (!user2.isStaff()) {
|
|
continue;
|
|
}
|
|
if (currentUser2 == null ? void 0 : currentUser2.isStaff()) {
|
|
break L24;
|
|
}
|
|
continue;
|
|
}
|
|
}
|
|
if (mutualGuilds.length > 0) {
|
|
r72.mutualGuilds = mutualGuilds;
|
|
}
|
|
}
|
|
r45.push(r72);
|
|
}
|
|
}
|
|
results = r45;
|
|
c8834_29.emitChange();
|
|
}
|
|
};
|
|
const handleModalActionSheetOpen = function handleModalActionSheetOpen(a0) {
|
|
if (a0.key !== NEW_GROUP_DM_POPOUT_ID) {
|
|
return false;
|
|
}
|
|
c8834_15 = true;
|
|
hasFriends2 = RelationshipStore.getFriendCount() > 0;
|
|
if (userSearchContext != null) {
|
|
userSearchContext.destroy();
|
|
userSearchContext = null;
|
|
}
|
|
userSearchContext = UserSearchManager.getUserSearchContext(parseUserResults, 1000);
|
|
channelId = null;
|
|
query = "";
|
|
row = 0;
|
|
performQuery();
|
|
};
|
|
const handleActionSheetDismiss = function handleActionSheetDismiss(a0) {
|
|
if (a0.key !== NEW_GROUP_DM_POPOUT_ID) {
|
|
return false;
|
|
}
|
|
if (userSearchContext != null) {
|
|
userSearchContext.destroy();
|
|
userSearchContext = null;
|
|
}
|
|
query = "";
|
|
row = 0;
|
|
results = [];
|
|
selectedUsers = new Set();
|
|
c8834_15 = false;
|
|
channelId = null;
|
|
isLoading = false;
|
|
};
|
|
performQueryOnAffinityChange = function performQueryOnAffinityChange() {
|
|
const r1 = c8834_15 ? !getFrictionlessGDMsEnabled("PrivateChannelRecipientsInviteStore") : !c8834_15;
|
|
return r1 ? !r1 : performQuery();
|
|
};
|
|
Consents;
|
|
c8834_15 = false;
|
|
query = "";
|
|
row = 0;
|
|
results = [];
|
|
hasFriends2 = false;
|
|
isLoading = false;
|
|
selectedUsers = new Set();
|
|
channelId = null;
|
|
class PrivateChannelRecipientsInviteStoreClass extends Module589.Store {
|
|
static displayName = "PrivateChannelRecipientsInviteStore";
|
|
initialize() {
|
|
this.waitFor(ChannelStore, ConsentStore, ExperimentStore, FrecencyStore, GuildMemberStore, GuildStore, RelationshipStore, UserAffinitiesV2Store, UserStore);
|
|
this.syncWith([UserStore, ChannelStore], performQuery);
|
|
this.syncWith([UserAffinitiesV2Store], performQueryOnAffinityChange);
|
|
this.syncWith([RelationshipStore], updateHasFriends);
|
|
}
|
|
getResults() {
|
|
return results;
|
|
}
|
|
hasFriends() {
|
|
return hasFriends2;
|
|
}
|
|
getSelectedUsers() {
|
|
return selectedUsers;
|
|
}
|
|
getQuery() {
|
|
return query;
|
|
}
|
|
getState() {
|
|
return {
|
|
query,
|
|
selectedRow: row,
|
|
selectedUsers,
|
|
results,
|
|
hasFriends: hasFriends2,
|
|
isLoading
|
|
};
|
|
}
|
|
}
|
|
c8834_29 = new PrivateChannelRecipientsInviteStoreClass(Dispatcher, {
|
|
CONNECTION_OPEN: function handleConnectionOpen() {
|
|
query = "";
|
|
row = 0;
|
|
results = [];
|
|
selectedUsers = new Set();
|
|
c8834_15 = false;
|
|
channelId = null;
|
|
isLoading = false;
|
|
},
|
|
GUILD_MEMBERS_CHUNK_BATCH: function handleGuildMembersChunkBatch() {
|
|
const r0 = c8834_15 ? !getFrictionlessGDMsEnabled("PrivateChannelRecipientsInviteStore") : !c8834_15;
|
|
let r12 = !r0;
|
|
if (!r0) {
|
|
let r14 = isLoading !== false;
|
|
if (r14) {
|
|
isLoading = false;
|
|
r14 = true;
|
|
}
|
|
r12 = r14;
|
|
}
|
|
return r12;
|
|
},
|
|
GUILD_MEMBERS_REQUEST: function handleGuildMembersRequest({ query: query2 }) {
|
|
const r0 = c8834_15 ? !getFrictionlessGDMsEnabled("PrivateChannelRecipientsInviteStore") : !c8834_15;
|
|
let r15 = !r0;
|
|
if (!r0) {
|
|
let r19 = query2 === query.toLocaleLowerCase();
|
|
if (r19) {
|
|
let r20 = isLoading !== true;
|
|
if (r20) {
|
|
isLoading = true;
|
|
r20 = true;
|
|
}
|
|
r19 = r20;
|
|
}
|
|
r15 = r19;
|
|
}
|
|
return r15;
|
|
},
|
|
CHANNEL_SELECT: function handleChannelSelect({ guildId, channelId: channelId2 }) {
|
|
if (guildId != null) {
|
|
return false;
|
|
}
|
|
const r10 = c8834_15;
|
|
query = "";
|
|
row = 0;
|
|
results = [];
|
|
selectedUsers = new Set();
|
|
isLoading = false;
|
|
c8834_15 = r10;
|
|
channelId = channelId2;
|
|
return performQuery();
|
|
},
|
|
MODAL_PUSH: handleModalActionSheetOpen,
|
|
SHOW_ACTION_SHEET: handleModalActionSheetOpen,
|
|
PRIVATE_CHANNEL_RECIPIENTS_INVITE_OPEN: function handleInviteOpen(a0) {
|
|
c8834_15 = true;
|
|
hasFriends2 = RelationshipStore.getFriendCount() > 0;
|
|
if (userSearchContext != null) {
|
|
userSearchContext.destroy();
|
|
userSearchContext = null;
|
|
}
|
|
userSearchContext = UserSearchManager.getUserSearchContext(parseUserResults, 1000);
|
|
channelId = a0.channelId;
|
|
query = "";
|
|
row = 0;
|
|
performQuery();
|
|
},
|
|
MODAL_POP: handleActionSheetDismiss,
|
|
HIDE_ACTION_SHEET: handleActionSheetDismiss,
|
|
PRIVATE_CHANNEL_RECIPIENTS_INVITE_CLOSE: function handleClose() {
|
|
if (userSearchContext != null) {
|
|
userSearchContext.destroy();
|
|
userSearchContext = null;
|
|
}
|
|
query = "";
|
|
row = 0;
|
|
results = [];
|
|
selectedUsers = new Set();
|
|
c8834_15 = false;
|
|
channelId = null;
|
|
isLoading = false;
|
|
},
|
|
PRIVATE_CHANNEL_RECIPIENTS_INVITE_QUERY: function handleQuery(a0) {
|
|
channelId = a0.channelId;
|
|
query = a0.query;
|
|
row = 0;
|
|
performQuery();
|
|
},
|
|
PRIVATE_CHANNEL_RECIPIENTS_INVITE_SELECT: function handleSelect(a0) {
|
|
row = a0.row;
|
|
},
|
|
PRIVATE_CHANNEL_RECIPIENTS_ADD_USER: function handleAddUser(a0) {
|
|
selectedUsers.add(a0.userId);
|
|
selectedUsers = new Set(selectedUsers);
|
|
},
|
|
PRIVATE_CHANNEL_RECIPIENTS_REMOVE_USER: function handleRemoveUser(a0) {
|
|
selectedUsers.delete(a0.userId);
|
|
selectedUsers = new Set(selectedUsers);
|
|
}
|
|
});
|
|
export default c8834_29;
|