Files
discord-decomp/modules/messages/VoiceSessionUtils.tsx
T
2026-11-01 12:12:55 +02:00

80 lines
3.2 KiB
TypeScript

// Metro module 7846 (f7847).
import { useMemo } from "react";
import UserAffinitiesV2Store from "../user_affinities/UserAffinitiesV2Store";
import ChannelStore from "../../stores/ChannelStore";
import UserStore from "../../stores/UserStore";
import { maybeSortByProbability } from "../user_affinities/maybeSortByProbability";
import { useStateFromStoresArray, useStateFromStores } from "../../_bundle/Module589";
import getHumanizedCallDuration from "./getHumanizedCallDuration";
import { getMessageAuthor, getUserAuthor } from "./useMessageAuthor";
import { intl, t } from "../../intl/index.native";
import { identity } from "../../_bundle/Module12";
function $mk105478($env) {
return (a0, a1) => {
const user = $env.$parent[6].getUser(a1);
return user != null ? user.id !== $env[0].author.id ? [...a0, user] : a0 : a0;
};
}
let env4952 = {};
export function getSortedVoiceSessionParticipants(a0) {
let env16036;
const r3 = env16036 = {
$parent: env4952
};
env16036[0] = a0;
const call = a0.call;
let r7 = call == null ? void 0 : call.participants.reduce($mk105478(r3), []);
if (r7 == null) {
r7 = [];
}
return maybeSortByProbability(r7, UserAffinitiesV2Store.getUserAffinitiesMap(), "VoiceSessionUtils - participants");
}
export function useSortedVoiceSessionParticipants(a0) {
let stateFromStores;
const stateFromStoresArray = useStateFromStoresArray([UserStore], () => a0.call?.participants != null ? a0.call.participants.map((participant) => UserStore.getUser(participant)).filter((item) => item != null).filter((item) => item.id !== a0.author.id) : [], [a0.author.id, a0.call]);
stateFromStores = useStateFromStores([UserAffinitiesV2Store], () => UserAffinitiesV2Store.getUserAffinitiesMap(), []);
return useMemo(() => maybeSortByProbability(stateFromStoresArray, stateFromStores, "VoiceSessionUtils - participants"), [stateFromStoresArray, stateFromStores]);
}
export function getVoiceSessionMessageContent(a0) {
let r70;
let env16040;
const channel = ChannelStore.getChannel(a0.channel_id);
const humanizedCallDuration = getHumanizedCallDuration(a0);
const messageAuthor = getMessageAuthor(a0);
const r24 = env16040 = {
$parent: env4952
};
env16040[0] = a0;
const call = a0.call;
let r13 = call == null ? void 0 : call.participants.reduce($mk105478(r24), []);
if (r13 == null) {
r13 = [];
}
const r38 = maybeSortByProbability(r13, UserAffinitiesV2Store.getUserAffinitiesMap(), "VoiceSessionUtils - participants").map((item) => ({
user: item,
messageAuthor: getUserAuthor(item, channel)
}));
if (humanizedCallDuration == null) {
r70 = intl.formatToPlainString(t.HzBfIN, {
username: messageAuthor.nick,
usernameOnClick: identity
});
} else {
const atbXuX = t.atbXuX;
const r54 = r38[0];
const r61 = r38[1];
r70 = intl.formatToPlainString(atbXuX, {
userCount: r38.length + 1,
username: messageAuthor.nick,
usernameOnClick: identity,
username2: r54 == null ? void 0 : r54.messageAuthor.nick,
username2OnClick: identity,
username3: r61 == null ? void 0 : r61.messageAuthor.nick,
username3OnClick: identity,
otherCount: r38.length - 1,
duration: humanizedCallDuration
});
}
return r70;
}