437 lines
13 KiB
TypeScript
437 lines
13 KiB
TypeScript
// Metro module 7687 (f7688).
|
|
import { createChannelRecordFromInvite } from "../records/ChannelRecord";
|
|
import InviteRecord from "../records/InviteRecord";
|
|
import UserRecord from "../records/UserRecord";
|
|
import ChannelStore from "./ChannelStore";
|
|
import { ChannelSettingsSections, ChannelTypes, Endpoints, FormStates } from "../Constants";
|
|
import { DEFAULT_AUTO_ARCHIVE_DURATION } from "../modules/threads/ThreadConstants";
|
|
import { isCustomReactionEmojiId } from "../modules/reactions/ReactionUtils";
|
|
import UnicodeEmojis from "../modules/emojis/UnicodeEmojis";
|
|
import { ThreadSortOrder } from "../_bundle/Module1381";
|
|
import { ForumLayout } from "../_bundle/Module1382";
|
|
import { HTTP } from "../_bundle/sendRequest";
|
|
import Dispatcher from "../Dispatcher";
|
|
import Module12, { isArray } from "../_bundle/Module12";
|
|
import { fromInviteGuild } from "../utils/GuildRecordUtils";
|
|
import Module3771 from "../_bundle/Module3771";
|
|
import Module589 from "../_bundle/Module589";
|
|
let section, subsection, channel, channel2, channel3, guildId, CLOSED, errors, invites, loading, c4830_22, location2, _excluded, c4830_26, _createInvite, _syncChannelUpdate, c4830_29, $mk79194 = function() {
|
|
return (a0) => {
|
|
loading = false;
|
|
Dispatcher.dispatch({
|
|
type: "CHANNEL_SETTINGS_LOADED_INVITES",
|
|
invites: a0.body
|
|
});
|
|
};
|
|
}, $mk79195 = function() {
|
|
return () => {
|
|
loading = false;
|
|
return false;
|
|
};
|
|
};
|
|
const normalizeChannelPropertyForCompare = function normalizeChannelPropertyForCompare(a0, a1, type) {
|
|
let r4 = a1;
|
|
if (a0 === "topic_") {
|
|
if (a1 == null) {
|
|
r4 = "";
|
|
}
|
|
return r4;
|
|
}
|
|
if (a0 === "defaultAutoArchiveDuration") {
|
|
return a1 == null ? DEFAULT_AUTO_ARCHIVE_DURATION : a1;
|
|
}
|
|
if (a0 === "defaultSortOrder") {
|
|
return a1 == null ? ThreadSortOrder.LATEST_ACTIVITY : a1;
|
|
}
|
|
if (a0 === "defaultForumLayout") {
|
|
if (type === ChannelTypes.GUILD_MEDIA) {
|
|
return ForumLayout.GRID;
|
|
}
|
|
return a1 != null ? a1 === ForumLayout.DEFAULT ? ForumLayout.LIST : a1 : ForumLayout.LIST;
|
|
}
|
|
if (a0 !== "rateLimitPerUser_" && a0 !== "defaultThreadRateLimitPerUser") {
|
|
if (a0 === "defaultReactionEmoji") {
|
|
const r1 = a1 == null;
|
|
let r18 = null;
|
|
if (!r1) {
|
|
if (isCustomReactionEmojiId(a1.emojiId)) {
|
|
r18 = {
|
|
emojiId: a1.emojiId
|
|
};
|
|
} else {
|
|
const emojiName = a1.emojiName;
|
|
r18 = emojiName == null ? null : emojiName !== "" ? {
|
|
emojiName: UnicodeEmojis.translateInlineEmojiToSurrogates(emojiName)
|
|
} : null;
|
|
}
|
|
}
|
|
return r18;
|
|
}
|
|
return a1;
|
|
}
|
|
return a1 == null ? 0 : a1;
|
|
};
|
|
_createInvite = function _createInvite(invite) {
|
|
return new InviteRecord({
|
|
code: invite.code,
|
|
temporary: invite.temporary,
|
|
revoked: invite.revoked,
|
|
inviter: invite.inviter != null ? new UserRecord(invite.inviter) : null,
|
|
channel: createChannelRecordFromInvite(invite.channel),
|
|
guild: invite.guild != null ? fromInviteGuild(invite.guild) : null,
|
|
uses: invite.uses,
|
|
maxUses: invite.max_uses,
|
|
maxAge: invite.max_age,
|
|
createdAt: Module3771(invite.created_at),
|
|
type: invite.type,
|
|
roles: invite.roles
|
|
});
|
|
};
|
|
_syncChannelUpdate = function _syncChannelUpdate(a0) {
|
|
const r1 = channel == null;
|
|
let r0 = false;
|
|
if (!r1) {
|
|
const id = channel.id;
|
|
r0 = false;
|
|
if (id === a0) {
|
|
if (channel === channel2) {
|
|
const channel5 = ChannelStore.getChannel(a0);
|
|
const r35 = channel5 == null;
|
|
r0 = false;
|
|
if (!r35) {
|
|
channel = channel5;
|
|
channel2 = channel5;
|
|
channel3 = ChannelStore.getChannel(channel2.parent_id);
|
|
r0 = true;
|
|
}
|
|
} else {
|
|
const channel4 = ChannelStore.getChannel(a0);
|
|
const r17 = channel4 == null;
|
|
r0 = false;
|
|
if (!r17) {
|
|
channel = channel4;
|
|
const r4 = channel2 != null;
|
|
r0 = true;
|
|
if (r4) {
|
|
channel2 = channel2.set("permissionOverwrites", channel.permissionOverwrites).set("availableTags", channel.availableTags);
|
|
channel3 = ChannelStore.getChannel(channel2.parent_id);
|
|
r0 = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const r40 = r0 ? channel2 == null : !r0;
|
|
let r42 = !r40;
|
|
if (!r40) {
|
|
const r44 = guildId != null && channel2.permissionOverwrites[guildId] == null;
|
|
r42 = true;
|
|
if (r44) {
|
|
guildId = channel2.getGuildId();
|
|
r42 = true;
|
|
}
|
|
}
|
|
return r42;
|
|
};
|
|
const handleOverwriteUpdate = function handleOverwriteUpdate(a0) {
|
|
return _syncChannelUpdate(a0.channelId);
|
|
};
|
|
CLOSED = FormStates.CLOSED;
|
|
errors = {};
|
|
invites = {};
|
|
loading = false;
|
|
c4830_22 = false;
|
|
location2 = null;
|
|
_excluded = ["name", "type", "topic_", "bitrate_", "userLimit_", "nsfw_", "flags_", "rateLimitPerUser_", "defaultThreadRateLimitPerUser", "defaultAutoArchiveDuration", "template", "defaultReactionEmoji", "rtcRegion", "videoQualityMode", "threadMetadata", "banner", "availableTags", "defaultSortOrder", "defaultForumLayout", "defaultTagSetting", "iconEmoji", "themeColor"];
|
|
c4830_26 = Module12.debounce(() => {
|
|
if (channel2 != null && channel != null) {
|
|
const r8 = channel2.toJS();
|
|
let c15959_0 = r8;
|
|
let c15959_1 = channel.toJS();
|
|
const type = r8.type;
|
|
if (_excluded.every((item) => {
|
|
const r5 = c15959_0[item];
|
|
const r6 = c15959_1[item];
|
|
return Module12.isEqual(normalizeChannelPropertyForCompare(item, r5, type), normalizeChannelPropertyForCompare(item, r6, type));
|
|
}) && channel2 !== channel) {
|
|
channel2 = channel;
|
|
c4830_29.emitChange();
|
|
}
|
|
return void 0;
|
|
}
|
|
return false;
|
|
}, 500);
|
|
class ChannelSettingsStore extends Module589.Store {
|
|
static displayName = "ChannelSettingsStore";
|
|
initialize() {
|
|
this.waitFor(ChannelStore);
|
|
}
|
|
hasChanges() {
|
|
return channel2 !== channel;
|
|
}
|
|
isOpen() {
|
|
return c4830_22;
|
|
}
|
|
getSection() {
|
|
return section;
|
|
}
|
|
getInvites() {
|
|
return {
|
|
invites,
|
|
loading
|
|
};
|
|
}
|
|
showNotice() {
|
|
return this.hasChanges();
|
|
}
|
|
getChannel() {
|
|
return channel2;
|
|
}
|
|
getFormState() {
|
|
return CLOSED;
|
|
}
|
|
getCategory() {
|
|
return channel3;
|
|
}
|
|
getProps() {
|
|
return {
|
|
submitting: CLOSED === FormStates.SUBMITTING,
|
|
errors,
|
|
channel: channel2,
|
|
section,
|
|
subsection,
|
|
invites,
|
|
selectedOverwriteId: guildId,
|
|
hasChanges: this.hasChanges(),
|
|
analyticsLocation: location2
|
|
};
|
|
}
|
|
}
|
|
c4830_29 = new ChannelSettingsStore(Dispatcher, {
|
|
CHANNEL_SETTINGS_INIT: function handleSettingsInit(a0) {
|
|
const channel4 = ChannelStore.getChannel(a0.channelId);
|
|
if (channel4 == null) {
|
|
c4830_22 = false;
|
|
CLOSED = FormStates.CLOSED;
|
|
section = null;
|
|
channel = null;
|
|
channel2 = null;
|
|
channel3 = null;
|
|
invites = {};
|
|
return void 0;
|
|
}
|
|
CLOSED = FormStates.OPEN;
|
|
channel = channel4;
|
|
channel2 = channel4;
|
|
location2 = "location" in a0 ? a0.location != null ? a0.location : null : null;
|
|
subsection = "subsection" in a0 ? a0.subsection : null;
|
|
if (channel2 != null) {
|
|
channel2 = channel2.set("nsfw", channel2.isNSFW());
|
|
}
|
|
channel3 = ChannelStore.getChannel(channel2.parent_id);
|
|
guildId = channel2.getGuildId();
|
|
const r38 = channel2.isModeratorReportChannel() ? ChannelSettingsSections.PERMISSIONS : ChannelSettingsSections.OVERVIEW;
|
|
errors = {};
|
|
let r42 = section;
|
|
if (r42 == null) {
|
|
r42 = r38;
|
|
}
|
|
section = r42;
|
|
subsection = subsection;
|
|
if (channel2 != null && section === ChannelSettingsSections.INSTANT_INVITES) {
|
|
loading = true;
|
|
const r61 = HTTP.get({
|
|
url: Endpoints.INSTANT_INVITES(channel2.id),
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
});
|
|
const r63 = $mk79195();
|
|
r61.then($mk79194(), r63);
|
|
}
|
|
return true;
|
|
},
|
|
CHANNEL_SETTINGS_SUBMIT: function handleSettingsSubmit() {
|
|
CLOSED = FormStates.SUBMITTING;
|
|
errors = {};
|
|
},
|
|
CHANNEL_SETTINGS_SUBMIT_SUCCESS: function handleSettingsSubmitSuccess() {
|
|
channel = channel2;
|
|
CLOSED = FormStates.OPEN;
|
|
},
|
|
CHANNEL_SETTINGS_SUBMIT_FAILURE: function handleSettingsSubmitFailure(a0) {
|
|
CLOSED = FormStates.OPEN;
|
|
const r5 = Object;
|
|
let errors2 = a0.errors;
|
|
if (errors2 == null) {
|
|
errors2 = {};
|
|
}
|
|
errors = r5.keys(errors2).reduce((acc, item) => {
|
|
const r5 = a0.errors[item];
|
|
if (isArray(r5)) {
|
|
acc[item] = r5.join("\n");
|
|
} else {
|
|
acc[item] = r5;
|
|
}
|
|
return acc;
|
|
}, {});
|
|
},
|
|
CHANNEL_SETTINGS_CLOSE: function handleSettingsClose() {
|
|
c4830_22 = false;
|
|
CLOSED = FormStates.CLOSED;
|
|
section = null;
|
|
channel = null;
|
|
channel2 = null;
|
|
channel3 = null;
|
|
invites = {};
|
|
},
|
|
CHANNEL_PERMISSIONS_PUT_OVERWRITE_SUCCESS: handleOverwriteUpdate,
|
|
CHANNEL_PERMISSIONS_DELETE_OVERWRITE_SUCCESS: handleOverwriteUpdate,
|
|
CHANNEL_SETTINGS_OVERWRITE_SELECT: function handlePermissionOverwriteSelect(a0) {
|
|
guildId = a0.overwriteId;
|
|
},
|
|
CHANNEL_SETTINGS_UPDATE: function handleSettingsUpdate({ name, channelType, topic, bitrate, userLimit, nsfw, flags, rateLimitPerUser, defaultThreadRateLimitPerUser, autoArchiveDuration, locked, invitable, defaultAutoArchiveDuration, template, defaultReactionEmoji, rtcRegion, videoQualityMode, availableTags, defaultSortOrder, defaultForumLayout, defaultTagSetting, iconEmoji, themeColor }) {
|
|
if (channel2 == null) {
|
|
return false;
|
|
}
|
|
if (name != null) {
|
|
channel2 = channel2.set("name", name);
|
|
}
|
|
if (topic != null) {
|
|
channel2 = channel2.set("topic", topic);
|
|
}
|
|
if (bitrate != null) {
|
|
channel2 = channel2.set("bitrate", bitrate);
|
|
}
|
|
if (userLimit != null) {
|
|
channel2 = channel2.set("userLimit", userLimit);
|
|
}
|
|
if (nsfw != null) {
|
|
channel2 = channel2.set("nsfw", nsfw);
|
|
}
|
|
if (flags != null) {
|
|
channel2 = channel2.set("flags", flags);
|
|
}
|
|
if (rateLimitPerUser != null) {
|
|
channel2 = channel2.set("rateLimitPerUser", rateLimitPerUser);
|
|
}
|
|
if (defaultThreadRateLimitPerUser != null) {
|
|
channel2 = channel2.set("defaultThreadRateLimitPerUser", defaultThreadRateLimitPerUser);
|
|
}
|
|
if (autoArchiveDuration != null) {
|
|
channel2 = channel2.set("threadMetadata", {
|
|
...channel2.threadMetadata,
|
|
autoArchiveDuration
|
|
});
|
|
}
|
|
if (locked != null) {
|
|
channel2 = channel2.set("threadMetadata", {
|
|
...channel2.threadMetadata,
|
|
locked
|
|
});
|
|
}
|
|
if (invitable != null) {
|
|
channel2 = channel2.set("threadMetadata", {
|
|
...channel2.threadMetadata,
|
|
invitable
|
|
});
|
|
}
|
|
if (defaultAutoArchiveDuration != null) {
|
|
channel2 = channel2.set("defaultAutoArchiveDuration", defaultAutoArchiveDuration);
|
|
}
|
|
if (template != null) {
|
|
channel2 = channel2.set("template", template);
|
|
}
|
|
if (channelType != null) {
|
|
channel2 = channel2.set("type", channelType);
|
|
}
|
|
if (rtcRegion !== void 0) {
|
|
channel2 = channel2.set("rtcRegion", rtcRegion);
|
|
}
|
|
if (videoQualityMode != null) {
|
|
channel2 = channel2.set("videoQualityMode", videoQualityMode);
|
|
}
|
|
if (defaultReactionEmoji !== void 0) {
|
|
channel2 = channel2.set("defaultReactionEmoji", defaultReactionEmoji);
|
|
}
|
|
if (availableTags != null) {
|
|
channel2 = channel2.set("availableTags", availableTags);
|
|
}
|
|
if (defaultSortOrder != null) {
|
|
channel2 = channel2.set("defaultSortOrder", defaultSortOrder);
|
|
}
|
|
if (defaultTagSetting != null) {
|
|
channel2 = channel2.set("defaultTagSetting", defaultTagSetting);
|
|
}
|
|
if (defaultForumLayout != null) {
|
|
channel2 = channel2.set("defaultForumLayout", defaultForumLayout);
|
|
}
|
|
if (iconEmoji !== void 0) {
|
|
channel2 = channel2.set("iconEmoji", iconEmoji);
|
|
}
|
|
if (themeColor != null) {
|
|
channel2 = channel2.set("themeColor", themeColor);
|
|
}
|
|
c4830_26();
|
|
},
|
|
CHANNEL_SETTINGS_SET_SECTION: function handleSetSection(a0) {
|
|
section = a0.section;
|
|
subsection = a0.subsection;
|
|
if (channel2 != null && section === ChannelSettingsSections.INSTANT_INVITES) {
|
|
loading = true;
|
|
const r25 = HTTP.get({
|
|
url: Endpoints.INSTANT_INVITES(channel2.id),
|
|
oldFormErrors: true,
|
|
rejectWithError: true
|
|
});
|
|
const r27 = $mk79195();
|
|
r25.then($mk79194(), r27);
|
|
}
|
|
},
|
|
CHANNEL_SETTINGS_LOADED_INVITES: function handleLoadedInvites(a0) {
|
|
invites = {};
|
|
a0.invites.forEach((invite) => {
|
|
invites[invite.code] = _createInvite(invite);
|
|
});
|
|
},
|
|
CHANNEL_UPDATES: function handleChannelUpdates({ channels }) {
|
|
if (channel2 == null) {
|
|
return false;
|
|
}
|
|
let r20 = false;
|
|
for (const item of channels) {
|
|
r20 = _syncChannelUpdate(item.id) || r20;
|
|
}
|
|
return r20;
|
|
},
|
|
THREAD_UPDATE: function handleThreadUpdate({ channel: channel4 }) {
|
|
return channel2 != null && _syncChannelUpdate(channel4.id);
|
|
},
|
|
CHANNEL_DELETE: function handleChannelDelete(a0) {
|
|
const id = a0.channel.id;
|
|
let r8 = channel2 != null;
|
|
if (r8) {
|
|
let r1 = channel2.id === id;
|
|
if (r1) {
|
|
CLOSED = FormStates.CLOSED;
|
|
r1 = void 0;
|
|
}
|
|
r8 = r1;
|
|
}
|
|
return r8;
|
|
},
|
|
INSTANT_INVITE_REVOKE_SUCCESS: function handleInviteRevoke(a0) {
|
|
invites = {
|
|
...invites
|
|
};
|
|
delete invites[a0.code];
|
|
},
|
|
INSTANT_INVITE_CREATE_SUCCESS: function handleInviteCreateSuccess(a0) {
|
|
const r2 = {
|
|
...invites
|
|
};
|
|
r2[a0.invite.code] = _createInvite(a0.invite);
|
|
invites = r2;
|
|
}
|
|
});
|
|
export default c4830_29;
|