summary refs log tree commit diff
path: root/src/util/entities
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-08-16 10:13:22 +0000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-08-16 10:17:56 +0000
commit0941df15831c64d5321bbbf381e09e4340b44268 (patch)
treeb320cb5b3a39270abcabc865f57f893715078e3f /src/util/entities
parentMove AP methods to own file (diff)
downloadserver-0941df15831c64d5321bbbf381e09e4340b44268.tar.xz
a ton of broken shit and approx 1 nice function
Diffstat (limited to 'src/util/entities')
-rw-r--r--src/util/entities/Channel.ts14
-rw-r--r--src/util/entities/Message.ts19
-rw-r--r--src/util/entities/User.ts3
3 files changed, 35 insertions, 1 deletions
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 <https://www.gnu.org/licenses/>. */ -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) {