feat(federation): Federate likes and unlikes

This commit is contained in:
Jesse Wierzbinski 2024-10-24 17:31:39 +02:00
parent 5a26bdf2f8
commit f494f76f82
No known key found for this signature in database
6 changed files with 22 additions and 6 deletions

View file

@ -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": {

BIN
bun.lockb

Binary file not shown.

View file

@ -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<typeof Likes, LikeType> {
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(),
};
}
}

View file

@ -987,7 +987,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
id,
author: this.author.getUri(),
deleted_type: "Note",
target: this.getUri(),
deleted: this.getUri(),
created_at: new Date().toISOString(),
};
}

View file

@ -473,7 +473,8 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
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<typeof Users, UserWithRelations> {
if (this.isLocal() && note.author.isRemote()) {
// User is local, federate the delete
// TODO: Federate this
this.federateToFollowers(likeToDelete.unlikeToVersia(this));
}
}

View file

@ -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",