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

611 lines
17 KiB
TypeScript

// Metro module 6075 (f6076).
import _asyncToGenerator from "../../_bundle/_asyncToGenerator";
import AuthenticationStore from "../../stores/AuthenticationStore";
import ChannelStore from "../../stores/ChannelStore";
import MessageStore from "../../stores/MessageStore";
import { Endpoints, AnalyticEvents, AbortCodes, ComponentActions } from "../../Constants";
import Durations from "../../utils/Durations";
import AlertActionCreators from "../../actions/AlertActionCreators";
import * as _index_native from "../../intl/index.native";
import { t } from "../../intl/index.native";
import { ComponentDispatch } from "../../utils/ComponentDispatchUtils";
import Dispatcher from "../../Dispatcher";
import { ReactionTypes } from "../messages/MessageReactionsTypes";
import { rejectWithMigratedError, HTTP } from "../../_bundle/sendRequest";
import ThreadActionCreators from "../threads/ThreadActionCreators";
import AnalyticsUtils from "../../utils/AnalyticsUtils";
import { collectGuildAnalyticsMetadata, collectChannelAnalyticsMetadata } from "../app_analytics/AppAnalyticsUtils";
import * as _shared from "../../design/shared";
import EmojiUtilsPlatformed_native from "../../utils/EmojiUtilsPlatformed.native";
import { getEmojiColors } from "../../utils/EmojiUtils";
function $mk114858($env) {
return function makeURLForVoteReactors(a0, a1, a2) {
let id = a2.id;
if (id == null) {
id = a2.name;
}
return Endpoints.POLL_ANSWER_VOTERS(a0, a1, id);
};
}
function $mk114859($env) {
return () => {
const r6 = $env;
if (r6[3] === "Message Shortcut") {
const channel_id = r6[0];
const channel = ChannelStore.getChannel(channel_id);
const MESSAGE_SHORTCUT_ACTION_SENT = AnalyticEvents.MESSAGE_SHORTCUT_ACTION_SENT;
const guild_id = channel?.guild_id;
const r11 = r6[2];
let id = r11.id;
if (id == null) {
id = r11.name;
}
AnalyticsUtils.track(MESSAGE_SHORTCUT_ACTION_SENT, {
channel_id,
guild_id,
original_message_id: r6[1],
emoji_id: id,
action: "react",
...collectGuildAnalyticsMetadata(channel?.guild_id),
...collectChannelAnalyticsMetadata(channel)
});
}
const r43 = r6[5];
if (r43) {
const r69 = t["RJlG+R"];
const r70 = r6[2];
_shared.AccessibilityAnnouncer.announce(_index_native.intl.formatToPlainString(r69, {
name: r70.name
}));
EmojiUtilsPlatformed_native.triggerFullscreenAnimation({
channelId: r6[0],
messageId: r6[1],
emoji: {
...r70,
animated: false
}
});
} else {
_shared.AccessibilityAnnouncer.announce(_index_native.intl.formatToPlainString(t.ol4acF, {
name: r6[2].name
}));
}
};
}
function $mk114860($env) {
return (a0) => {
let r33, BURST;
const r4 = $env;
const r6 = {
isRetry: r4[6]
};
if (checkReactionResponse(a0, $mk117948(r4), r6)) {
const channelId = r4[0];
const messageId = r4[1];
const emoji = r4[2];
const r16 = {
burst: r4[5]
};
let userId2 = r16.userId;
if (userId2 == null) {
userId2 = AuthenticationStore.getId();
}
let colors = r16.colors;
if (colors == null) {
colors = [];
}
if (r16.burst) {
BURST = ReactionTypes.BURST;
r33 = require;
} else {
BURST = ReactionTypes.NORMAL;
r33 = require;
}
Dispatcher.dispatch({
type: "MESSAGE_REACTION_REMOVE",
channelId,
messageId,
userId: userId2,
emoji,
optimistic: true,
colors,
reactionType: BURST
});
const r35 = r4[5];
const AccessibilityAnnouncer = r33(dependencyMap[15]).AccessibilityAnnouncer;
const intl = r33(dependencyMap[7]).intl;
const r46 = r33(dependencyMap[7]).t;
if (r35) {
AccessibilityAnnouncer.announce(intl.formatToPlainString(r46.fJeu87, {
name: emoji.name
}));
} else {
AccessibilityAnnouncer.announce(intl.formatToPlainString(r46["UUn5V+"], {
name: emoji.name
}));
}
}
};
}
function $mk114861($env) {
return (a0) => {
const r2 = $env;
const r4 = {
isRetry: r2[2]
};
checkReactionResponse(a0, $mk117949(r2), r4);
};
}
function $mk114862($env) {
return (a0) => {
const r2 = $env;
const r4 = {
isRetry: r2[3]
};
checkReactionResponse(a0, $mk117950(r2), r4);
};
}
function $mk114863($env) {
return () => {
const r8 = $env;
const burst = r8[5]?.burst;
if (burst) {
_shared.AccessibilityAnnouncer.announce(_index_native.intl.formatToPlainString(t["3l9f6u"], {
name: r8[2].name
}));
} else {
_shared.AccessibilityAnnouncer.announce(_index_native.intl.formatToPlainString(t["DQxi+7"], {
name: r8[2].name
}));
}
};
}
function $mk114864($env) {
return function() {
let env31389 = {
$parent: $env
};
env31389[0] = (0, _asyncToGenerator)(function*(c31947_0) {
let c31947_1, c31947_2;
L17: {
let env32121;
c31947_2 = env31389;
const r8 = env31389.$parent;
const r10 = env32121 = {
$parent: r8
};
c31947_1 = r10;
env32121[0] = void 0;
const r31 = env31389.$parent.$parent;
const r13 = r31[12];
const r12 = {
isRetry: r8[7]
};
if (r13(c31947_0, $mk119027(r8), r12)) {
const r45 = yield (0, r31[24])(r8[2], r8[6]);
const r54 = c31947_2;
env32121[0] = r45;
const r56 = r54.$parent.$parent[13];
const r57 = r54.$parent;
r56("MESSAGE_REACTION_ADD", r57[0], r57[1], r57[2], {
userId: r57[4],
burst: r57[6],
colors: env32121[0]
});
const burst = r57[5]?.burst;
const r67 = c31947_2;
const r68 = r67.$parent.$parent;
const AccessibilityAnnouncer = (0, r68[0])(r68[2][15]).AccessibilityAnnouncer;
const intl = (0, r68[0])(r68[2][7]).intl;
const r85 = (0, r68[0])(r68[2][7]).t;
if (burst) {
AccessibilityAnnouncer.announce(intl.formatToPlainString(r85.OamVbV, {
name: r67.$parent[2].name
}));
break L17;
}
AccessibilityAnnouncer.announce(intl.formatToPlainString(r85["tD9+b+"], {
name: r67.$parent[2].name
}));
break L17;
}
return void 0;
}
});
return function() {
return env31389[0].apply(this, arguments);
};
};
}
function $mk117948($env) {
return () => {
const r7 = $env;
return (0, addReaction)(r7[0], r7[1], r7[2], r7[3], {
burst: r7[5],
isRetry: true
});
};
}
function $mk117949($env) {
return () => {
const r1 = $env;
return (0, removeAllReactions)(r1[0], r1[1], {
isRetry: true
});
};
}
function $mk117950($env) {
return () => {
const r1 = $env;
return (0, removeEmojiReactions)(r1[0], r1[1], r1[2], {
isRetry: true
});
};
}
function $mk119027($env) {
return () => {
const r4 = $env;
return (0, $env.$parent[22])({
channelId: r4[0],
messageId: r4[1],
emoji: r4[2],
location: r4[3],
userId: r4[4],
options: {
burst: r4[6],
isRetry: true
}
});
};
}
let optimisticDispatch, makeURL, addReaction, removeAllReactions, removeEmojiReactions, removeReaction, getOptimisticEmojiColors, hasUserAlreadyReacted, c3854_11;
let env3854 = {};
const checkReactionResponse = function checkReactionResponse({ headers, status, body }, a1, a2) {
if (status === 429) {
if (a2.isRetry) {
return true;
}
const r70 = parseInt(headers["retry-after"]);
if (!isNaN(r70)) {
setTimeout(a1, r70 * Durations.Millis.SECOND);
}
return false;
}
if (status === 403) {
const r19 = body && body.code;
if (AbortCodes.TOO_MANY_REACTIONS === r19) {
AlertActionCreators.show({
title: _index_native.intl.string(t.lFddsR),
body: _index_native.intl.string(t.h27eIm),
confirmText: _index_native.intl.string(t.BddRzS)
});
} else if (AbortCodes.REACTION_BLOCKED === r19) {
ComponentDispatch.dispatch(ComponentActions.SHAKE_APP, {
duration: 200,
intensity: 2
});
}
} else if (!a2.isRetry) {
a1();
return false;
}
return true;
};
optimisticDispatch = function optimisticDispatch(a0, a1, a2, a3, a4) {
let userId2 = a4.userId;
if (userId2 == null) {
userId2 = AuthenticationStore.getId();
}
let colors = a4.colors;
if (colors == null) {
colors = [];
}
Dispatcher.dispatch({
type: a0,
channelId: a1,
messageId: a2,
userId: userId2,
emoji: a3,
optimistic: true,
colors,
reactionType: a4.burst ? ReactionTypes.BURST : ReactionTypes.NORMAL
});
};
makeURL = function makeURL({ channelId, messageId, emoji, userId: userId2, useTypeEndpoint = false, type = ReactionTypes.NORMAL }) {
const r26 = emoji.id != null ? `${emoji.name}:${emoji.id}` : emoji.name;
return userId2 == null ? Endpoints.REACTIONS(channelId, messageId, r26) : useTypeEndpoint ? Endpoints.REACTION_WITH_TYPE(channelId, messageId, r26, userId2, type) : Endpoints.REACTION(channelId, messageId, r26, userId2);
};
addReaction = async function addReaction(c25694_0, c25694_1, c25694_2, c25694_3, c25694_4) {
let r212;
let c25694_5, c25694_6;
L26: {
L18: {
let env29656;
const r12 = env3854;
c25694_6 = r12;
const r10 = env29656 = {
$parent: r12
};
c25694_5 = r10;
env29656[3] = void 0;
env29656[4] = void 0;
env29656[0] = c25694_0;
env29656[1] = c25694_1;
env29656[2] = c25694_2;
let r38 = c25694_3;
if (r38 === void 0) {
r38 = c3854_11.MESSAGE;
}
env29656[3] = r38;
env29656[4] = c25694_4;
env29656[5] = void 0;
env29656[6] = void 0;
env29656[7] = void 0;
await void 0;
env29656[5] = env29656[4] != null && !!env29656[4].burst;
env29656[6] = env29656[4] != null && !!env29656[4].isRetry;
if (!env29656[6] && (0, hasUserAlreadyReacted)(env29656[0], env29656[1], env29656[2], env29656[5])) {
AlertActionCreators.show({
title: _index_native.intl.string(t["uaUU/g"]),
body: _index_native.intl.string(t.psMorl),
confirmText: _index_native.intl.string(t["NX+WJN"])
});
break L18;
}
env29656[7] = await (0, getOptimisticEmojiColors)(env29656[2], env29656[5]);
(0, optimisticDispatch)("MESSAGE_REACTION_ADD", env29656[0], env29656[1], env29656[2], {
burst: env29656[5],
colors: env29656[7]
});
await ThreadActionCreators.unarchiveThreadIfNecessary(env29656[0]);
const r187 = {
url: (0, makeURL)({
channelId: env29656[0],
messageId: env29656[1],
emoji: env29656[2],
userId: "@me"
}),
query: null,
oldFormErrors: true,
rejectWithError: null
};
const type = env29656[5] ? ReactionTypes.BURST : ReactionTypes.NORMAL;
const r198 = c25694_5;
r187.query = {
location: env29656[3],
type
};
r187.rejectWithError = rejectWithMigratedError();
r212 = HTTP.put(r187).then($mk114859(r198)).catch($mk114860(r198));
break L26;
}
return void 0;
}
return r212;
};
removeAllReactions = async function removeAllReactions(c25695_0, c25695_1, c25695_2) {
let env29657;
const r29 = env3854;
let c25695_4 = r29;
const r13 = env29657 = {
$parent: r29
};
let c25695_3 = r13;
env29657[0] = c25695_0;
env29657[1] = c25695_1;
env29657[2] = void 0;
env29657[2] = c25695_2 != null && !!c25695_2.isRetry;
await ThreadActionCreators.unarchiveThreadIfNecessary(c25695_0);
HTTP.del({
url: Endpoints.REMOVE_REACTIONS(env29657[0], env29657[1]),
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
}).catch($mk114861(c25695_3));
};
removeEmojiReactions = async function removeEmojiReactions(c25696_0, c25696_1, c25696_2, c25696_3) {
let env29658;
const r31 = env3854;
let c25696_5 = r31;
const r13 = env29658 = {
$parent: r31
};
let c25696_4 = r13;
env29658[0] = c25696_0;
env29658[1] = c25696_1;
env29658[2] = c25696_2;
env29658[3] = void 0;
env29658[4] = void 0;
env29658[3] = c25696_3 != null && !!c25696_3.isRetry;
await ThreadActionCreators.unarchiveThreadIfNecessary(c25696_0);
const r62 = env29658[2].id === null ? env29658[2].name : `${env29658[2].name}:${env29658[2].id}`;
env29658[4] = r62;
HTTP.del({
url: Endpoints.REMOVE_EMOJI_REACTIONS(env29658[0], env29658[1], env29658[4]),
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
}).catch($mk114862(c25696_4));
};
removeReaction = async function removeReaction(c25697_0) {
let env29659;
const r13 = env3854;
let c25697_3 = r13;
const r10 = env29659 = {
$parent: r13
};
let c25697_2 = r10;
env29659[0] = void 0;
env29659[1] = void 0;
env29659[2] = void 0;
env29659[3] = void 0;
env29659[4] = void 0;
env29659[5] = void 0;
env29659[0] = c25697_0.channelId;
env29659[1] = c25697_0.messageId;
env29659[2] = c25697_0.emoji;
let location2 = c25697_0.location;
if (location2 === void 0) {
location2 = c3854_11.MESSAGE;
}
env29659[3] = location2;
env29659[4] = c25697_0.userId;
env29659[5] = c25697_0.options;
env29659[6] = void 0;
env29659[7] = void 0;
await void 0;
env29659[6] = env29659[5] != null && !!env29659[5].burst;
env29659[7] = env29659[5] != null && !!env29659[5].isRetry;
(0, optimisticDispatch)("MESSAGE_REACTION_REMOVE", env29659[0], env29659[1], env29659[2], {
userId: env29659[4],
burst: env29659[6]
});
await ThreadActionCreators.unarchiveThreadIfNecessary(env29659[0]);
let userId = env29659[4];
if (userId == null) {
userId = "@me";
}
const type = env29659[6] ? ReactionTypes.BURST : ReactionTypes.NORMAL;
HTTP.del({
url: makeURL({
channelId: env29659[0],
messageId: env29659[1],
emoji: env29659[2],
userId,
type,
useTypeEndpoint: true
}),
query: {
location: env29659[3],
burst: env29659[6]
},
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
}).then($mk114863(c25697_2)).catch($mk114864(c25697_2)());
};
getOptimisticEmojiColors = async function getOptimisticEmojiColors(c25698_0, c25698_1) {
let r33, r51;
let c25698_4 = 0;
let c29660_0;
L13: {
try {
c29660_0 = [];
if (c25698_1) {
c25698_4 = 1;
c29660_0 = await getEmojiColors(c25698_0);
c25698_4 = 0;
r51 = c29660_0;
break L13;
}
r33 = c29660_0;
} catch ($e) {
let r22 = $e;
if (c25698_4 !== 0) {
while (true) {
try {
c25698_4 = 0;
r51 = c29660_0;
break L13;
} catch ($e) {
r22 = $e;
if (c25698_4 === 0) {
break;
}
}
}
}
throw r22;
}
return r33;
}
return r51;
};
hasUserAlreadyReacted = function hasUserAlreadyReacted(a0, a1, a2, a3) {
const message = MessageStore.getMessage(a0, a1);
return message != null && message.userHasReactedWithEmoji(a2, a3);
};
c3854_11 = {
MESSAGE: "Message",
FORUM_TOOLBAR: "Forum Toolbar",
MOBILE_MEDIA_VIEWER: "Mobile Media Viewer",
MESSAGE_HOVER_BAR: "Message Hover Bar",
MESSAGE_INLINE_BUTTON: "Message Inline Button",
MESSAGE_CONTEXT_MENU: "Message Context Menu",
MESSAGE_REACTION_PICKER: "Message Reaction Picker",
MESSAGE_SHORTCUT: "Message Shortcut",
DOUBLE_TAP: "Double Tap",
IN_APP_NOTIFICATION: "In App Notification"
};
export { c3854_11 as ReactionLocations };
export async function getReactors(c25693_0) {
let r63;
let env29655;
const r29 = env3854;
let c25693_2 = r29;
const r10 = env29655 = {
$parent: r29
};
let c25693_1 = r10;
env29655[0] = void 0;
env29655[1] = void 0;
env29655[2] = void 0;
env29655[3] = void 0;
env29655[4] = void 0;
env29655[5] = void 0;
env29655[0] = c25693_0.channelId;
env29655[1] = c25693_0.messageId;
env29655[2] = c25693_0.emoji;
env29655[3] = c25693_0.limit;
env29655[4] = c25693_0.after;
env29655[5] = c25693_0.type;
env29655[6] = void 0;
env29655[7] = void 0;
env29655[8] = void 0;
await void 0;
if (env29655[5] === ReactionTypes.VOTE) {
const r13 = env29655[0];
const r59 = env29655[1];
const r60 = env29655[2];
r63 = $mk114858(env3854)(r13, r59, r60);
} else {
r63 = (0, makeURL)({
channelId: env29655[0],
messageId: env29655[1],
emoji: env29655[2]
});
}
env29655[6] = r63;
env29655[7] = await HTTP.get({
url: env29655[6],
query: {
limit: env29655[3],
after: env29655[4],
type: env29655[5]
},
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
});
env29655[8] = env29655[5] === ReactionTypes.VOTE ? env29655[7].body.users : env29655[7].body;
Dispatcher.dispatch({
type: "MESSAGE_REACTION_ADD_USERS",
channelId: env29655[0],
messageId: env29655[1],
users: env29655[8],
emoji: env29655[2],
reactionType: env29655[5]
});
return env29655[8];
}
export { addReaction };
export function playBurstReaction(a0) {
Dispatcher.dispatch({
type: "BURST_REACTION_EFFECT_PLAY",
channelId: a0.channelId,
messageId: a0.messageId,
emoji: a0.emoji,
key: a0.key
});
}
export { removeAllReactions };
export { removeEmojiReactions };
export { removeReaction };
export { hasUserAlreadyReacted };