diff --git a/src/api/routes/channels/#channel_id/messages/#message_id/index.ts b/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
index 54ba6b4e..973e20e2 100644
--- a/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/#message_id/index.ts
@@ -233,11 +233,15 @@ router.put(
// no await as it shouldnt block the message send function and silently catch error
postHandleMessage(message).catch((e) => console.error("[Message] post-message handler failed", e));
- const sign = new NewUrlUserSignatureData({
- ip: req.ip,
- userAgent: req.headers["user-agent"] as string,
- });
- return res.json(Message.prototype.withSignedComponents.call(message.withSignedAttachments(sign), sign));
+
+ return res.json(
+ message.withSignedAttachments(
+ new NewUrlUserSignatureData({
+ ip: req.ip,
+ userAgent: req.headers["user-agent"] as string,
+ }),
+ ),
+ );
},
);
diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index bf4803aa..bd0f32ec 100644
--- a/src/api/routes/channels/#channel_id/messages/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -506,11 +506,14 @@ router.post(
// no await as it shouldnt block the message send function and silently catch error
postHandleMessage(message).catch((e) => console.error("[Message] post-message handler failed", e));
- const sign = new NewUrlUserSignatureData({
- ip: req.ip,
- userAgent: req.headers["user-agent"] as string,
- });
- return res.json(Message.prototype.withSignedComponents.call(Message.prototype.withSignedAttachments.call(message.toJSON(), sign), sign));
+ return res.json(
+ message.withSignedAttachments(
+ new NewUrlUserSignatureData({
+ ip: req.ip,
+ userAgent: req.headers["user-agent"] as string,
+ }),
+ ),
+ );
},
);
diff --git a/src/gateway/listener/listener.ts b/src/gateway/listener/listener.ts
index 6b261ccc..149b0edb 100644
--- a/src/gateway/listener/listener.ts
+++ b/src/gateway/listener/listener.ts
@@ -353,7 +353,7 @@ async function consume(this: WebSocket, opts: EventOpts) {
}),
).attachments;
if (data["components"]) {
- data["components"] = Message.prototype.withSignedComponents.call(
+ data["components"] = Message.prototype.withSignedAttachments.call(
data,
new NewUrlUserSignatureData({
ip: this.ipAddress,
diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts
index 42f79ee4..735402f2 100644
--- a/src/util/entities/Message.ts
+++ b/src/util/entities/Message.ts
@@ -306,58 +306,54 @@ export class Message extends BaseClass {
}
withSignedAttachments(data: NewUrlUserSignatureData) {
- return {
- ...this,
- attachments: this.attachments?.map((attachment: Attachment) => Attachment.prototype.signUrls.call(attachment, data)),
- };
- }
- withSignedComponents(data: NewUrlUserSignatureData) {
- if (!this.components || !(this.flags & Number(MessageFlags.FLAGS.IS_COMPONENTS_V2))) return { ...this };
function signMedia(media: UnfurledMediaItem) {
Object.assign(media, Attachment.prototype.signUrls.call(media, data));
}
return {
...this,
- components: this.components.map((comp) => {
- comp = structuredClone(comp);
- if (comp.type === MessageComponentType.Section) {
- const accessory = comp.accessory;
- if (accessory.type === MessageComponentType.Thumbnail) {
- signMedia(accessory.media);
- }
- } else if (comp.type === MessageComponentType.MediaGallery) {
- comp.items.forEach(({ media }) => signMedia(media));
- } else if (comp.type === MessageComponentType.File) {
- signMedia(comp.file);
- } else if (comp.type === MessageComponentType.Container) {
- for (const elm of comp.components) {
- switch (elm.type) {
- case MessageComponentType.Separator:
- case MessageComponentType.TextDisplay:
- case MessageComponentType.ActionRow:
- break;
- case MessageComponentType.Section: {
- const accessory = elm.accessory;
- if (accessory.type === MessageComponentType.Thumbnail) {
- signMedia(accessory.media);
- }
- break;
- }
- case MessageComponentType.MediaGallery:
- elm.items.forEach(({ media }) => signMedia(media));
- break;
- case MessageComponentType.File: {
- signMedia(elm.file);
- break;
- }
+ attachments: this.attachments?.map((attachment: Attachment) => Attachment.prototype.signUrls.call(attachment, data)),
+ components: this.components
+ ? this.components.map((comp) => {
+ comp = structuredClone(comp);
+ if (comp.type === MessageComponentType.Section) {
+ const accessory = comp.accessory;
+ if (accessory.type === MessageComponentType.Thumbnail) {
+ signMedia(accessory.media);
+ }
+ } else if (comp.type === MessageComponentType.MediaGallery) {
+ comp.items.forEach(({ media }) => signMedia(media));
+ } else if (comp.type === MessageComponentType.File) {
+ signMedia(comp.file);
+ } else if (comp.type === MessageComponentType.Container) {
+ for (const elm of comp.components) {
+ switch (elm.type) {
+ case MessageComponentType.Separator:
+ case MessageComponentType.TextDisplay:
+ case MessageComponentType.ActionRow:
+ break;
+ case MessageComponentType.Section: {
+ const accessory = elm.accessory;
+ if (accessory.type === MessageComponentType.Thumbnail) {
+ signMedia(accessory.media);
+ }
+ break;
+ }
+ case MessageComponentType.MediaGallery:
+ elm.items.forEach(({ media }) => signMedia(media));
+ break;
+ case MessageComponentType.File: {
+ signMedia(elm.file);
+ break;
+ }
- default:
- elm satisfies never;
- }
- }
- }
- return comp;
- }),
+ default:
+ elm satisfies never;
+ }
+ }
+ }
+ return comp;
+ })
+ : this.components,
};
}
|