refactor(federation): 🚚 Move old function to User

This commit is contained in:
Jesse Wierzbinski 2024-08-27 15:50:14 +02:00
parent 3b2c0d3b5a
commit fbb845f7f8
No known key found for this signature in database
2 changed files with 17 additions and 19 deletions

View file

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

View file

@ -14,7 +14,11 @@ import {
type HttpVerb, type HttpVerb,
SignatureConstructor, SignatureConstructor,
} from "@versia/federation"; } 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 chalk from "chalk";
import { import {
type InferInsertModel, type InferInsertModel,
@ -49,7 +53,6 @@ import {
} from "~/drizzle/schema"; } from "~/drizzle/schema";
import { type Config, config } from "~/packages/config-manager"; import { type Config, config } from "~/packages/config-manager";
import type { KnownEntity } from "~/types/api.ts"; import type { KnownEntity } from "~/types/api.ts";
import { unfollowFederationRequest } from "../../classes/functions/federation.ts";
import { BaseInterface } from "./base"; import { BaseInterface } from "./base";
import { Emoji } from "./emoji"; import { Emoji } from "./emoji";
import { Instance } from "./instance"; import { Instance } from "./instance";
@ -210,7 +213,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
if (followee.isRemote()) { if (followee.isRemote()) {
// TODO: This should reschedule for a later time and maybe notify the server admin if it fails too often // TODO: This should reschedule for a later time and maybe notify the server admin if it fails too often
const { ok } = await this.federateToUser( const { ok } = await this.federateToUser(
unfollowFederationRequest(this, followee), this.unfollowToVersia(followee),
followee, followee,
); );
@ -240,6 +243,17 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
return true; 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( static async webFinger(
manager: FederationRequester, manager: FederationRequester,
username: string, username: string,