236 lines
8.3 KiB
TypeScript
236 lines
8.3 KiB
TypeScript
// Metro module 6072 (f6073).
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import MessageReactionsStore from "../../stores/MessageReactionsStore";
|
|
import MessageStore from "../../stores/MessageStore";
|
|
import PermissionStore from "../../stores/PermissionStore";
|
|
import RelationshipStore from "../../stores/RelationshipStore";
|
|
import { POLL_RESULT_MESSAGE_POLL_TITLE_MAX_VISIBLE_CHARS, VOTES_TOOLTIP_MAX_USERS } from "./PollsConstants";
|
|
import { ChannelTypesSets, Permissions } from "../../Constants";
|
|
import { v4 } from "../../_bundle/Module514";
|
|
import { useStateFromStores } from "../../_bundle/Module589";
|
|
import { FAKE_PLACEHOLDER_PRIVATE_CHANNEL_ID } from "../channel/FakePlaceholderPrivateChannel";
|
|
import Durations from "../../utils/Durations";
|
|
import { truncateText } from "../../_bundle/Module1857";
|
|
import { getMessageAuthor } from "../messages/useMessageAuthor";
|
|
import { intl, t } from "../../intl/index.native";
|
|
import { ReactionTypes } from "../messages/MessageReactionsTypes";
|
|
import Module12 from "../../_bundle/Module12";
|
|
import NicknameUtils from "../../utils/NicknameUtils";
|
|
function $mk77708() {
|
|
return (a0) => a0.rawName === "poll_question_text";
|
|
}
|
|
let formatVoterTooltipText;
|
|
const getSampleOfVoterUsernamesForAnswer = function getSampleOfVoterUsernamesForAnswer(message, a1) {
|
|
const channelId = message.getChannelId();
|
|
const reactions = MessageReactionsStore.getReactions(channelId, message.id, {
|
|
id: a1,
|
|
name: "",
|
|
animated: false
|
|
}, VOTES_TOOLTIP_MAX_USERS, ReactionTypes.VOTE);
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
const guildId = channel == null ? null : channel.isPrivate() ? null : channel.getGuildId();
|
|
const r37 = Array;
|
|
let r40 = reactions == null ? void 0 : reactions.values();
|
|
if (r40 == null) {
|
|
r40 = [];
|
|
}
|
|
return Module12(r37.from(r40)).reject((a0) => RelationshipStore.isBlockedOrIgnored(a0.id)).take(VOTES_TOOLTIP_MAX_USERS).map((item) => NicknameUtils.getName(guildId, channel?.id, item)).value();
|
|
};
|
|
formatVoterTooltipText = function formatVoterTooltipText(sampleOfVoterUsernamesForAnswer, a1) {
|
|
const r9 = Math.max(0, a1 - sampleOfVoterUsernamesForAnswer.length);
|
|
return sampleOfVoterUsernamesForAnswer.length === 1 ? r9 > 0 ? intl.formatToPlainString(t["SV/iZn"], {
|
|
a: sampleOfVoterUsernamesForAnswer[0],
|
|
n: r9
|
|
}) : sampleOfVoterUsernamesForAnswer[0] : sampleOfVoterUsernamesForAnswer.length === 2 ? r9 > 0 ? intl.formatToPlainString(t.YBnZK0, {
|
|
a: sampleOfVoterUsernamesForAnswer[0],
|
|
b: sampleOfVoterUsernamesForAnswer[1],
|
|
n: r9
|
|
}) : intl.formatToPlainString(t["O5+f5c"], {
|
|
a: sampleOfVoterUsernamesForAnswer[0],
|
|
b: sampleOfVoterUsernamesForAnswer[1]
|
|
}) : sampleOfVoterUsernamesForAnswer.length === 3 ? r9 > 0 ? intl.formatToPlainString(t["ThXp+N"], {
|
|
a: sampleOfVoterUsernamesForAnswer[0],
|
|
b: sampleOfVoterUsernamesForAnswer[1],
|
|
c: sampleOfVoterUsernamesForAnswer[2],
|
|
n: r9
|
|
}) : intl.formatToPlainString(t["0UzBM3"], {
|
|
a: sampleOfVoterUsernamesForAnswer[0],
|
|
b: sampleOfVoterUsernamesForAnswer[1],
|
|
c: sampleOfVoterUsernamesForAnswer[2]
|
|
}) : intl.formatToPlainString(t.yVX6kE, {
|
|
n: r9
|
|
});
|
|
};
|
|
export function generateEmptyPollAnswer() {
|
|
return {
|
|
text: void 0,
|
|
image: void 0,
|
|
localCreationAnswerId: v4()
|
|
};
|
|
}
|
|
export function generateLocalCreationAnswerId() {
|
|
return v4();
|
|
}
|
|
export function filterOutUUID(a0) {
|
|
return a0.replace(/\b[a-f\d]{8}-(?:[a-f\d]{4}-){3}[a-f\d]{12}-\b/i, "");
|
|
}
|
|
export function hasNonVoteReactions(a0) {
|
|
for (const reaction of a0.reactions) {
|
|
if (reaction.me_vote != null) {
|
|
continue;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
export function useCanPostPollsInChannel(c15459_0) {
|
|
return useStateFromStores([PermissionStore], () => c15459_0 != null && c15459_0.id !== FAKE_PLACEHOLDER_PRIVATE_CHANNEL_ID && (!!ChannelTypesSets.POLLS.has(c15459_0.type) && (!!c15459_0.isPrivate() || PermissionStore.can(Permissions.SEND_MESSAGES, c15459_0) && PermissionStore.can(Permissions.SEND_POLLS, c15459_0))));
|
|
}
|
|
export function isPollCreationEmpty(a0, a1) {
|
|
return a0.length === 0 && a1.find(({ text }) => {
|
|
const r6 = text == null ? void 0 : text.trim();
|
|
return r6 != null && r6.length > 0;
|
|
}) == null;
|
|
}
|
|
export function isAnswerFilled({ text }) {
|
|
const r6 = text == null ? void 0 : text.trim();
|
|
return r6 != null && r6.length > 0;
|
|
}
|
|
export function isIncompleteAnswer(a0) {
|
|
const text = a0.text;
|
|
const r4 = text == null ? void 0 : text.trim();
|
|
return a0.image != null && (r4 == null || r4.length === 0);
|
|
}
|
|
export function createPollExpiryTimestamp(a0) {
|
|
return new Date(Date.now() + a0 * Durations.Millis.HOUR).toISOString();
|
|
}
|
|
export function createPollServerDataFromCreateRequest(a0) {
|
|
if (a0 != null) {
|
|
const r2 = a0 == null;
|
|
let answers2 = void 0;
|
|
if (!r2) {
|
|
const answers = a0.answers;
|
|
answers2 = answers == null ? void 0 : answers.map((answer, index) => {
|
|
const emoji = answer.poll_media?.emoji;
|
|
const r12 = emoji != null;
|
|
let emoji2 = void 0;
|
|
if (r12) {
|
|
let name = emoji.name;
|
|
if (name == null) {
|
|
name = "";
|
|
}
|
|
emoji2 = {
|
|
id: emoji.id,
|
|
name
|
|
};
|
|
}
|
|
return {
|
|
...answer,
|
|
answer_id: index + 1,
|
|
poll_media: {
|
|
...answer.poll_media,
|
|
emoji: emoji2
|
|
}
|
|
};
|
|
});
|
|
}
|
|
const r18 = a0?.duration != null;
|
|
let expiry = "0";
|
|
if (r18) {
|
|
const duration = a0.duration;
|
|
expiry = new Date(Date.now() + duration * Durations.Millis.HOUR).toISOString();
|
|
}
|
|
return {
|
|
...a0,
|
|
expiry,
|
|
answers: answers2
|
|
};
|
|
}
|
|
}
|
|
export function getPollReplyPreview({ poll }) {
|
|
let r5 = poll == null ? void 0 : poll.question?.text;
|
|
if (r5 == null) {
|
|
r5 = "";
|
|
}
|
|
return r5;
|
|
}
|
|
export function getPollResultsReplyPreview(a0) {
|
|
const messageAuthor = getMessageAuthor(a0);
|
|
const r14 = a0.embeds[0];
|
|
const r2 = r14 == null;
|
|
let r9 = void 0;
|
|
if (!r2) {
|
|
const fields = r14.fields;
|
|
r9 = fields == null ? void 0 : fields.find($mk77708())?.rawValue;
|
|
}
|
|
if (r9 == null) {
|
|
r9 = "";
|
|
}
|
|
return intl.format(t.Vn97Ka, {
|
|
username: messageAuthor.nick,
|
|
title: POLL_RESULT_MESSAGE_POLL_TITLE_MAX_VISIBLE_CHARS != null ? truncateText(r9, POLL_RESULT_MESSAGE_POLL_TITLE_MAX_VISIBLE_CHARS) : r9
|
|
});
|
|
}
|
|
export function getPollResultsReplyPreviewMobile(a0) {
|
|
if ("author" in a0) {
|
|
const messageAuthor = getMessageAuthor(a0);
|
|
const r17 = a0.embeds[0];
|
|
const r2 = r17 == null;
|
|
let r9 = void 0;
|
|
if (!r2) {
|
|
const fields = r17.fields;
|
|
r9 = fields == null ? void 0 : fields.find($mk77708())?.rawValue;
|
|
}
|
|
if (r9 == null) {
|
|
r9 = "";
|
|
}
|
|
return intl.formatToParts(t.Vn97Ka, {
|
|
username: messageAuthor.nick,
|
|
title: POLL_RESULT_MESSAGE_POLL_TITLE_MAX_VISIBLE_CHARS != null ? truncateText(r9, POLL_RESULT_MESSAGE_POLL_TITLE_MAX_VISIBLE_CHARS) : r9
|
|
});
|
|
}
|
|
return null;
|
|
}
|
|
export function getTotalVotes(a0) {
|
|
return a0.reduce((acc, item) => {
|
|
let r4 = item.count_details?.vote;
|
|
if (r4 == null) {
|
|
r4 = 0;
|
|
}
|
|
return acc + r4;
|
|
}, 0);
|
|
}
|
|
export { getSampleOfVoterUsernamesForAnswer };
|
|
export { formatVoterTooltipText };
|
|
export function getPollAnswerVotesTooltipText(a0, a1, a2) {
|
|
const message = MessageStore.getMessage(a1, a0);
|
|
if (message == null) {
|
|
return "";
|
|
}
|
|
const reaction = message.getReaction({
|
|
id: a2,
|
|
name: "",
|
|
animated: false
|
|
});
|
|
let r14 = reaction == null ? void 0 : reaction.count_details?.vote;
|
|
if (r14 == null) {
|
|
r14 = 0;
|
|
}
|
|
const sampleOfVoterUsernamesForAnswer = getSampleOfVoterUsernamesForAnswer(message, a2);
|
|
return sampleOfVoterUsernamesForAnswer.length !== 0 ? formatVoterTooltipText(sampleOfVoterUsernamesForAnswer, r14) : "";
|
|
}
|
|
export function formatPollResultNotificationCenterText(a0) {
|
|
const { questionText, victorAnswerText, victorAnswerVotes, victorAnswerId, totalVotes } = a0;
|
|
const r13 = a0.totalVotes > 0 ? Math.round(victorAnswerVotes / totalVotes * 100) : 0;
|
|
return totalVotes === 0 ? intl.formatToPlainString(t["8anM0l"], {
|
|
questionText
|
|
}) : victorAnswerId != null ? intl.formatToPlainString(t["8yEgvE"], {
|
|
questionText,
|
|
victorAnswerText,
|
|
percentage: `${r13}%`
|
|
}) : intl.formatToPlainString(t.XVk6Zv, {
|
|
questionText,
|
|
percentage: `${r13}%`
|
|
});
|
|
}
|