mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
fix(federation): Send Undos to the followee when unfollowing
This commit is contained in:
commit
838debec25
|
|
@ -48,6 +48,7 @@ import {
|
|||
Users,
|
||||
} from "~/drizzle/schema";
|
||||
import { type Config, config } from "~/packages/config-manager";
|
||||
import { undoFederationRequest } from "../../classes/functions/federation.ts";
|
||||
import { BaseInterface } from "./base";
|
||||
import { Emoji } from "./emoji";
|
||||
import { Instance } from "./instance";
|
||||
|
|
@ -254,6 +255,46 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
return foundRelationship;
|
||||
}
|
||||
|
||||
async unfollow(followee: User, relationship: Relationship) {
|
||||
if (followee.isRemote()) {
|
||||
// TODO: This should reschedule for a later time and maybe notify the server admin if it fails too often
|
||||
const { ok } = await this.federateToUser(
|
||||
undoFederationRequest(
|
||||
this,
|
||||
new URL(
|
||||
`/follows/${relationship.id}`,
|
||||
config.http.base_url,
|
||||
).toString(),
|
||||
),
|
||||
followee,
|
||||
);
|
||||
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this.data.isLocked) {
|
||||
if (relationship.data.following) {
|
||||
await db.insert(Notifications).values({
|
||||
accountId: followee.id,
|
||||
type: "unfollow",
|
||||
notifiedId: this.id,
|
||||
});
|
||||
} else {
|
||||
await db.insert(Notifications).values({
|
||||
accountId: followee.id,
|
||||
type: "cancel-follow",
|
||||
notifiedId: this.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await relationship.update({
|
||||
following: false,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static async webFinger(
|
||||
manager: FederationRequester,
|
||||
username: string,
|
||||
|
|
|
|||
|
|
@ -57,10 +57,8 @@ export default (app: Hono) =>
|
|||
otherUser,
|
||||
);
|
||||
|
||||
if (foundRelationship.data.following) {
|
||||
await foundRelationship.update({
|
||||
following: false,
|
||||
});
|
||||
if (!(await self.unfollow(otherUser, foundRelationship))) {
|
||||
return errorResponse("Failed to unfollow user", 500);
|
||||
}
|
||||
|
||||
return jsonResponse(foundRelationship.toApi());
|
||||
|
|
|
|||
Loading…
Reference in a new issue