mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
feat(federation): ✨ Federate likes and unlikes
This commit is contained in:
parent
5a26bdf2f8
commit
f494f76f82
6 changed files with 22 additions and 6 deletions
|
|
@ -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(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue