mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
feat(federation): ✨ Federate likes and unlikes
This commit is contained in:
parent
5a26bdf2f8
commit
f494f76f82
|
|
@ -366,7 +366,7 @@ export default apiRoute((app) =>
|
||||||
// "delete" is a reserved keyword in JS
|
// "delete" is a reserved keyword in JS
|
||||||
delete: async (delete_) => {
|
delete: async (delete_) => {
|
||||||
// Delete the specified object from database, if it exists and belongs to the user
|
// 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) {
|
switch (delete_.deleted_type) {
|
||||||
case "Note": {
|
case "Note": {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { RolePermission } from "@versia/client/types";
|
import { RolePermission } from "@versia/client/types";
|
||||||
import type { LikeExtension } from "@versia/federation";
|
import type { Delete, LikeExtension } from "@versia/federation/types";
|
||||||
import {
|
import {
|
||||||
type InferInsertModel,
|
type InferInsertModel,
|
||||||
type InferSelectModel,
|
type InferSelectModel,
|
||||||
|
|
@ -160,4 +160,19 @@ export class Like extends BaseInterface<typeof Likes, LikeType> {
|
||||||
uri: this.getUri().toString(),
|
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(),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -987,7 +987,7 @@ export class Note extends BaseInterface<typeof Notes, StatusWithRelations> {
|
||||||
id,
|
id,
|
||||||
author: this.author.getUri(),
|
author: this.author.getUri(),
|
||||||
deleted_type: "Note",
|
deleted_type: "Note",
|
||||||
target: this.getUri(),
|
deleted: this.getUri(),
|
||||||
created_at: new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -473,7 +473,8 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
||||||
noteId: note.id,
|
noteId: note.id,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// TODO: Add database jobs for federating this
|
// Federate the like
|
||||||
|
this.federateToFollowers(newLike.toVersia());
|
||||||
}
|
}
|
||||||
|
|
||||||
return newLike;
|
return newLike;
|
||||||
|
|
@ -511,7 +512,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
||||||
|
|
||||||
if (this.isLocal() && note.author.isRemote()) {
|
if (this.isLocal() && note.author.isRemote()) {
|
||||||
// User is local, federate the delete
|
// User is local, federate the delete
|
||||||
// TODO: Federate this
|
this.federateToFollowers(likeToDelete.unlikeToVersia(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@
|
||||||
"@sentry/bun": "^8.35.0",
|
"@sentry/bun": "^8.35.0",
|
||||||
"@tufjs/canonical-json": "^2.0.0",
|
"@tufjs/canonical-json": "^2.0.0",
|
||||||
"@versia/client": "^0.1.0",
|
"@versia/client": "^0.1.0",
|
||||||
"@versia/federation": "^0.1.1",
|
"@versia/federation": "^0.1.2",
|
||||||
"@versia/kit": "workspace:*",
|
"@versia/kit": "workspace:*",
|
||||||
"altcha-lib": "^1.1.0",
|
"altcha-lib": "^1.1.0",
|
||||||
"blurhash": "^2.0.5",
|
"blurhash": "^2.0.5",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue