decord/source/modules/share/formatResults.tsx

402 lines
14 KiB
TypeScript
Raw Normal View History

2026-08-25 06:04:03 +00:00
// Module ID: 7450
// Function ID: 7451
2026-07-29 08:29:29 +00:00
// Name: getChannelIdFromDestinationId
2026-08-25 06:04:03 +00:00
// Dependencies: [5, 7451, 1391, 4025, 1922, 7465, 676, 7452, 4393, 7463, 1236, 1370, 12, 2]
2026-08-07 06:50:47 +00:00
// Exports: default, destinationKey, formatResultsWithHeaders, getDestinationIdFromChannelId, getDestinationIdFromResult, getOrResolveChannelIdFromDestinationId
2026-07-20 16:05:17 +00:00
2026-08-25 06:04:03 +00:00
// Module 7450 (getChannelIdFromDestinationId)
import sortByMatchScore from "sortByMatchScore" /* 7452 */;
import createAutocompleterResultForChannelIdDefault from "createAutocompleterResultForChannelId" /* 7463 */;
2026-08-24 06:08:38 +00:00
import closure_3 from "asyncGeneratorStep" /* 5 */;
2026-08-25 06:04:03 +00:00
import closure_4 from "handleConnectionOpen" /* 7451 */;
2026-08-24 06:08:38 +00:00
import closure_5 from "ensureGuildLoaded" /* 1391 */;
2026-08-25 06:04:03 +00:00
import closure_6 from "getUncachedChannelPermissions" /* 4025 */;
2026-08-24 06:08:38 +00:00
import closure_7 from "mergeGuildAvatar" /* 1922 */;
2026-08-25 06:04:03 +00:00
import { isAllowedType } from "ALLOWED_TYPES" /* 7465 */;
2026-08-24 06:08:38 +00:00
import ME from "ME" /* 676 */;
2026-07-20 16:05:17 +00:00
2026-08-24 06:08:38 +00:00
require = arg1;
2026-07-20 16:05:17 +00:00
function getChannelIdFromDestinationId(type) {
if ("channel" === type.type) {
return type.id;
} else {
const dMFromUserId = authStore.getDMFromUserId(type.id);
let tmp4;
if (null != dMFromUserId) {
tmp4 = dMFromUserId;
}
return tmp4;
}
}
2026-07-29 08:29:29 +00:00
function _getOrResolveChannelIdFromDestinationId() {
const self = this;
const tmp = callback((arg0) => {
2026-08-24 06:08:38 +00:00
closure_0 = arg0;
c2 = 0;
c1 = 0;
c4 = 0;
2026-07-29 08:29:29 +00:00
return (function*(arg0) {
if (v0 === 2) {
v0 = 3;
HermesBuiltin.throwTypeError();
} else if (tmp5 === 3) {
if (arg0 === 1) {
throw arg1;
} else if (arg0 === 2) {
let obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
2026-08-25 06:04:03 +00:00
return { value: "HermesInternal", done: "HermesInternal" };
2026-07-29 08:29:29 +00:00
}
} else {
try {
v0 = 2;
if (0 === table) {
if (arg0 === 1) {
v0 = 3;
throw arg1;
} else if (arg0 === 2) {
v0 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
} else {
2026-08-24 06:08:38 +00:00
const tmp21 = closure_1_11(closure_0);
2026-07-29 08:29:29 +00:00
if (null != tmp21) {
v0 = 3;
2026-08-24 06:08:38 +00:00
obj1 = { value: null, done: true };
2026-07-29 08:29:29 +00:00
obj1[0] = tmp21;
return obj1;
} else if ("user" === tmp19.type) {
2026-08-24 06:08:38 +00:00
c4 = 1;
2026-08-07 06:50:47 +00:00
let obj2 = v0(table[8]);
2026-07-29 08:29:29 +00:00
table = 2;
v0 = 1;
obj2 = { value: null, done: false };
obj2[0] = obj2.getOrEnsurePrivateChannel(tmp19.id);
return obj2;
} else {
v0 = 3;
2026-08-25 06:04:03 +00:00
return { value: "HermesInternal", done: "HermesInternal" };
2026-07-29 08:29:29 +00:00
}
}
} else if (1 === tmp6) {
c4 = 0;
v0 = 3;
2026-08-25 06:04:03 +00:00
return { value: "HermesInternal", done: "HermesInternal" };
2026-07-29 08:29:29 +00:00
} else if (arg0 === 1) {
v0 = 3;
throw arg1;
} else if (arg0 === 2) {
c4 = 0;
v0 = 3;
const obj3 = { value: null, done: true };
obj3[0] = arg1;
return obj3;
} else {
c4 = 0;
v0 = 3;
obj = { value: null, done: true };
obj[0] = arg1;
return obj;
}
} catch (tmp10) {
2026-08-24 06:08:38 +00:00
closure_3 = tmp10;
2026-07-29 08:29:29 +00:00
if (tmp3 === c4) {
v0 = tmp2;
throw tmp10;
} else {
table = tmp;
}
}
}
})();
});
2026-08-24 06:08:38 +00:00
closure_12 = tmp;
2026-07-29 08:29:29 +00:00
const apply = tmp.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
applyArgumentsResult = apply(self, arguments);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return applyArgumentsResult;
2026-07-20 16:05:17 +00:00
}
function canShareToChannel(type) {
2026-08-24 06:08:38 +00:00
if (type.type === sortByMatchScore.AutocompleterResultTypes.USER) {
2026-07-29 08:29:29 +00:00
let tmp8 = arg1;
if (!arg1) {
tmp8 = null != authStore.getDMChannelFromUserId(type.record.id);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let tmp7 = tmp8;
2026-07-20 16:05:17 +00:00
} else {
2026-08-24 06:08:38 +00:00
tmp7 = type.type === sortByMatchScore.AutocompleterResultTypes.GROUP_DM;
2026-07-29 08:29:29 +00:00
if (!tmp7) {
let tmp4 = type.record.type !== constants2.GUILD_FORUM && type.record.type !== tmp3.GUILD_MEDIA;
if (tmp4) {
2026-08-24 06:08:38 +00:00
tmp4 = closure_6.can(constants.VIEW_CHANNEL, type.record) && closure_6.can(constants.SEND_MESSAGES, type.record);
const obj = closure_6;
2026-07-29 08:29:29 +00:00
const tmp5 = constants;
2026-08-24 06:08:38 +00:00
const tmp6 = closure_6.can(constants.VIEW_CHANNEL, type.record) && closure_6.can(constants.SEND_MESSAGES, type.record);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
tmp7 = tmp4;
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
return tmp7;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
function mergeAndDedupeResultsWithHeaders(found, items1) {
2026-07-20 16:05:17 +00:00
const set = new Set();
if (null != items1) {
2026-07-29 08:29:29 +00:00
const tmp3 = items1[Symbol.iterator]();
while (tmp3 !== undefined) {
let addResult = set.add(tmp5);
continue;
2026-07-20 16:05:17 +00:00
}
}
const items = [];
2026-07-29 08:29:29 +00:00
const iter = found[Symbol.iterator]();
const nextResult = iter.next();
while (iter !== undefined) {
let tmp9 = nextResult;
if (null != nextResult) {
let tmp19 = nextResult;
let tmp20 = require;
let tmp21 = dependencyMap;
2026-08-24 06:08:38 +00:00
if (tmp9.type === sortByMatchScore.AutocompleterResultTypes.HEADER) {
2026-07-29 08:29:29 +00:00
let tmp = nextResult;
} else {
let tmp10 = nextResult;
let id = tmp9.record.id;
let tmp11 = id;
if (!set.has(id)) {
let tmp12 = id;
let addResult1 = set.add(tmp11);
let tmp14 = tmp;
if (null != tmp) {
let tmp15 = tmp;
let arr = items.push(tmp);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
let tmp17 = nextResult;
arr = items.push(tmp9);
2026-07-20 16:05:17 +00:00
}
}
}
2026-07-29 08:29:29 +00:00
continue;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return items;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
({ Permissions: c9, ChannelTypes: c10 } = ME);
2026-08-24 06:08:38 +00:00
const result = require("set").fileFinishedImporting("modules/share/formatResults.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export default function formatResults(hasQuery) {
({ results, queryMode } = hasQuery);
includeMissingDMs = queryMode;
({ frequentChannels, targetDestination, selectedDestinations, pinnedDestinations, originDestination } = hasQuery);
2026-08-24 06:08:38 +00:00
importDefault = originDestination;
2026-07-29 08:29:29 +00:00
({ channelFilter, includeMissingDMs } = hasQuery);
if (hasQuery.hasQuery) {
if (channelFilter === undefined) {
channelFilter = canShareToChannel;
}
importDefault = channelFilter;
return mergeAndDedupeResultsWithHeaders(results.filter((type) => {
2026-08-24 06:08:38 +00:00
let isNotNullishResult = includeMissingDMs(closure_1_2[11]).isNotNullish(type);
2026-07-29 08:29:29 +00:00
if (isNotNullishResult) {
2026-08-24 06:08:38 +00:00
let tmp4 = type.type === includeMissingDMs(closure_1_2[7]).AutocompleterResultTypes.HEADER;
2026-07-29 08:29:29 +00:00
if (!tmp4) {
2026-08-24 06:08:38 +00:00
let tmp6 = closure_1_8(type);
2026-07-29 08:29:29 +00:00
if (tmp6) {
2026-08-24 06:08:38 +00:00
tmp6 = callback(type, includeMissingDMs);
2026-07-29 08:29:29 +00:00
}
tmp4 = tmp6;
}
isNotNullishResult = tmp4;
}
return isNotNullishResult;
}));
2026-07-20 16:05:17 +00:00
} else {
if (null != pinnedDestinations) {
if (pinnedDestinations.length > 0) {
2026-07-29 08:29:29 +00:00
let mapped = pinnedDestinations.map((type) => {
if ("user" === type.type) {
user = user.getUser(type.id);
let tmp6 = null;
if (null != user) {
const obj = { type: null, record: null, score: 0 };
2026-08-25 06:04:03 +00:00
obj[0] = includeMissingDMs(7452).AutocompleterResultTypes.USER;
2026-07-29 08:29:29 +00:00
obj[1] = user;
tmp6 = obj;
}
let tmp3 = tmp6;
} else {
2026-08-25 06:04:03 +00:00
tmp3 = callback(7463)(type.id);
2026-07-29 08:29:29 +00:00
}
return tmp3;
});
2026-07-20 16:05:17 +00:00
}
2026-07-23 10:11:24 +00:00
channelHistory = channelHistory.getChannelHistory();
2026-07-20 16:05:17 +00:00
if (channelHistory.length > 0) {
2026-08-25 06:04:03 +00:00
let mapped1 = channelHistory.map((arg0) => callback(7463)(arg0));
2026-07-20 16:05:17 +00:00
} else {
mapped1 = [];
}
if (frequentChannels.length > 0) {
2026-08-25 06:04:03 +00:00
let mapped2 = frequentChannels.map((id) => callback(7463)(id.id));
2026-07-20 16:05:17 +00:00
} else {
mapped2 = [];
}
const items = [];
let arraySpreadResult = HermesBuiltin.arraySpread(mapped, 0);
2026-07-29 08:29:29 +00:00
if (null == targetDestination) {
items[arraySpreadResult] = null;
arraySpreadResult = HermesBuiltin.arraySpread(mapped2, HermesBuiltin.arraySpread(mapped1, arraySpreadResult + 1));
importDefault = undefined;
let tmp20 = channelFilter;
if (channelFilter === undefined) {
tmp20 = canShareToChannel;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
importDefault = tmp20;
const found = items.filter((type) => {
2026-08-24 06:08:38 +00:00
let isNotNullishResult = includeMissingDMs(closure_1_2[11]).isNotNullish(type);
2026-07-29 08:29:29 +00:00
if (isNotNullishResult) {
2026-08-24 06:08:38 +00:00
let tmp4 = type.type === includeMissingDMs(closure_1_2[7]).AutocompleterResultTypes.HEADER;
2026-07-29 08:29:29 +00:00
if (!tmp4) {
2026-08-24 06:08:38 +00:00
let tmp6 = closure_1_8(type);
2026-07-29 08:29:29 +00:00
if (tmp6) {
2026-08-24 06:08:38 +00:00
tmp6 = callback(type, includeMissingDMs);
2026-07-29 08:29:29 +00:00
}
tmp4 = tmp6;
}
isNotNullishResult = tmp4;
}
return isNotNullishResult;
});
if (selectedDestinations != null) {
2026-08-24 06:08:38 +00:00
const found1 = selectedDestinations.find((arg0) => includeMissingDMs(closure_1_2[12]).isEqual(arg0, closure_1));
2026-07-29 08:29:29 +00:00
}
if (null != originDestination) {
if (null == found1) {
let items1 = [originDestination.id];
}
if (null != queryMode) {
let substr = mergeAndDedupeResultsWithHeaders(found.filter((type) => type.type === includeMissingDMs), items1);
} else {
substr = mergeAndDedupeResultsWithHeaders(found, items1).slice(0, 15);
const arr8 = mergeAndDedupeResultsWithHeaders(found, items1);
}
return substr;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
items1 = [];
} else if ("user" === targetDestination.type) {
user = user.getUser(targetDestination.id);
targetDestination = null;
if (null != user) {
let obj = { type: null, record: null, score: 0 };
2026-08-25 06:04:03 +00:00
obj[0] = includeMissingDMs(7452).AutocompleterResultTypes.USER;
2026-07-29 08:29:29 +00:00
obj[1] = user;
targetDestination = obj;
}
let tmp9 = targetDestination;
} else {
2026-08-24 06:08:38 +00:00
tmp9 = createAutocompleterResultForChannelIdDefault(targetDestination.id);
2026-07-20 16:05:17 +00:00
}
}
mapped = [];
}
};
export const getDestinationIdFromChannelId = function getDestinationIdFromChannelId(channel_id) {
const channel = authStore.getChannel(channel_id);
let type;
2026-07-29 08:29:29 +00:00
if (channel != null) {
2026-07-20 16:05:17 +00:00
type = channel.type;
}
if (type === constants2.DM) {
2026-07-29 08:29:29 +00:00
let obj = { type: "user", id: null };
obj[1] = channel.recipients[0];
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
obj = { type: "channel", id: null };
obj[1] = channel_id;
2026-07-20 16:05:17 +00:00
}
return obj;
};
2026-08-11 06:20:06 +00:00
export const getDestinationIdFromResult = function getDestinationIdFromResult(closure_0) {
const record = closure_0.record;
2026-08-24 06:08:38 +00:00
if (closure_0.type === sortByMatchScore.AutocompleterResultTypes.USER) {
2026-08-07 06:50:47 +00:00
let obj = { type: "user", id: null };
obj[1] = record.id;
} else {
obj = { type: "channel", id: null };
obj[1] = record.id;
}
return obj;
};
export const destinationKey = function destinationKey(destinationIdFromResult) {
return "" + destinationIdFromResult.type + "-" + destinationIdFromResult.id;
2026-07-20 16:05:17 +00:00
};
export { getChannelIdFromDestinationId };
2026-08-11 06:20:06 +00:00
export const getOrResolveChannelIdFromDestinationId = function getOrResolveChannelIdFromDestinationId(closure_0) {
2026-07-29 08:29:29 +00:00
const self = this;
const apply = _getOrResolveChannelIdFromDestinationId.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
2026-07-20 16:05:17 +00:00
};
2026-07-29 08:29:29 +00:00
export const formatResultsWithHeaders = function formatResultsWithHeaders(hasNonEmptyQuery) {
({ results, selectedResult, queryMode } = hasNonEmptyQuery);
({ selectedChannelId, frequentChannels } = hasNonEmptyQuery);
2026-07-20 16:05:17 +00:00
if (null != selectedResult) {
const items = [selectedResult.record.id];
let items1 = items;
} else {
items1 = [];
}
2026-07-29 08:29:29 +00:00
const intl = queryMode(1236).intl;
2026-08-25 06:04:03 +00:00
const headerResult = queryMode(7452).createHeaderResult(intl.string(queryMode(1236).t.qm9dSj));
2026-07-29 08:29:29 +00:00
if (hasNonEmptyQuery.hasNonEmptyQuery) {
2026-07-20 16:05:17 +00:00
const items2 = [headerResult];
HermesBuiltin.arraySpread(mergeAndDedupeResultsWithHeaders(results.filter(isAllowedType), items1), 1);
return items2;
} else {
2026-07-29 08:29:29 +00:00
const mapped = frequentChannels.map((id) => callback(table[9])(id.id));
2026-08-11 06:20:06 +00:00
const found = mapped.filter(tmp(1370).isNotNullish);
2026-07-20 16:05:17 +00:00
const found1 = found.filter(isAllowedType);
if (null != queryMode) {
const items3 = [headerResult];
HermesBuiltin.arraySpread(found1.filter((type) => type.type === queryMode), 1);
let items4 = items3;
} else {
2026-07-29 08:29:29 +00:00
const intl2 = tmp(1236).intl;
2026-08-25 06:04:03 +00:00
items4 = [tmp(7452).createHeaderResult(intl2.string(tmp(1236).t["80lOZ1"])), , ];
2026-07-29 08:29:29 +00:00
let tmp13 = null;
if (null != selectedChannelId) {
2026-08-24 06:08:38 +00:00
const tmp7 = createAutocompleterResultForChannelIdDefault(selectedChannelId);
2026-07-29 08:29:29 +00:00
let tmp8 = null;
if (null != tmp7) {
let tmp9 = null;
if (isAllowedType(tmp7)) {
2026-08-25 06:04:03 +00:00
let canResult = tmp7.type === tmp(7452).AutocompleterResultTypes.USER;
2026-07-29 08:29:29 +00:00
if (!canResult) {
2026-08-24 06:08:38 +00:00
canResult = closure_6.can(constants.VIEW_CHANNEL, tmp7.record);
2026-07-29 08:29:29 +00:00
}
tmp9 = null;
if (canResult) {
tmp9 = tmp7;
}
}
tmp8 = tmp9;
}
tmp13 = tmp8;
}
items4[1] = tmp13;
items4[2] = headerResult;
2026-07-20 16:05:17 +00:00
HermesBuiltin.arraySpread(found1, 3);
2026-08-25 06:04:03 +00:00
const tmpResult = tmp(7452);
2026-07-20 16:05:17 +00:00
}
return mergeAndDedupeResultsWithHeaders(items4, items1);
}
2026-08-25 06:04:03 +00:00
const obj = queryMode(7452);
2026-07-20 16:05:17 +00:00
};