aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVen <vendicated@riseup.net>2023-02-12 19:43:57 +0100
committerGitHub <noreply@github.com>2023-02-12 19:43:57 +0100
commit614234ad208963a8068b156fd04760be6013a554 (patch)
tree7ddf59a87e3800b97778b5a11c985cf5db8b219d
parent2489bc68315f4e2c7cd54eae7c64846d6d1218d9 (diff)
downloadVencord-614234ad208963a8068b156fd04760be6013a554.tar.gz
Vencord-614234ad208963a8068b156fd04760be6013a554.tar.bz2
Vencord-614234ad208963a8068b156fd04760be6013a554.zip
MessageLinkEmbeds: Prevent infinite cycles (#488)
-rw-r--r--src/plugins/messageLinkEmbeds.tsx21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/plugins/messageLinkEmbeds.tsx b/src/plugins/messageLinkEmbeds.tsx
index d08f25e..a6b63d8 100644
--- a/src/plugins/messageLinkEmbeds.tsx
+++ b/src/plugins/messageLinkEmbeds.tsx
@@ -139,6 +139,16 @@ interface MessageEmbedProps {
guildID: string;
}
+function withEmbeddedBy(message: Message, embeddedBy: string[]) {
+ return new Proxy(message, {
+ get(_, prop) {
+ if (prop === "vencordEmbeddedBy") return embeddedBy;
+ // @ts-ignore ts so bad
+ return Reflect.get(...arguments);
+ }
+ });
+}
+
export default definePlugin({
name: "MessageLinkEmbeds",
description: "Adds a preview to messages that link another message",
@@ -194,19 +204,24 @@ export default definePlugin({
messageEmbedAccessory(props) {
const { message }: { message: Message; } = props;
+ // @ts-ignore
+ const embeddedBy: string[] = message.vencordEmbeddedBy ?? [];
const accessories = [] as (JSX.Element | null)[];
let match = null as RegExpMatchArray | null;
while ((match = this.messageLinkRegex.exec(message.content!)) !== null) {
const [_, guildID, channelID, messageID] = match;
+ if (embeddedBy.includes(messageID)) {
+ continue;
+ }
const linkedChannel = ChannelStore.getChannel(channelID);
if (!linkedChannel || (guildID !== "@me" && !PermissionStore.can(1024n /* view channel */, linkedChannel))) {
continue;
}
- let linkedMessage = messageCache[messageID]?.message as Message;
+ let linkedMessage = messageCache[messageID]?.message;
if (!linkedMessage) {
linkedMessage ??= MessageStore.getMessage(channelID, messageID);
if (linkedMessage) messageCache[messageID] = { message: linkedMessage, fetched: true };
@@ -223,7 +238,7 @@ export default definePlugin({
}
}
const messageProps: MessageEmbedProps = {
- message: linkedMessage,
+ message: withEmbeddedBy(linkedMessage, [...embeddedBy, message.id]),
channel: linkedChannel,
guildID
};
@@ -267,7 +282,7 @@ export default definePlugin({
}
}}
renderDescription={() => {
- return <div key={message.id} className={classNames.join(" ")} >
+ return <div key={message.id} className={classNames.join(" ")}>
<ChannelMessage
id={`message-link-embeds-${message.id}`}
message={message}