218 lines
8.0 KiB
TypeScript
218 lines
8.0 KiB
TypeScript
// Metro module 6158 (f6159).
|
|
import QuickSwitcherStore from "../quickswitcher/QuickSwitcherStore";
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import PermissionStore from "../../stores/PermissionStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import { isAllowedType } from "./ShareConstants";
|
|
import { ChannelTypes, Permissions } from "../../Constants";
|
|
import ChannelActionCreators from "../../actions/ChannelActionCreators";
|
|
import { AutocompleterResultTypes, createHeaderResult } from "../autocompleter/index";
|
|
import createAutocompleterResultForChannelId from "../autocompleter/createAutocompleterResultForChannelId";
|
|
import { intl, t } from "../../intl/index.native";
|
|
import { isNotNullish } from "../../utils/GlobalUtils";
|
|
import { isEqual } from "../../_bundle/Module12";
|
|
import { HermesBuiltin } from "../../_hermes/prelude";
|
|
function $mk77849($env) {
|
|
return (a0) => {
|
|
const r3 = $env.$parent;
|
|
const r5 = r3[0];
|
|
const r2 = r3[2];
|
|
let r8 = r5(r2[11]).isNotNullish(a0);
|
|
if (r8) {
|
|
let r14 = a0.type === r5(r2[8]).AutocompleterResultTypes.HEADER;
|
|
if (!r14) {
|
|
let r16 = (0, r3[8])(a0);
|
|
if (r16) {
|
|
const r17 = $env;
|
|
r16 = (0, r17[1])(a0, r17[0]);
|
|
}
|
|
r14 = r16;
|
|
}
|
|
r8 = r14;
|
|
}
|
|
return r8;
|
|
};
|
|
}
|
|
let canShareToChannel, mergeAndDedupeResultsWithHeaders;
|
|
let env3900 = {};
|
|
export function getChannelIdFromDestinationId(a0) {
|
|
if (a0.type === "channel") {
|
|
return a0.id;
|
|
}
|
|
const dMFromUserId = ChannelStore.getDMFromUserId(a0.id);
|
|
return dMFromUserId ?? void 0;
|
|
}
|
|
canShareToChannel = function canShareToChannel(a0, a1) {
|
|
return a0.type === AutocompleterResultTypes.USER ? a1 ? a1 : ChannelStore.getDMChannelFromUserId(a0.record.id) != null : a0.type === AutocompleterResultTypes.GROUP_DM || a0.record.type !== ChannelTypes.GUILD_FORUM && a0.record.type !== ChannelTypes.GUILD_MEDIA && (PermissionStore.can(Permissions.VIEW_CHANNEL, a0.record) && PermissionStore.can(Permissions.SEND_MESSAGES, a0.record));
|
|
};
|
|
mergeAndDedupeResultsWithHeaders = function mergeAndDedupeResultsWithHeaders(a0, a1) {
|
|
let r8 = void 0;
|
|
const set = new Set();
|
|
if (a1 != null) {
|
|
for (const item of a1) {
|
|
set.add(item);
|
|
}
|
|
}
|
|
const r36 = [];
|
|
for (const item2 of a0) {
|
|
if (item2 != null) {
|
|
if (item2.type === AutocompleterResultTypes.HEADER) {
|
|
r8 = item2;
|
|
} else {
|
|
const id = item2.record.id;
|
|
if (!set.has(id)) {
|
|
set.add(id);
|
|
if (r8 != null) {
|
|
r36.push(r8);
|
|
r8 = void 0;
|
|
}
|
|
r36.push(item2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return r36;
|
|
};
|
|
export default function formatResults(a0) {
|
|
let r50;
|
|
const { results, hasQuery, queryMode, frequentChannels, targetDestination, selectedDestinations, pinnedDestinations, originDestination } = a0;
|
|
let channelFilter = a0.channelFilter;
|
|
const includeMissingDMs = a0.includeMissingDMs;
|
|
if (hasQuery) {
|
|
let env15535;
|
|
const r92 = env15535 = {
|
|
$parent: env3900
|
|
};
|
|
env15535[0] = includeMissingDMs;
|
|
if (channelFilter === void 0) {
|
|
channelFilter = canShareToChannel;
|
|
}
|
|
env15535[1] = channelFilter;
|
|
return mergeAndDedupeResultsWithHeaders(results.filter($mk77849(r92)));
|
|
}
|
|
const r14 = pinnedDestinations != null && pinnedDestinations.length > 0 ? pinnedDestinations.map((pinnedDestination) => {
|
|
let r12;
|
|
if (pinnedDestination.type === "user") {
|
|
const user = UserStore.getUser(pinnedDestination.id);
|
|
r12 = user != null ? {
|
|
type: AutocompleterResultTypes.USER,
|
|
record: user,
|
|
score: 0
|
|
} : null;
|
|
} else {
|
|
r12 = createAutocompleterResultForChannelId(pinnedDestination.id);
|
|
}
|
|
return r12;
|
|
}) : [];
|
|
const channelHistory = QuickSwitcherStore.getChannelHistory();
|
|
const r33 = channelHistory.length > 0 ? channelHistory.map((item) => createAutocompleterResultForChannelId(item)) : [];
|
|
const r37 = frequentChannels.length > 0 ? frequentChannels.map((frequentChannel) => createAutocompleterResultForChannelId(frequentChannel.id)) : [];
|
|
const r40 = [,];
|
|
const r2 = HermesBuiltin.arraySpread(r40, r14, 0);
|
|
const r3 = targetDestination != null;
|
|
let r41 = null;
|
|
if (r3) {
|
|
if (targetDestination.type === "user") {
|
|
const user = UserStore.getUser(targetDestination.id);
|
|
r50 = user != null ? {
|
|
type: AutocompleterResultTypes.USER,
|
|
record: user,
|
|
score: 0
|
|
} : null;
|
|
} else {
|
|
r50 = createAutocompleterResultForChannelId(targetDestination.id);
|
|
}
|
|
r41 = r50;
|
|
}
|
|
let env15534;
|
|
r40[r2] = r41;
|
|
HermesBuiltin.arraySpread(r40, r37, HermesBuiltin.arraySpread(r40, r33, r2 + 1));
|
|
const r69 = env15534 = {
|
|
$parent: env3900
|
|
};
|
|
env15534[1] = void 0;
|
|
env15534[0] = includeMissingDMs;
|
|
env15534[1] = channelFilter === void 0 ? canShareToChannel : channelFilter;
|
|
const r74 = r40.filter($mk77849(r69));
|
|
const r79 = (selectedDestinations == null ? void 0 : selectedDestinations.find((selectedDestination) => isEqual(selectedDestination, originDestination))) != null;
|
|
const r81 = originDestination != null && !r79 ? [originDestination.id] : [];
|
|
return queryMode != null ? mergeAndDedupeResultsWithHeaders(r74.filter((item) => item.type === queryMode), r81) : mergeAndDedupeResultsWithHeaders(r74, r81).slice(0, 15);
|
|
};
|
|
export function getDestinationIdFromChannelId(a0) {
|
|
const channel = ChannelStore.getChannel(a0);
|
|
return channel?.type === ChannelTypes.DM ? {
|
|
type: "user",
|
|
id: channel.recipients[0]
|
|
} : {
|
|
type: "channel",
|
|
id: a0
|
|
};
|
|
}
|
|
export function destinationKey(a0) {
|
|
return `${a0.type}-${a0.id}`;
|
|
}
|
|
export async function getOrResolveChannelIdFromDestinationId(c25727_0) {
|
|
let channelIdFromDestinationId, orEnsurePrivateChannel;
|
|
let c25727_4 = 0;
|
|
L15: {
|
|
L14: {
|
|
try {
|
|
channelIdFromDestinationId = getChannelIdFromDestinationId(c25727_0);
|
|
if (channelIdFromDestinationId != null) {
|
|
break L15;
|
|
}
|
|
if (c25727_0.type === "user") {
|
|
c25727_4 = 1;
|
|
orEnsurePrivateChannel = await ChannelActionCreators.getOrEnsurePrivateChannel(c25727_0.id);
|
|
c25727_4 = 0;
|
|
break L14;
|
|
}
|
|
} catch ($e) {
|
|
let r8 = $e;
|
|
if (c25727_4 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c25727_4 = 0;
|
|
} catch ($e) {
|
|
r8 = $e;
|
|
if (c25727_4 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return void 0;
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return void 0;
|
|
}
|
|
return orEnsurePrivateChannel;
|
|
}
|
|
return channelIdFromDestinationId;
|
|
}
|
|
export function formatResultsWithHeaders({ results, selectedResult, hasNonEmptyQuery, queryMode: queryMode2, selectedChannelId, frequentChannels }) {
|
|
let r61;
|
|
const r7 = selectedResult != null ? [selectedResult.record.id] : [];
|
|
const headerResult = createHeaderResult(intl.string(t.qm9dSj));
|
|
if (hasNonEmptyQuery) {
|
|
return [headerResult, ...mergeAndDedupeResultsWithHeaders(results.filter(isAllowedType), r7)];
|
|
}
|
|
const r47 = frequentChannels.map((frequentChannel) => createAutocompleterResultForChannelId(frequentChannel.id)).filter(isNotNullish).filter(isAllowedType);
|
|
if (queryMode2 != null) {
|
|
r61 = [headerResult, ...r47.filter((item) => item.type === queryMode2)];
|
|
} else {
|
|
r61 = [createHeaderResult(intl.string(t["80lOZ1"])), , ,];
|
|
const r3 = selectedChannelId == null;
|
|
let r62 = null;
|
|
if (!r3) {
|
|
const autocompleterResultForChannelId = createAutocompleterResultForChannelId(selectedChannelId);
|
|
r62 = autocompleterResultForChannelId == null ? null : isAllowedType(autocompleterResultForChannelId) ? autocompleterResultForChannelId.type === AutocompleterResultTypes.USER || PermissionStore.can(Permissions.VIEW_CHANNEL, autocompleterResultForChannelId.record) ? autocompleterResultForChannelId : null : null;
|
|
}
|
|
r61[1] = r62;
|
|
r61[2] = headerResult;
|
|
HermesBuiltin.arraySpread(r61, r47, 3);
|
|
}
|
|
return mergeAndDedupeResultsWithHeaders(r61, r7);
|
|
}
|