435 lines
16 KiB
TypeScript
435 lines
16 KiB
TypeScript
// Metro module 7997 (f7998).
|
|
import AccessibilityStore from "../../a11y/AccessibilityStore";
|
|
import EmojiStore from "../../emojis/EmojiStore";
|
|
import ChannelStore from "../../../stores/ChannelStore";
|
|
import GuildMemberStore from "../../../stores/GuildMemberStore";
|
|
import MessageStore from "../../../stores/MessageStore";
|
|
import UserStore from "../../../stores/UserStore";
|
|
import { getPollState } from "../PollsInteractionStore";
|
|
import { MessageStates, EMPTY_STRING_SNOWFLAKE_ID } from "../../../Constants";
|
|
import { match } from "../../../_bundle/Module4389";
|
|
import UnicodeEmojis from "../../emojis/UnicodeEmojis";
|
|
import EmojiUtils from "../../../utils/EmojiUtils";
|
|
import AvatarUtils from "../../../utils/AvatarUtils";
|
|
import { formatExpirationLabel } from "./useFormattedExpirationLabel";
|
|
import * as _AutomodPermissionUtils from "../../guild_automod/AutomodPermissionUtils";
|
|
import * as _CommunicationDisabledUtils from "../../guild_communication_disabled/CommunicationDisabledUtils";
|
|
import { getAvatarUrl } from "./buildPlatformPollResources.native";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
import { getTotalVotes } from "../PollsUtils";
|
|
import { PollLayoutTypes } from "../../../_bundle/Module8002";
|
|
import { isIOS } from "../../../utils/PlatformUtils";
|
|
import { PollChatAnswerInteractionType } from "./PollMessageChatDataTypes";
|
|
import buildPollResources from "./buildPollResources";
|
|
let c5060_11, computeBasicPollChatData;
|
|
const reactionForId = function reactionForId(reactions, a1) {
|
|
for (const item of reactions) {
|
|
if ((typeof item.emoji.id === "number" ? `${item.emoji.id}` : item.emoji.id) !== a1) {
|
|
continue;
|
|
}
|
|
return item;
|
|
}
|
|
};
|
|
computeBasicPollChatData = function computeBasicPollChatData(a0, a1, r7 = {}) {
|
|
let formattedExpirationLabel = r7.formattedExpirationLabel;
|
|
const poll = a0.poll;
|
|
if (poll != null) {
|
|
const isSent = a0.state === MessageStates.SENT;
|
|
let expirationLabel = "";
|
|
if (isSent) {
|
|
if (formattedExpirationLabel == null) {
|
|
formattedExpirationLabel = formatExpirationLabel(poll.expiry);
|
|
}
|
|
expirationLabel = formattedExpirationLabel;
|
|
}
|
|
const isExpired2 = expirationLabel == null && isSent;
|
|
let r31 = a1 == null ? getPollState(a0.getChannelId(), a0.id) : a1;
|
|
if (r31 == null) {
|
|
r31 = c5060_11;
|
|
}
|
|
const { selectedAnswerIds: selectedAnswerIds2, submitting: submitting2, editing, showResults: showResults2 } = r31;
|
|
const reactions2 = a0.reactions;
|
|
const r2 = a0.poll == null || MessageStore.getMessage(a0.channel_id, a0.id) === a0;
|
|
let isInteractive = true;
|
|
let r42 = reactions2;
|
|
if (!r2) {
|
|
const message = MessageStore.getMessage(a0.channel_id, a0.id);
|
|
const isSearchHit = a0.isSearchHit;
|
|
const r48 = isSearchHit ? !isSearchHit : message != null;
|
|
let r49 = message?.reactions;
|
|
if (r49 == null) {
|
|
r49 = reactions2;
|
|
}
|
|
r42 = r49;
|
|
isInteractive = r48;
|
|
}
|
|
const hasSelectedAnswer2 = selectedAnswerIds2.size > 0;
|
|
const hasVoteRecorded = r42.some((item) => item.me_vote === true);
|
|
let hasVoted2 = !editing;
|
|
const reactions3 = r42;
|
|
if (!editing) {
|
|
hasVoted2 = hasVoteRecorded;
|
|
}
|
|
const canShowVoteCounts = (hasVoted2 ? hasVoted2 : isExpired2) || showResults2;
|
|
const canTapAnswers = (isSent ? isInteractive : isSent) && ((hasVoteRecorded ? editing : !hasVoteRecorded) || canShowVoteCounts);
|
|
const channel = ChannelStore.getChannel(a0.getChannelId());
|
|
const r63 = channel == null;
|
|
let r64 = void 0;
|
|
if (!r63) {
|
|
const getGuildId = channel.getGuildId;
|
|
r64 = getGuildId == null ? void 0 : getGuildId.call(channel);
|
|
}
|
|
const r68 = r64 != null ? GuildMemberStore.getSelfMember(r64) : null;
|
|
const hasAutomodQuarantinedProfile = _AutomodPermissionUtils.hasAutomodQuarantinedProfile(r68);
|
|
const isMemberCommunicationDisabled = _CommunicationDisabledUtils.isMemberCommunicationDisabled(r68);
|
|
return {
|
|
poll,
|
|
canTapAnswers,
|
|
canRemoveVote: hasVoted2 && isSent && !isExpired2,
|
|
canShowVoteCounts,
|
|
canSubmitVote: (submitting2 ? !submitting2 : hasSelectedAnswer2) && !hasVoted2 && isSent && !hasAutomodQuarantinedProfile && !isMemberCommunicationDisabled,
|
|
expirationLabel,
|
|
hasSelectedAnswer: hasSelectedAnswer2,
|
|
hasVoted: hasVoted2,
|
|
hasVoteRecorded,
|
|
isEditingVote: editing,
|
|
isExpired: isExpired2,
|
|
isInteractive,
|
|
isSent,
|
|
reactions: reactions3,
|
|
selectedAnswerIds: selectedAnswerIds2,
|
|
submitting: submitting2,
|
|
tapShouldOpenVotersModal: canShowVoteCounts,
|
|
showResults: showResults2
|
|
};
|
|
}
|
|
};
|
|
c5060_11 = {
|
|
channelId: EMPTY_STRING_SNOWFLAKE_ID,
|
|
selectedAnswerIds: new Set(),
|
|
submitting: false,
|
|
editing: false,
|
|
showResults: false
|
|
};
|
|
export default function formatPollMessageChatData(a0, a1, r4 = {}) {
|
|
let animateEmoji2 = r4.animateEmoji;
|
|
if (animateEmoji2 === void 0) {
|
|
animateEmoji2 = false;
|
|
}
|
|
let useReducedMotion, layout_type, canSubmitVote, secondaryLabel, hasSelectedAnswer, hasVoted, isExpired, reactions, selectedAnswerIds, submitting, showResults, totalVotes, label, c16156_14, accessibilityHint;
|
|
const animateEmoji = animateEmoji2;
|
|
const { theme = "dark", formattedExpirationLabel } = r4;
|
|
useReducedMotion = void 0;
|
|
layout_type = void 0;
|
|
canSubmitVote = void 0;
|
|
secondaryLabel = void 0;
|
|
hasSelectedAnswer = void 0;
|
|
hasVoted = void 0;
|
|
isExpired = void 0;
|
|
reactions = void 0;
|
|
selectedAnswerIds = void 0;
|
|
submitting = void 0;
|
|
showResults = void 0;
|
|
totalVotes = void 0;
|
|
label = void 0;
|
|
c16156_14 = void 0;
|
|
accessibilityHint = void 0;
|
|
const poll = a0.poll;
|
|
if (poll != null) {
|
|
const currentUser = UserStore.getCurrentUser();
|
|
if (currentUser != null) {
|
|
useReducedMotion = AccessibilityStore.useReducedMotion;
|
|
const channel = ChannelStore.getChannel(a0.getChannelId());
|
|
const r3 = channel == null;
|
|
let r40 = void 0;
|
|
if (!r3) {
|
|
const getGuildId = channel.getGuildId;
|
|
r40 = getGuildId == null ? void 0 : getGuildId.call(channel);
|
|
}
|
|
const avatarUrl = getAvatarUrl(currentUser, r40);
|
|
const answers = poll.answers;
|
|
layout_type = poll.layout_type;
|
|
const r49 = computeBasicPollChatData(a0, a1, {
|
|
formattedExpirationLabel
|
|
});
|
|
if (r49 != null) {
|
|
const { canTapAnswers, canRemoveVote, canShowVoteCounts } = r49;
|
|
canSubmitVote = r49.canSubmitVote;
|
|
let expirationLabel = r49.expirationLabel;
|
|
if (expirationLabel === void 0) {
|
|
expirationLabel = intl.string(t["e+J3JZ"]);
|
|
}
|
|
secondaryLabel = expirationLabel;
|
|
hasSelectedAnswer = r49.hasSelectedAnswer;
|
|
hasVoted = r49.hasVoted;
|
|
const isEditingVote = r49.isEditingVote;
|
|
isExpired = r49.isExpired;
|
|
const isInteractive = r49.isInteractive;
|
|
reactions = r49.reactions;
|
|
selectedAnswerIds = r49.selectedAnswerIds;
|
|
submitting = r49.submitting;
|
|
const tapShouldOpenVotersModal = r49.tapShouldOpenVotersModal;
|
|
showResults = r49.showResults;
|
|
totalVotes = getTotalVotes(reactions);
|
|
label = intl.formatToPlainString(t.XRkuof, {
|
|
count: totalVotes
|
|
});
|
|
const r78 = Math;
|
|
c16156_14 = r78.max.apply(r78, [...answers.map((answer) => {
|
|
const r15 = reactionForId(reactions, `${answer.answer_id}`);
|
|
let r16 = r15 == null ? void 0 : r15.count_details?.vote;
|
|
if (r16 == null) {
|
|
r16 = 0;
|
|
}
|
|
return r16;
|
|
})]);
|
|
const answers2 = answers.map((answer) => {
|
|
const answerId = `${answer.answer_id}`;
|
|
const r9 = reactionForId(reactions, answerId);
|
|
let r32 = r9 == null ? void 0 : r9.count_details?.vote;
|
|
if (r32 == null) {
|
|
r32 = 0;
|
|
}
|
|
const count = r32;
|
|
const r13 = totalVotes !== 0 ? count / totalVotes : 0;
|
|
const isSelected = selectedAnswerIds.has(answerId);
|
|
const isLeader = count >= c16156_14 && count !== 0;
|
|
let didSelfVote = hasVoted;
|
|
if (hasVoted) {
|
|
let r40 = r9?.me_vote;
|
|
if (r40 == null) {
|
|
r40 = false;
|
|
}
|
|
didSelfVote = r40;
|
|
}
|
|
let isVictor = isExpired;
|
|
const style = match({
|
|
didSelfVote,
|
|
hasVoted,
|
|
isExpired,
|
|
isSelected,
|
|
isLeader,
|
|
showResults
|
|
}).with({
|
|
isExpired: true,
|
|
isLeader: true,
|
|
didSelfVote: true
|
|
}, () => "victorSelected").with({
|
|
isExpired: true,
|
|
isLeader: true,
|
|
didSelfVote: false
|
|
}, () => "victorNotSelected").with({
|
|
isExpired: true,
|
|
didSelfVote: true
|
|
}, () => "loserSelected").with({
|
|
isExpired: true
|
|
}, () => "notVoted").with({
|
|
didSelfVote: true,
|
|
isExpired: false
|
|
}, () => "voted").with({
|
|
hasVoted: true,
|
|
isExpired: false
|
|
}, () => "notVoted").with({
|
|
isSelected: true
|
|
}, () => "selected").with({
|
|
isExpired: false,
|
|
showResults: true
|
|
}, () => "notVoted").otherwise(() => "normalVote");
|
|
const emoji = answer.poll_media.emoji;
|
|
const r88 = {
|
|
animateEmoji
|
|
};
|
|
let animateEmoji2 = r88.animateEmoji;
|
|
if (animateEmoji2 === void 0) {
|
|
animateEmoji2 = false;
|
|
}
|
|
let size = r88.size;
|
|
if (size === void 0) {
|
|
size = 48;
|
|
}
|
|
const r89 = emoji != null;
|
|
let emoji2 = void 0;
|
|
if (r89) {
|
|
let animated = emoji.animated;
|
|
if (animated == null && emoji.id != null) {
|
|
let r96 = EmojiStore.getCustomEmojiById(emoji.id)?.animated;
|
|
if (r96 == null) {
|
|
r96 = false;
|
|
}
|
|
animated = r96;
|
|
}
|
|
if (animateEmoji2) {
|
|
if (animated == null) {
|
|
animated = false;
|
|
}
|
|
animateEmoji2 = animated;
|
|
}
|
|
emoji2 = {
|
|
id: emoji.id == null ? null : `${emoji.id}`,
|
|
name: emoji.name,
|
|
displayName: emoji.id == null ? UnicodeEmojis.convertSurrogateToName(emoji.name) : emoji.name,
|
|
src: emoji.id == null ? EmojiUtils.getURL(emoji.name) : AvatarUtils.getEmojiURL({
|
|
id: emoji.id,
|
|
animated: animateEmoji2,
|
|
size
|
|
}),
|
|
animated: animateEmoji2
|
|
};
|
|
}
|
|
const pollMedia = {
|
|
text: answer.poll_media.text,
|
|
emoji: emoji2,
|
|
stickerId: answer.poll_media.sticker_id,
|
|
attachmentIds: answer.poll_media.attachment_ids
|
|
};
|
|
if (isExpired) {
|
|
isVictor = isLeader;
|
|
}
|
|
let shouldAnimateTransition = submitting;
|
|
if (submitting) {
|
|
shouldAnimateTransition = !useReducedMotion;
|
|
}
|
|
return {
|
|
answerId,
|
|
pollMedia,
|
|
isSelected,
|
|
isVictor,
|
|
didSelfVote,
|
|
style,
|
|
shouldAnimateTransition,
|
|
votesPercentage: Math.round(100 * r13),
|
|
votes: match(layout_type).with(PollLayoutTypes.IMAGE_ONLY_ANSWERS, () => `(${count.toLocaleString()})`).otherwise(() => intl.formatToPlainString(t.XRkuof, {
|
|
count
|
|
}))
|
|
};
|
|
});
|
|
const primaryAction = match({
|
|
isExpired,
|
|
canSubmitVote,
|
|
hasVoted,
|
|
isEditingVote,
|
|
canRemoveVote,
|
|
isInteractive,
|
|
showResults
|
|
}).with({
|
|
isInteractive: false
|
|
}, () => {}).with({
|
|
isExpired: true
|
|
}, () => {}).with({
|
|
isEditingVote: true
|
|
}, () => ({
|
|
label: intl.string(t.JwkNU4),
|
|
presentation: "button",
|
|
enabled: hasSelectedAnswer,
|
|
type: "submit"
|
|
})).with({
|
|
canRemoveVote: true
|
|
}, () => ({
|
|
label: intl.string(t.XhQEh8),
|
|
presentation: "secondaryButton",
|
|
enabled: true,
|
|
type: "remove"
|
|
})).with({
|
|
hasVoted: false,
|
|
showResults: true
|
|
}, () => ({
|
|
label: intl.string(t.gNj6In),
|
|
presentation: "secondaryButton",
|
|
enabled: true,
|
|
type: "showVotes"
|
|
})).otherwise(() => ({
|
|
label: intl.string(t.JwkNU4),
|
|
presentation: "button",
|
|
enabled: canSubmitVote,
|
|
type: "submit"
|
|
}));
|
|
accessibilityHint = isIOS() ? intl.string(t["PVATM/"]) : intl.string(t.cHfFql);
|
|
const secondaryAction = match({
|
|
isExpired,
|
|
isInteractive,
|
|
isEditingVote
|
|
}).with({
|
|
isInteractive: false,
|
|
isExpired: false
|
|
}, () => ({
|
|
label: intl.string(t.trrip0),
|
|
presentation: "text",
|
|
enabled: false
|
|
})).with({
|
|
isEditingVote: true
|
|
}, () => ({
|
|
label: intl.string(t["ETE/oC"]),
|
|
presentation: "textButton",
|
|
enabled: true,
|
|
type: "cancel"
|
|
})).otherwise(() => ({
|
|
label,
|
|
secondaryLabel,
|
|
accessibilityHint,
|
|
presentation: "text",
|
|
enabled: true,
|
|
type: "showVoterDetails"
|
|
}));
|
|
const tertiaryAction = isInteractive ? isExpired ? void 0 : hasVoted ? void 0 : showResults ? void 0 : {
|
|
label: intl.string(t["/KHAUF"]),
|
|
presentation: "textButton",
|
|
enabled: true,
|
|
type: "showVotes"
|
|
} : void 0;
|
|
const allow_multiselect = poll.allow_multiselect;
|
|
return {
|
|
question: poll.question,
|
|
promptLabel: match({
|
|
isInteractive,
|
|
isExpired,
|
|
canSelectMultipleAnswers: allow_multiselect
|
|
}).with({
|
|
isInteractive: false
|
|
}, () => {}).with({
|
|
isExpired: true
|
|
}, () => {}).with({
|
|
canSelectMultipleAnswers: true
|
|
}, () => intl.string(t.yCXvxa)).otherwise(() => intl.string(t["9Y2wKO"])),
|
|
answers: answers2,
|
|
answersInteraction: match({
|
|
tapShouldOpenVotersModal,
|
|
canTapAnswers,
|
|
canSelectMultipleAnswers: allow_multiselect
|
|
}).with({
|
|
tapShouldOpenVotersModal: true
|
|
}, () => PollChatAnswerInteractionType.LIST).with({
|
|
canTapAnswers: false
|
|
}, () => PollChatAnswerInteractionType.LIST).with({
|
|
canSelectMultipleAnswers: false
|
|
}, () => PollChatAnswerInteractionType.RADIO_BUTTONS).with({
|
|
canSelectMultipleAnswers: true
|
|
}, () => PollChatAnswerInteractionType.CHECKBOXES).exhaustive(),
|
|
answerTapAccessibilityLabel: tapShouldOpenVotersModal ? accessibilityHint : void 0,
|
|
layoutType: layout_type,
|
|
resources: buildPollResources({
|
|
theme,
|
|
layoutType: layout_type
|
|
}),
|
|
containerStyle: "normal",
|
|
primaryAction,
|
|
isInteractive,
|
|
canTapAnswers,
|
|
canSelectMultipleAnswers: allow_multiselect,
|
|
hasSelectedAnswer,
|
|
canShowVoteCounts,
|
|
hasVoted,
|
|
isExpired,
|
|
myAvatarUrl: avatarUrl,
|
|
secondaryAction,
|
|
tertiaryAction
|
|
};
|
|
}
|
|
}
|
|
}
|
|
};
|
|
export { reactionForId };
|
|
export function isPollMessageDirectlyInteractive(a0) {
|
|
return a0.poll == null || MessageStore.getMessage(a0.channel_id, a0.id) === a0;
|
|
}
|
|
export { computeBasicPollChatData };
|