361 lines
11 KiB
TypeScript
361 lines
11 KiB
TypeScript
// Metro module 4630 (f4631).
|
|
import GatedChannelStore from "../channel/GatedChannelStore";
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import PermissionStore from "../../stores/PermissionStore";
|
|
import RelationshipStore from "../../stores/RelationshipStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import { ChannelTypes, ME } from "../../Constants";
|
|
import { truncateText } from "../../utils/StringUtils";
|
|
import AvatarUtils from "../../utils/AvatarUtils";
|
|
import { intl, t } from "../../intl/index.native";
|
|
import { getChannelRoleSubscriptionStatus } from "../guild_role_subscriptions/useChannelRoleSubscriptionStatus";
|
|
import { getMentionIconType } from "../../utils/ChannelUtils";
|
|
import { computeChannelName } from "../channel/useChannelName";
|
|
import { isChannelTypeMentionable } from "./ChannelUtils";
|
|
import * as _LinkUtils from "../links/LinkUtils";
|
|
import { CHANNEL_OR_MESSAGES_URL_RE, MEDIA_POST_URL_RE } from "../links/LinkUtils";
|
|
import MarkupTextRule from "./MarkupTextRule";
|
|
import Module3888 from "../../_bundle/Module3888";
|
|
import { HermesBuiltin } from "../../_hermes/prelude";
|
|
let handleUnknownChannel, parseChannel;
|
|
const getChannel = function getChannel(a0, mentionChannels) {
|
|
const channel = ChannelStore.getChannel(a0);
|
|
const isSubscriptionGated = getChannelRoleSubscriptionStatus(a0, ChannelStore, GatedChannelStore, PermissionStore).isSubscriptionGated;
|
|
let iconType = getMentionIconType(channel);
|
|
if (iconType == null) {
|
|
iconType = "text";
|
|
}
|
|
if (mentionChannels != null) {
|
|
const r29 = mentionChannels.find((item) => item.id === a0);
|
|
if (r29 != null) {
|
|
return {
|
|
type: r29.type,
|
|
id: r29.id,
|
|
guildId: r29.guild_id,
|
|
name: r29.name,
|
|
isDm: channel != null && channel.isPrivate(),
|
|
isForumPost: channel != null && channel.isForumPost(),
|
|
isMentionable: true,
|
|
canViewChannel: true,
|
|
roleSubscriptionGated: isSubscriptionGated,
|
|
iconType,
|
|
parentId: channel?.parent_id
|
|
};
|
|
}
|
|
}
|
|
return channel != null ? {
|
|
type: channel.type,
|
|
id: channel.id,
|
|
guildId: channel.guild_id,
|
|
name: computeChannelName(channel, UserStore, RelationshipStore),
|
|
isDm: channel.isPrivate(),
|
|
isForumPost: channel.isForumPost(),
|
|
isMentionable: isChannelTypeMentionable(channel.type),
|
|
canViewChannel: _LinkUtils.canViewChannel(channel),
|
|
roleSubscriptionGated: isSubscriptionGated,
|
|
iconType,
|
|
parentId: channel.parent_id
|
|
} : null;
|
|
};
|
|
handleUnknownChannel = function handleUnknownChannel(a0, a1, a2, a3, target) {
|
|
const guild = GuildStore.getGuild(a0);
|
|
const inContent = guild == null ? null : guild?.id !== a3 ? [{
|
|
type: "guild",
|
|
guildId: guild.id,
|
|
content: truncateText(guild.name, 32),
|
|
icon: AvatarUtils.getGuildIconURL({
|
|
id: guild.id,
|
|
icon: guild.icon,
|
|
size: 40
|
|
})
|
|
}] : null;
|
|
const r48 = intl.string(t.zLZPmk).toLowerCase();
|
|
const UNKNOWN = ChannelTypes.UNKNOWN;
|
|
return {
|
|
type: "channelMention",
|
|
guildId: a0,
|
|
channelId: a1,
|
|
messageId: a2,
|
|
originalLink: target,
|
|
inContent,
|
|
content: [{
|
|
type: "channel",
|
|
content: [{
|
|
type: "em",
|
|
content: [{
|
|
type: "text",
|
|
content: truncateText(r48, 32)
|
|
}]
|
|
}],
|
|
channelType: UNKNOWN,
|
|
iconType: "text"
|
|
}]
|
|
};
|
|
};
|
|
parseChannel = function parseChannel(a0, a1, a2, a3) {
|
|
let r89;
|
|
if (a0.canViewChannel) {
|
|
if (a0.isMentionable) {
|
|
const r52 = {
|
|
type: "channelMention",
|
|
channelId: a0.id,
|
|
guildId: a0.guildId,
|
|
messageId: a1,
|
|
originalLink: a3
|
|
};
|
|
const guild = GuildStore.getGuild(a0.guildId);
|
|
if (guild == null) {
|
|
return a0.isDm ? {
|
|
...r52,
|
|
guildId: ME,
|
|
inContent: [{
|
|
type: "channel",
|
|
content: [{
|
|
type: "text",
|
|
content: truncateText(a0.name, 32)
|
|
}],
|
|
channelType: a0.type,
|
|
iconType: a0.iconType
|
|
}],
|
|
content: [{
|
|
type: "channel",
|
|
content: [{
|
|
type: "text",
|
|
content: ""
|
|
}],
|
|
iconType: "message"
|
|
}]
|
|
} : a3 != null ? {
|
|
type: "link",
|
|
content: [{
|
|
type: "text",
|
|
content: a3
|
|
}],
|
|
target: a3,
|
|
title: void 0
|
|
} : {
|
|
type: "text",
|
|
content: `#${intl.string(t.J90oLW)}`
|
|
};
|
|
}
|
|
const guildId = a0.guildId;
|
|
const r58 = {
|
|
...r52
|
|
};
|
|
const r4 = a1 != null;
|
|
const r19 = {
|
|
type: "guild",
|
|
guildId: guild.id,
|
|
content: truncateText(guild.name, 32),
|
|
icon: AvatarUtils.getGuildIconURL({
|
|
id: guild.id,
|
|
icon: guild.icon,
|
|
size: 40
|
|
})
|
|
};
|
|
const r79 = {
|
|
type: "channel",
|
|
content: [{
|
|
type: "text",
|
|
content: truncateText(a0.name, 32)
|
|
}],
|
|
channelType: a0.type,
|
|
iconType: a0.iconType
|
|
};
|
|
const isForumPost = a0.isForumPost;
|
|
const r85 = {
|
|
type: "channel",
|
|
content: [{
|
|
type: "text",
|
|
content: ""
|
|
}],
|
|
iconType: null
|
|
};
|
|
const iconType = isForumPost ? "post" : "message";
|
|
L35: {
|
|
const r3 = guildId === a2;
|
|
r85.iconType = iconType;
|
|
if (r3 && r4) {
|
|
if (a0.isForumPost) {
|
|
const channel = ChannelStore.getChannel(a0.parentId);
|
|
if (channel != null) {
|
|
const r111 = computeChannelName(channel, UserStore, RelationshipStore);
|
|
const type = channel.type;
|
|
let iconType2 = getMentionIconType(channel);
|
|
if (iconType2 == null) {
|
|
iconType2 = "forum";
|
|
}
|
|
r89 = {
|
|
inContent: [{
|
|
type: "channel",
|
|
content: [{
|
|
type: "text",
|
|
content: truncateText(r111, 32)
|
|
}],
|
|
channelType: type,
|
|
iconType: iconType2
|
|
}],
|
|
content: [r79]
|
|
};
|
|
break L35;
|
|
}
|
|
}
|
|
r89 = {
|
|
inContent: [r79],
|
|
content: [r85]
|
|
};
|
|
} else {
|
|
r89 = r3 && !r4 ? {
|
|
inContent: null,
|
|
content: [r79]
|
|
} : !r3 && r4 ? {
|
|
inContent: [r19],
|
|
content: [a0.isForumPost ? r79 : r85]
|
|
} : r3 ? void 0 : r4 ? void 0 : {
|
|
inContent: [r19],
|
|
content: [r79]
|
|
};
|
|
}
|
|
}
|
|
HermesBuiltin.copyDataProperties(r58, r89);
|
|
return r58;
|
|
}
|
|
return {
|
|
type: "text",
|
|
content: `#${a0.name}`
|
|
};
|
|
}
|
|
return {
|
|
type: "channelMention",
|
|
guildId: a0.guildId,
|
|
channelId: a0.id,
|
|
messageId: a1,
|
|
inContent: null,
|
|
content: [{
|
|
type: "channel",
|
|
content: [{
|
|
type: "text",
|
|
content: a0.roleSubscriptionGated ? a0.name : intl.string(t["/YzI63"])
|
|
}],
|
|
channelType: a0.roleSubscriptionGated ? a0.type : ChannelTypes.UNKNOWN,
|
|
iconType: "locked"
|
|
}]
|
|
};
|
|
};
|
|
const r40 = {
|
|
channelMention: {
|
|
order: MarkupTextRule.order,
|
|
requiredFirstCharacters: ["<"],
|
|
match: (a0) => /^<#(\d+)>/.exec(a0),
|
|
parse: (a0, a1, a2) => {
|
|
let r23;
|
|
const id = a0[1];
|
|
if (a2.returnMentionIds) {
|
|
return {
|
|
type: "channelMention",
|
|
id
|
|
};
|
|
}
|
|
const channel = getChannel(id, a2.mentionChannels);
|
|
if (channel == null) {
|
|
const channel3 = ChannelStore.getChannel(a2.channelId);
|
|
r23 = handleUnknownChannel(null, id, null, channel3 == null ? void 0 : channel3.getGuildId());
|
|
} else {
|
|
const channel2 = ChannelStore.getChannel(a2.channelId);
|
|
r23 = parseChannel(channel, null, channel2 == null ? void 0 : channel2.getGuildId());
|
|
}
|
|
return r23;
|
|
}
|
|
},
|
|
channelOrMessageUrl: {
|
|
order: Module3888.defaultRules.url.order - 0.5,
|
|
requiredFirstCharacters: ["h"],
|
|
match: (a0) => {
|
|
const r10 = CHANNEL_OR_MESSAGES_URL_RE.exec(a0);
|
|
if (r10 != null) {
|
|
if (r10[2] != null && /\D/.test(r10[2])) {
|
|
return null;
|
|
}
|
|
if (r10[3] != null && /\D/.test(r10[3])) {
|
|
return null;
|
|
}
|
|
}
|
|
return r10;
|
|
},
|
|
parse: (a0, a1, a2) => {
|
|
let r25;
|
|
const target = a0[0];
|
|
const r9 = a0[1];
|
|
const r8 = a0[2];
|
|
const r7 = a0[3];
|
|
if (r8 == null) {
|
|
return {
|
|
type: "link",
|
|
content: [{
|
|
type: "text",
|
|
content: target
|
|
}],
|
|
target,
|
|
title: void 0
|
|
};
|
|
}
|
|
const channel = getChannel(r8, null);
|
|
if (channel == null) {
|
|
const channel3 = ChannelStore.getChannel(a2.channelId);
|
|
r25 = handleUnknownChannel(r9, r8, r7, channel3 == null ? void 0 : channel3.getGuildId(), target);
|
|
} else {
|
|
const channel2 = ChannelStore.getChannel(a2.channelId);
|
|
r25 = parseChannel(channel, r7, channel2 == null ? void 0 : channel2.getGuildId(), target);
|
|
}
|
|
return r25;
|
|
}
|
|
},
|
|
mediaPostLink: {
|
|
order: Module3888.defaultRules.url.order - 0.5,
|
|
requiredFirstCharacters: ["h"],
|
|
match: (a0) => MEDIA_POST_URL_RE.exec(a0),
|
|
parse: (a0, a1, a2) => {
|
|
let r27;
|
|
const target = a0[0];
|
|
const r12 = a0[1];
|
|
const r10 = a0[2];
|
|
const r6 = a0[3];
|
|
const r7 = a0[4];
|
|
if (r10 != null && r6 != null) {
|
|
const channel2 = getChannel(r6, null);
|
|
if (channel2 != null) {
|
|
const channel5 = ChannelStore.getChannel(a2.channelId);
|
|
return parseChannel(channel2, r7, channel5 == null ? void 0 : channel5.getGuildId(), target);
|
|
}
|
|
const channel = getChannel(r10, null);
|
|
if (channel != null) {
|
|
const channel4 = ChannelStore.getChannel(a2.channelId);
|
|
r27 = parseChannel(channel, r7, channel4 == null ? void 0 : channel4.getGuildId(), target);
|
|
} else {
|
|
const channel3 = ChannelStore.getChannel(a2.channelId);
|
|
r27 = handleUnknownChannel(r12, r10, r7, channel3 == null ? void 0 : channel3.getGuildId(), target);
|
|
}
|
|
return r27;
|
|
}
|
|
return {
|
|
type: "link",
|
|
content: [{
|
|
type: "text",
|
|
content: target
|
|
}],
|
|
target,
|
|
title: void 0
|
|
};
|
|
}
|
|
}
|
|
};
|
|
export default r40;
|
|
export function getGuildIdFromChannelId(a0) {
|
|
const channel = ChannelStore.getChannel(a0);
|
|
return channel == null ? void 0 : channel.getGuildId();
|
|
}
|
|
export { getChannel };
|
|
export { handleUnknownChannel };
|
|
export { parseChannel };
|