Add ability to accept and reject remote follows if account is locked

This commit is contained in:
Jesse Wierzbinski 2024-04-09 22:07:03 -10:00
parent f72671fb07
commit cf295a596a
No known key found for this signature in database
5 changed files with 92 additions and 419 deletions

View file

@ -131,6 +131,44 @@ export const followRequestUser = async (
return relationship;
};
export const sendFollowAccept = async (follower: User, followee: User) => {
// TODO: Make database job
const request = await objectToInboxRequest(
followAcceptToLysand(follower, followee),
followee,
follower,
);
// Send request
const response = await fetch(request);
if (!response.ok) {
console.error(await response.text());
throw new Error(
`Failed to federate follow accept from ${followee.id} to ${follower.uri}`,
);
}
};
export const sendFollowReject = async (follower: User, followee: User) => {
// TODO: Make database job
const request = await objectToInboxRequest(
followRejectToLysand(follower, followee),
followee,
follower,
);
// Send request
const response = await fetch(request);
if (!response.ok) {
console.error(await response.text());
throw new Error(
`Failed to federate follow reject from ${followee.id} to ${follower.uri}`,
);
}
};
export const resolveUser = async (uri: string) => {
// Check if user not already in database
const foundUser = await client.user.findUnique({
@ -659,3 +697,13 @@ export const followAcceptToLysand = (
uri: new URL(`/follows/${id}`, config.http.base_url).toString(),
};
};
export const followRejectToLysand = (
follower: User,
followee: User,
): Lysand.FollowReject => {
return {
...followAcceptToLysand(follower, followee),
type: "FollowReject",
};
};