Files
discord-decomp/actions/ChannelActionCreators.tsx
T
2026-11-01 12:12:55 +02:00

659 lines
19 KiB
TypeScript

// Metro module 4199 (f4200).
import _slicedToArray from "../_bundle/_slicedToArray";
import ChangelogStore from "../modules/changelog/ChangelogStore";
import { createChannelRecordFromServer } from "../records/ChannelRecord";
import ChannelStore from "../stores/ChannelStore";
import ReadStateStore from "../stores/ReadStateStore";
import { Endpoints, AbortCodes, AnalyticEvents, Routes, ME, CURRENT_APP_CONTEXT, ChannelTypes } from "../Constants";
import CallActionCreators from "./CallActionCreators";
import { HTTP, rejectWithMigratedError } from "../_bundle/sendRequest";
import openQuarantineModeInfoModal_native from "../modules/quarantine/openQuarantineModeInfoModal.native";
import { getRootNavigationRef } from "../modules/main_tabs_v2/RootNavigationRef.native";
import { transitionToChannel } from "../modules/routing/transitionToChannel";
import SelectedChannelActionCreators from "./SelectedChannelActionCreators";
import Dispatcher from "../Dispatcher";
import isChangelogChannel from "../modules/changelog/utils/isChangelogChannel";
import AnalyticsUtils from "../utils/AnalyticsUtils";
import { transitionTo } from "../modules/routing/router_utils";
import { AccessibilityAnnouncer } from "../design/shared";
import { intl, t } from "../intl/index.native";
import GuildTemplateTooltipActionCreators from "../modules/guild_templates/GuildTemplateTooltipActionCreators";
import { httpGetWithCountryCodeQuery } from "../utils/StoreUtils";
let env2419 = {};
const r35 = {
openPrivateChannel: async function openPrivateChannel(a0) {
let r73, id;
let env13902 = {
$parent: env2419
};
env13902[0] = a0.recipientIds;
let joinCall = a0.joinCall;
if (joinCall === void 0) {
joinCall = false;
}
env13902[1] = joinCall;
let joinCallVideo = a0.joinCallVideo;
if (joinCallVideo === void 0) {
joinCallVideo = false;
}
env13902[2] = joinCallVideo;
env13902[3] = a0.location;
env13902[4] = a0.onBeforeTransition;
let navigateToChannel = a0.navigateToChannel;
if (navigateToChannel === void 0) {
navigateToChannel = true;
}
env13902[5] = navigateToChannel;
env13902[6] = this;
let c24954_0, c24954_1, c24954_2;
let c24954_3 = 0;
const r17 = env13902;
L17: {
L10: {
try {
let env29280;
c24954_1 = r17;
const r41 = env29280 = {
$parent: r17
};
c24954_0 = r41;
env29280[1] = void 0;
const joinCallIfRequested = function joinCallIfRequested(a0) {
if (env13902[1]) {
CallActionCreators.call(a0.id, env13902[2], true, a0.isDM() ? a0.getRecipientId() : null);
}
};
env29280[0] = joinCallIfRequested;
const recipients = env13902[6]._getRecipients(env13902[0]);
if (recipients.length === 1) {
const r68 = env13902[6]._openCachedDMChannel(_slicedToArray(recipients, 1)[0], env13902[4], env13902[5]);
if (r68 != null) {
joinCallIfRequested(r68);
r73 = Promise.resolve(r68.id);
break L10;
}
}
c24954_3 = 1;
env29280[1] = await HTTP.post({
url: Endpoints.USER_CHANNELS,
body: {
recipients
},
context: {
location: env13902[3]
},
oldFormErrors: true,
retries: 3,
rejectWithError: rejectWithMigratedError()
});
if (env13902[5]) {
const r99 = env13902[4];
if (r99 != null) {
r99();
}
(0, env29280[0])(env13902[6]._openPrivateChannel(env29280[1].body));
}
id = env29280[1].body.id;
c24954_3 = 0;
break L17;
} catch ($e) {
const r39 = $e;
let r15 = r39;
c24954_2 = r39;
if (c24954_3 !== 0) {
while (true) {
try {
const r116 = c24954_2;
c24954_3 = 0;
env29280[2] = r116;
const r118 = env29280[2];
if ((r118 == null ? void 0 : r118.body?.code) === AbortCodes.QUARANTINED) {
openQuarantineModeInfoModal_native();
}
throw env29280[2];
} catch (r113) {
r15 = r113;
c24954_2 = r113;
if (c24954_3 === 0) {
break;
}
}
}
}
throw r15;
}
}
return r73;
}
return id;
},
createGroupDmShell: async function createGroupDmShell({ recipientId, location: location2, onBeforeTransition, navigateToChannel = true }) {
let id;
let c13903_3 = navigateToChannel;
const _this = this;
let c24955_2;
let c24955_3 = 0;
let c29281_0, c29281_1;
try {
c29281_0 = void 0;
c24955_3 = 1;
c29281_0 = await HTTP.post({
url: Endpoints.USER_GROUP_DM_SHELL,
body: {
recipient_id: recipientId
},
context: {
location: location2
},
oldFormErrors: true,
retries: 3,
rejectWithError: rejectWithMigratedError()
});
if (c13903_3) {
if (onBeforeTransition != null) {
onBeforeTransition();
}
_this._openPrivateChannel(c29281_0.body);
}
id = c29281_0.body.id;
c24955_3 = 0;
} catch ($e) {
const r32 = $e;
let r13 = r32;
c24955_2 = r32;
if (c24955_3 !== 0) {
while (true) {
try {
const r89 = c24955_2;
c24955_3 = 0;
c29281_1 = r89;
const r91 = c29281_1;
if ((r91 == null ? void 0 : r91.body?.code) === AbortCodes.QUARANTINED) {
openQuarantineModeInfoModal_native();
}
throw c29281_1;
} catch (r86) {
r13 = r86;
c24955_2 = r86;
if (c24955_3 === 0) {
break;
}
}
}
}
throw r13;
}
return id;
},
_openCachedDMChannel: function _openCachedDMChannel(a0, a1, r5 = true) {
const dMFromUserId = ChannelStore.getDMFromUserId(a0);
const r10 = dMFromUserId != null ? ChannelStore.getChannel(dMFromUserId) : null;
const r12 = r10 == null;
let r13 = null;
if (!r12) {
r13 = r10;
if (r5) {
if (a1 != null) {
a1();
}
if (getRootNavigationRef() != null) {
transitionToChannel(r10.id, {
navigationReplace: true
});
r13 = r10;
} else {
SelectedChannelActionCreators.selectPrivateChannel(r10.id);
r13 = r10;
}
}
}
return r13;
},
ensurePrivateChannel: async function ensurePrivateChannel(c13904_0) {
const _this2 = this;
let c24956_1;
c24956_1 = void 0;
let c29282_0 = await HTTP.post({
url: Endpoints.USER_CHANNELS,
body: {
recipients: _this2._getRecipients(c13904_0)
},
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
});
let c29282_1 = (0, createChannelRecordFromServer)(c29282_0.body);
Dispatcher.dispatch({
type: "CHANNEL_CREATE",
channel: c29282_1
});
return c29282_1.id;
},
getOrEnsurePrivateChannel: async function getOrEnsurePrivateChannel(c13905_0) {
let dMFromUserId;
const _this3 = this;
L11: {
dMFromUserId = ChannelStore.getDMFromUserId(c13905_0);
if (dMFromUserId != null) {
break L11;
}
return await _this3.ensurePrivateChannel(c13905_0);
}
return dMFromUserId;
},
getDMChannel: async (c13906_0) => {
let c24958_1;
c24958_1 = void 0;
let c29283_0 = await HTTP.get({
url: Endpoints.DM_CHANNEL(c13906_0),
rejectWithError: true
});
let c29283_1 = (0, createChannelRecordFromServer)(c29283_0.body);
Dispatcher.dispatch({
type: "CHANNEL_CREATE",
channel: c29283_1
});
return c29283_1.id;
},
_getRecipients: (a0) => a0 != null ? Array.isArray(a0) ? a0 : [a0] : [],
_openPrivateChannel: (a0) => {
const channel = (0, createChannelRecordFromServer)(a0);
Dispatcher.dispatch({
type: "CHANNEL_CREATE",
channel
});
if (getRootNavigationRef() != null) {
transitionToChannel(channel.id, {
navigationReplace: true
});
} else {
SelectedChannelActionCreators.selectPrivateChannel(channel.id);
}
return channel;
},
closePrivateChannel: function closePrivateChannel(a0, r3 = false, silent = false) {
if (isChangelogChannel(a0)) {
AnalyticsUtils.track(AnalyticEvents.CHANGE_LOG_DM_REMOVED, {
last_changelog_id: ChangelogStore.latestChangelogId(),
unread_count: ReadStateStore.getUnreadCount(a0)
});
}
Dispatcher.dispatch({
type: "CHANNEL_DELETE",
channel: {
id: a0,
guild_id: void 0,
parent_id: void 0
},
silent
});
if (r3) {
transitionTo(Routes.FRIENDS);
}
return HTTP.del({
url: Endpoints.CHANNEL(a0),
query: {
silent
},
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
}).then(() => {
AccessibilityAnnouncer.announce(intl.string(t.nRbucl));
}).catch(() => {
AccessibilityAnnouncer.announce(intl.string(t.ndXVI5));
});
},
updatePermissionOverwrite: async (c13907_0, body) => {
let c24959_1;
c24959_1 = void 0;
let c29284_0 = await HTTP.put({
url: Endpoints.CHANNEL_PERMISSIONS_OVERWRITE(c13907_0, body.id),
body,
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
});
Dispatcher.dispatch({
type: "CHANNEL_PERMISSIONS_PUT_OVERWRITE_SUCCESS",
channelId: c13907_0,
overwrite: body
});
return c29284_0;
},
clearPermissionOverwrite: async (c13908_0, c13908_1) => {
let c24960_1;
c24960_1 = void 0;
let c29285_0 = await HTTP.del({
url: Endpoints.CHANNEL_PERMISSIONS_OVERWRITE(c13908_0, c13908_1),
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
});
Dispatcher.dispatch({
type: "CHANNEL_PERMISSIONS_DELETE_OVERWRITE_SUCCESS",
channelId: c13908_0,
overwriteId: c13908_1
});
return c29285_0;
},
addRecipient: function addRecipient(a0, a1, a2, c13909_0) {
return HTTP.put({
url: Endpoints.CHANNEL_RECIPIENT(a0, a1),
context: {
location: a2
},
oldFormErrors: true,
rejectWithError: true
}).then((result) => {
AccessibilityAnnouncer.announce(intl.string(t.cU0t1F));
if (c13909_0 != null) {
c13909_0();
}
return result.status === 201 ? this._openPrivateChannel(result.body).id : a0;
}).catch(() => {
AccessibilityAnnouncer.announce(intl.string(t["8GEdej"]));
return a0;
});
},
addRecipients: function addRecipients(a0, a1, a2, a3) {
return this.addRecipient(a0, a1[0], a2, a3).then((c24961_0) => Promise.all(a1.slice(1).map((item) => this.addRecipient(c24961_0, item, a2))).then(() => c24961_0));
},
removeRecipient: (a0, a1) => HTTP.del({
url: Endpoints.CHANNEL_RECIPIENT(a0, a1),
oldFormErrors: true,
rejectWithError: true
}),
setDMOwner: (a0, a1) => HTTP.patch({
url: Endpoints.CHANNEL(a0),
body: {
owner: a1
},
oldFormErrors: true,
rejectWithError: true
}),
setName: async (c13911_0, name) => {
let c24962_1;
c24962_1 = void 0;
let c29286_0 = ChannelStore.getChannel(c13911_0);
let c29286_1 = await HTTP.patch({
url: Endpoints.CHANNEL(c13911_0),
body: {
name
},
oldFormErrors: true,
rejectWithError: true
});
let c29286_2 = c29286_0 == null ? void 0 : c29286_0.getGuildId();
let r61 = c29286_2 == null;
if (!r61) {
r61 = c29286_0 == null ? void 0 : c29286_0.isThread();
}
if (!r61) {
GuildTemplateTooltipActionCreators.checkGuildTemplateDirty(c29286_2);
}
return c29286_1;
},
setIcon: async (channel_id, icon, location3) => {
let r112;
let c24963_2;
let c24963_3 = 0;
let c29287_0, c29287_1, c29287_2, c29287_3, c29287_4;
try {
c29287_0 = void 0;
c29287_1 = void 0;
c29287_2 = void 0;
c29287_3 = void 0;
const channel = ChannelStore.getChannel(channel_id);
c29287_0 = channel;
const r23 = {
channel_id,
channel_type: channel?.type,
old_icon_set: channel?.icon != null,
new_icon_set: icon != null,
location: location3
};
c29287_1 = r23;
AnalyticsUtils.track(AnalyticEvents.CHANNEL_ICON_EDIT_PROGRESSED, {
...r23,
status: "initiated"
});
c24963_3 = 1;
c29287_2 = await HTTP.patch({
url: Endpoints.CHANNEL(channel_id),
body: {
icon
},
oldFormErrors: true,
rejectWithError: true,
failImmediatelyWhenRateLimited: true
});
AnalyticsUtils.track(AnalyticEvents.CHANNEL_ICON_EDIT_PROGRESSED, {
...c29287_1,
status: "success"
});
const r99 = c29287_0;
c29287_3 = r99 == null ? void 0 : r99.getGuildId();
let r104 = c29287_3 == null;
if (!r104) {
const r107 = c29287_0;
r104 = r107 == null ? void 0 : r107.isThread();
}
if (!r104) {
GuildTemplateTooltipActionCreators.checkGuildTemplateDirty(c29287_3);
}
r112 = c29287_2;
c24963_3 = 0;
} catch ($e) {
const r32 = $e;
let r8 = r32;
c24963_2 = r32;
if (c24963_3 !== 0) {
while (true) {
try {
const r131 = c24963_2;
c24963_3 = 0;
c29287_4 = r131;
const CHANNEL_ICON_EDIT_PROGRESSED = AnalyticEvents.CHANNEL_ICON_EDIT_PROGRESSED;
const r145 = c29287_4;
const r147 = r145 == null ? void 0 : r145.body?.retry_after;
const r150 = c29287_4;
AnalyticsUtils.track(CHANNEL_ICON_EDIT_PROGRESSED, {
...c29287_1,
status: "failed",
is_rate_limited: r147 != null,
error_message: r150 == null ? void 0 : r150.body?.message
});
throw c29287_4;
} catch (r127) {
r8 = r127;
c24963_2 = r127;
if (c24963_3 === 0) {
break;
}
}
}
}
throw r8;
}
return r112;
},
updateChannel: async (channel_id2, body2, location4) => {
let r114;
let c24964_2;
let c24964_3 = 0;
let c29288_0, c29288_1, c29288_2, c29288_3, c29288_4, c29288_5;
try {
c29288_0 = void 0;
c29288_1 = void 0;
c29288_2 = void 0;
c29288_3 = void 0;
c29288_4 = void 0;
const r37 = "icon" in body2;
c29288_0 = r37;
const channel = ChannelStore.getChannel(channel_id2);
c29288_1 = channel;
const r26 = {
channel_id: channel_id2,
channel_type: channel?.type,
old_icon_set: channel?.icon != null,
new_icon_set: body2.icon != null,
location: location4
};
c29288_2 = r26;
if (r37) {
AnalyticsUtils.track(AnalyticEvents.CHANNEL_ICON_EDIT_PROGRESSED, {
...r26,
status: "initiated"
});
}
c24964_3 = 1;
c29288_3 = await HTTP.patch({
context: {
location: location4
},
url: Endpoints.CHANNEL(channel_id2),
body: body2,
oldFormErrors: true,
rejectWithError: true
});
const r89 = c29288_1;
c29288_4 = r89 == null ? void 0 : r89.getGuildId();
let r94 = c29288_4 == null;
if (!r94) {
const r97 = c29288_1;
r94 = r97 == null ? void 0 : r97.isThread();
}
if (!r94) {
GuildTemplateTooltipActionCreators.checkGuildTemplateDirty(c29288_4);
}
if (c29288_0) {
AnalyticsUtils.track(AnalyticEvents.CHANNEL_ICON_EDIT_PROGRESSED, {
...c29288_2,
status: "success"
});
}
r114 = c29288_3;
c24964_3 = 0;
} catch ($e) {
const r35 = $e;
let r8 = r35;
c24964_2 = r35;
if (c24964_3 !== 0) {
while (true) {
try {
const r136 = c24964_2;
c24964_3 = 0;
c29288_5 = r136;
if (c29288_0) {
const CHANNEL_ICON_EDIT_PROGRESSED = AnalyticEvents.CHANNEL_ICON_EDIT_PROGRESSED;
const r154 = c29288_5;
const r156 = r154 == null ? void 0 : r154.body?.retry_after;
const r159 = c29288_5;
AnalyticsUtils.track(CHANNEL_ICON_EDIT_PROGRESSED, {
...c29288_2,
status: "failed",
is_rate_limited: r156 != null,
error_message: r159 == null ? void 0 : r159.body?.message
});
}
throw c29288_5;
} catch (r133) {
r8 = r133;
c24964_2 = r133;
if (c24964_3 === 0) {
break;
}
}
}
}
throw r8;
}
return r114;
},
convertToGuild: (a0) => HTTP.post({
url: Endpoints.CHANNEL_CONVERT(a0),
oldFormErrors: true,
rejectWithError: true
}),
preload: (a0, a1) => {
Dispatcher.dispatch({
type: "CHANNEL_PRELOAD",
guildId: a0 !== ME ? a0 : null,
channelId: a1,
context: CURRENT_APP_CONTEXT
});
},
fetchChannelStoreListing: (a0, a1) => {
const channelId = a0;
return httpGetWithCountryCodeQuery(a1 != null ? Endpoints.CHANNEL_STORE_LISTING_SKU(a0, a1) : Endpoints.CHANNEL_STORE_LISTING(a0)).then((result) => {
Dispatcher.dispatch({
type: "STORE_LISTING_FETCH_SUCCESS",
channelId,
storeListing: result.body
});
});
},
createTextChannel: async (c13915_0, name2, parent_id, topic) => {
let c24965_1;
c24965_1 = void 0;
const body3 = {
type: ChannelTypes.GUILD_TEXT,
name: name2,
permission_overwrites: []
};
if (parent_id != null) {
body3.parent_id = parent_id;
}
if (topic != null) {
body3.topic = topic;
}
let c29289_0 = await HTTP.post({
url: Endpoints.GUILD_CHANNELS(c13915_0),
body: body3,
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
});
GuildTemplateTooltipActionCreators.checkGuildTemplateDirty(c13915_0);
return c29289_0;
},
fetchChannel: async (c13916_0) => (await HTTP.get({
url: Endpoints.CHANNEL(c13916_0),
rejectWithError: true
})).body,
openChannel: async function openChannel(c13917_0) {
let r55;
const _this4 = this;
let c24967_2 = 0;
let c29290_0, c29290_1;
try {
c29290_0 = void 0;
c29290_1 = void 0;
c24967_2 = 1;
c29290_0 = await _this4.fetchChannel(c13917_0);
c29290_1 = (0, createChannelRecordFromServer)(c29290_0);
Dispatcher.dispatch({
type: "CHANNEL_CREATE",
channel: c29290_1
});
r55 = c29290_1;
c24967_2 = 0;
} catch ($e) {
let r23 = $e;
if (c24967_2 !== 0) {
while (true) {
try {
c24967_2 = 0;
} catch ($e) {
r23 = $e;
if (c24967_2 === 0) {
break;
}
continue;
}
return void 0;
}
}
throw r23;
}
return r55;
}
};
export default r35;