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

@ -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));
}
}