From 9d6a3dc2a750e14c3181cc7658687323035fcc7a Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Mon, 14 Aug 2023 19:51:07 +1000 Subject: [PATCH] aaaaaaaa --- .../#channel_id/messages/#message_id/index.ts | 2 +- .../routes/channel/#channel_id/outbox.ts | 1 - src/activitypub/routes/messages/index.ts | 14 ++++++++++++++ src/util/entities/Message.ts | 6 +++--- 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 src/activitypub/routes/messages/index.ts diff --git a/src/activitypub/routes/channel/#channel_id/messages/#message_id/index.ts b/src/activitypub/routes/channel/#channel_id/messages/#message_id/index.ts index 7ac5ae0a..de498847 100644 --- a/src/activitypub/routes/channel/#channel_id/messages/#message_id/index.ts +++ b/src/activitypub/routes/channel/#channel_id/messages/#message_id/index.ts @@ -21,7 +21,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { type: "Announce", actor: `https://${webDomain}/fed/user/${message.author_id}`, published: message.timestamp, - to: `https://${webDomain}/fed/channel/${message.channel_id}`, + to: `https://${webDomain}/fed/channel/${message.channel_id}/followers`, object: message.toAP(), }; diff --git a/src/activitypub/routes/channel/#channel_id/outbox.ts b/src/activitypub/routes/channel/#channel_id/outbox.ts index 799be53f..bb44e174 100644 --- a/src/activitypub/routes/channel/#channel_id/outbox.ts +++ b/src/activitypub/routes/channel/#channel_id/outbox.ts @@ -52,7 +52,6 @@ router.get("/", route({}), async (req, res) => { // move this to like, Channel.createAPMessages or smth const apMessages = messages.map((message) => ({ - "@context": "https://www.w3.org/ns/activitystreams", id: `https://${webDomain}/fed/channel/${message.channel_id}/messages/${message.id}`, type: "Announce", actor: `https://${webDomain}/fed/user/${message.author_id}`, diff --git a/src/activitypub/routes/messages/index.ts b/src/activitypub/routes/messages/index.ts new file mode 100644 index 00000000..c764cdfa --- /dev/null +++ b/src/activitypub/routes/messages/index.ts @@ -0,0 +1,14 @@ +import { route } from "@spacebar/api"; +import { Message } from "@spacebar/util"; +import { Router } from "express"; + +const router = Router(); +export default router; + +router.get("/:message_id", route({}), async (req, res) => { + const id = req.params.message_id; + + const message = await Message.findOneOrFail({ where: { id } }); + + return res.json(message.toAP()); +}); diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts index dbaa9dd1..46a3758d 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts @@ -247,12 +247,12 @@ export class Message extends BaseClass { const { webDomain } = Config.get().federation; return { - id: `https://${webDomain}/fed/channel/${this.channel_id}/messages/${this.id}`, + id: `https://${webDomain}/fed/messages/${this.id}`, type: "Note", published: this.timestamp, - url: `https://${webDomain}/fed/channel/${this.channel_id}/messages/${this.id}`, + url: `https://${webDomain}/fed/messages/${this.id}`, attributedTo: `https://${webDomain}/fed/user/${this.author_id}`, - to: `https://${webDomain}/fed/channel/${this.channel_id}`, + to: `https://${webDomain}/fed/channel/${this.channel_id}/followers`, content: this.content, }; }