mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
refactor(federation): 🚚 Move old function to User
This commit is contained in:
parent
3b2c0d3b5a
commit
fbb845f7f8
|
|
@ -1,16 +0,0 @@
|
|||
import type { Unfollow } from "@versia/federation/types";
|
||||
import type { User } from "~/packages/database-interface/user";
|
||||
|
||||
export const unfollowFederationRequest = (
|
||||
unfollower: User,
|
||||
unfollowing: User,
|
||||
): Unfollow => {
|
||||
const id = crypto.randomUUID();
|
||||
return {
|
||||
type: "Unfollow",
|
||||
id,
|
||||
author: unfollower.getUri(),
|
||||
created_at: new Date().toISOString(),
|
||||
followee: unfollowing.getUri(),
|
||||
};
|
||||
};
|
||||
|
|
@ -14,7 +14,11 @@ import {
|
|||
type HttpVerb,
|
||||
SignatureConstructor,
|
||||
} from "@versia/federation";
|
||||
import type { Collection, User as VersiaUser } from "@versia/federation/types";
|
||||
import type {
|
||||
Collection,
|
||||
Unfollow,
|
||||
User as VersiaUser,
|
||||
} from "@versia/federation/types";
|
||||
import chalk from "chalk";
|
||||
import {
|
||||
type InferInsertModel,
|
||||
|
|
@ -49,7 +53,6 @@ import {
|
|||
} from "~/drizzle/schema";
|
||||
import { type Config, config } from "~/packages/config-manager";
|
||||
import type { KnownEntity } from "~/types/api.ts";
|
||||
import { unfollowFederationRequest } from "../../classes/functions/federation.ts";
|
||||
import { BaseInterface } from "./base";
|
||||
import { Emoji } from "./emoji";
|
||||
import { Instance } from "./instance";
|
||||
|
|
@ -210,7 +213,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
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(
|
||||
unfollowFederationRequest(this, followee),
|
||||
this.unfollowToVersia(followee),
|
||||
followee,
|
||||
);
|
||||
|
||||
|
|
@ -240,6 +243,17 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
|||
return true;
|
||||
}
|
||||
|
||||
private unfollowToVersia(followee: User): Unfollow {
|
||||
const id = crypto.randomUUID();
|
||||
return {
|
||||
type: "Unfollow",
|
||||
id,
|
||||
author: this.getUri(),
|
||||
created_at: new Date().toISOString(),
|
||||
followee: followee.getUri(),
|
||||
};
|
||||
}
|
||||
|
||||
static async webFinger(
|
||||
manager: FederationRequester,
|
||||
username: string,
|
||||
|
|
|
|||
Loading…
Reference in a new issue