From 0941df15831c64d5321bbbf381e09e4340b44268 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Wed, 16 Aug 2023 10:13:22 +0000 Subject: a ton of broken shit and approx 1 nice function --- src/util/entities/Channel.ts | 14 ++++++++++++++ src/util/entities/Message.ts | 19 ++++++++++++++++++- src/util/entities/User.ts | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) (limited to 'src/util/entities') diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts index a5191dc3..8b692ac7 100644 --- a/src/util/entities/Channel.ts +++ b/src/util/entities/Channel.ts @@ -387,6 +387,18 @@ export class Channel extends BaseClass { if (channel == null) { name = trimSpecial(name); + const { publicKey, privateKey } = await generateKeyPair("rsa", { + modulusLength: 4096, + publicKeyEncoding: { + type: "spki", + format: "pem", + }, + privateKeyEncoding: { + type: "pkcs8", + format: "pem", + }, + }); + channel = await Channel.create({ name, type, @@ -403,6 +415,8 @@ export class Channel extends BaseClass { }), ), nsfw: false, + publicKey, + privateKey, }).save(); } diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts index bbbb2ac1..3bf3b9d0 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts @@ -16,7 +16,7 @@ along with this program. If not, see . */ -import type { APAnnounce, APNote } from "activitypub-types"; +import type { APAnnounce, APCreate, APNote } from "activitypub-types"; import { Column, CreateDateColumn, @@ -220,6 +220,9 @@ export class Message extends BaseClass { @Column({ type: "simple-json", nullable: true }) components?: MessageComponent[]; + @Column({ nullable: true }) + federatedId: string; + toJSON(): Message { return { ...this, @@ -227,6 +230,7 @@ export class Message extends BaseClass { member_id: undefined, webhook_id: undefined, application_id: undefined, + federatedId: undefined, nonce: this.nonce ?? undefined, tts: this.tts ?? false, @@ -256,6 +260,19 @@ export class Message extends BaseClass { }; } + toCreateAP(): APCreate { + const { webDomain } = Config.get().federation; + + return { + "@context": "https://www.w3.org/ns/activitystreams", + type: "Create", + id: `https://${webDomain}/fed/channel/${this.channel_id}/messages/${this.id}`, + to: [], + actor: `https://${webDomain}/fed/user/${this.author_id}`, + object: this.toAP(), + }; + } + // TODO: move to AP module toAP(): APNote { const { webDomain } = Config.get().federation; diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts index f9213693..1594093f 100644 --- a/src/util/entities/User.ts +++ b/src/util/entities/User.ts @@ -252,6 +252,9 @@ export class User extends BaseClass { @Column({ select: false }) privateKey: string; + @Column({ nullable: true }) + federatedId: string; + // TODO: I don't like this method? validate() { if (this.discriminator) { -- cgit 1.5.1