From f494f76f82e7e4f31686ec19bbff58472ae4a2d8 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Thu, 24 Oct 2024 17:31:39 +0200 Subject: [PATCH] feat(federation): :sparkles: Federate likes and unlikes --- api/users/:uuid/inbox/index.ts | 2 +- bun.lockb | Bin 301132 -> 301132 bytes classes/database/like.ts | 17 ++++++++++++++++- classes/database/note.ts | 2 +- classes/database/user.ts | 5 +++-- package.json | 2 +- 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/api/users/:uuid/inbox/index.ts b/api/users/:uuid/inbox/index.ts index bb6f89bf..ff2189cd 100644 --- a/api/users/:uuid/inbox/index.ts +++ b/api/users/:uuid/inbox/index.ts @@ -366,7 +366,7 @@ export default apiRoute((app) => // "delete" is a reserved keyword in JS delete: async (delete_) => { // Delete the specified object from database, if it exists and belongs to the user - const toDelete = delete_.target; + const toDelete = delete_.deleted; switch (delete_.deleted_type) { case "Note": { diff --git a/bun.lockb b/bun.lockb index f039f30c8b2a5100e2bafd1a808d0acfa9dd75fa..bbc53a2db7982fdc34c50acb5509d8aa85514595 100755 GIT binary patch delta 151 zcmV;I0BHZruoBF$5|Az+PwmQM%6(Y?z!3_s#p`}!AO7*F&l}M0&vmJ|{H){wu}+$6 zljtrmvlwhm_dsNTj<}7m_Vb0%S(@Af=9hMJ&q*Aq=mdwQV*$6NV*+xM0WpUd_X3v~_XF0KLf-=+w-5LO FJ)l)xL&E?7 diff --git a/classes/database/like.ts b/classes/database/like.ts index 631c070a..cece6c41 100644 --- a/classes/database/like.ts +++ b/classes/database/like.ts @@ -1,5 +1,5 @@ import { RolePermission } from "@versia/client/types"; -import type { LikeExtension } from "@versia/federation"; +import type { Delete, LikeExtension } from "@versia/federation/types"; import { type InferInsertModel, type InferSelectModel, @@ -160,4 +160,19 @@ export class Like extends BaseInterface { uri: this.getUri().toString(), }; } + + public unlikeToVersia(unliker?: User): Delete { + return { + type: "Delete", + id: crypto.randomUUID(), + created_at: new Date().toISOString(), + author: User.getUri( + unliker?.id ?? this.data.liker.id, + unliker?.data.uri ?? this.data.liker.uri, + config.http.base_url, + ), + deleted_type: "pub.versia:likes/Like", + deleted: this.getUri().toString(), + }; + } } diff --git a/classes/database/note.ts b/classes/database/note.ts index 4ff62963..a74cb77e 100644 --- a/classes/database/note.ts +++ b/classes/database/note.ts @@ -987,7 +987,7 @@ export class Note extends BaseInterface { id, author: this.author.getUri(), deleted_type: "Note", - target: this.getUri(), + deleted: this.getUri(), created_at: new Date().toISOString(), }; } diff --git a/classes/database/user.ts b/classes/database/user.ts index 70a9f91c..af5d8a7f 100644 --- a/classes/database/user.ts +++ b/classes/database/user.ts @@ -473,7 +473,8 @@ export class User extends BaseInterface { noteId: note.id, }); } else { - // TODO: Add database jobs for federating this + // Federate the like + this.federateToFollowers(newLike.toVersia()); } return newLike; @@ -511,7 +512,7 @@ export class User extends BaseInterface { if (this.isLocal() && note.author.isRemote()) { // User is local, federate the delete - // TODO: Federate this + this.federateToFollowers(likeToDelete.unlikeToVersia(this)); } } diff --git a/package.json b/package.json index bb68cdff..b6f9ac1a 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "@sentry/bun": "^8.35.0", "@tufjs/canonical-json": "^2.0.0", "@versia/client": "^0.1.0", - "@versia/federation": "^0.1.1", + "@versia/federation": "^0.1.2", "@versia/kit": "workspace:*", "altcha-lib": "^1.1.0", "blurhash": "^2.0.5",