2025-11-21 08:31:02 +01:00
|
|
|
import type { z } from "zod";
|
2025-04-08 16:01:10 +02:00
|
|
|
import {
|
|
|
|
|
FollowAcceptSchema,
|
|
|
|
|
FollowRejectSchema,
|
|
|
|
|
FollowSchema,
|
|
|
|
|
UnfollowSchema,
|
|
|
|
|
} from "../schemas/follow.ts";
|
|
|
|
|
import type { JSONObject } from "../types.ts";
|
2026-02-25 02:34:27 +01:00
|
|
|
import { Entity, Reference } from "./entity.ts";
|
2025-04-08 16:01:10 +02:00
|
|
|
|
|
|
|
|
export class Follow extends Entity {
|
2025-05-23 17:29:27 +02:00
|
|
|
public static override name = "Follow";
|
2025-04-08 16:01:10 +02:00
|
|
|
|
2026-04-03 13:34:19 +02:00
|
|
|
public constructor(
|
|
|
|
|
public override data: z.infer<typeof FollowSchema>,
|
|
|
|
|
instanceDomain: string,
|
|
|
|
|
) {
|
|
|
|
|
super(data, instanceDomain);
|
2025-04-08 16:01:10 +02:00
|
|
|
}
|
|
|
|
|
|
2026-02-25 02:34:27 +01:00
|
|
|
public get author(): Reference {
|
2026-04-03 13:34:19 +02:00
|
|
|
return Reference.fromString(this.data.author, this.instanceDomain);
|
2026-02-25 02:34:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get followee(): Reference {
|
2026-04-03 13:34:19 +02:00
|
|
|
return Reference.fromString(this.data.followee, this.instanceDomain);
|
2026-02-25 02:34:27 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-03 13:34:19 +02:00
|
|
|
public static override fromJSON(
|
|
|
|
|
json: JSONObject,
|
|
|
|
|
instanceDomain: string,
|
|
|
|
|
): Promise<Follow> {
|
|
|
|
|
return FollowSchema.parseAsync(json).then(
|
|
|
|
|
(u) => new Follow(u, instanceDomain),
|
|
|
|
|
);
|
2025-04-08 16:01:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class FollowAccept extends Entity {
|
2025-05-23 17:29:27 +02:00
|
|
|
public static override name = "FollowAccept";
|
2025-04-08 16:01:10 +02:00
|
|
|
|
2025-05-23 17:29:27 +02:00
|
|
|
public constructor(
|
|
|
|
|
public override data: z.infer<typeof FollowAcceptSchema>,
|
2026-04-03 13:34:19 +02:00
|
|
|
instanceDomain: string,
|
2025-05-23 17:29:27 +02:00
|
|
|
) {
|
2026-04-03 13:34:19 +02:00
|
|
|
super(data, instanceDomain);
|
2025-04-08 16:01:10 +02:00
|
|
|
}
|
|
|
|
|
|
2026-02-25 02:34:27 +01:00
|
|
|
public get author(): Reference {
|
2026-04-03 13:34:19 +02:00
|
|
|
return Reference.fromString(this.data.author, this.instanceDomain);
|
2026-02-25 02:34:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get follower(): Reference {
|
2026-04-03 13:34:19 +02:00
|
|
|
return Reference.fromString(this.data.follower, this.instanceDomain);
|
2026-02-25 02:34:27 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-03 13:34:19 +02:00
|
|
|
public static override fromJSON(
|
|
|
|
|
json: JSONObject,
|
|
|
|
|
instanceDomain: string,
|
|
|
|
|
): Promise<FollowAccept> {
|
2025-04-08 16:01:10 +02:00
|
|
|
return FollowAcceptSchema.parseAsync(json).then(
|
2026-04-03 13:34:19 +02:00
|
|
|
(u) => new FollowAccept(u, instanceDomain),
|
2025-04-08 16:01:10 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class FollowReject extends Entity {
|
2025-05-23 17:29:27 +02:00
|
|
|
public static override name = "FollowReject";
|
2025-04-08 16:01:10 +02:00
|
|
|
|
2025-05-23 17:29:27 +02:00
|
|
|
public constructor(
|
|
|
|
|
public override data: z.infer<typeof FollowRejectSchema>,
|
2026-04-03 13:34:19 +02:00
|
|
|
instanceDomain: string,
|
2025-05-23 17:29:27 +02:00
|
|
|
) {
|
2026-04-03 13:34:19 +02:00
|
|
|
super(data, instanceDomain);
|
2025-04-08 16:01:10 +02:00
|
|
|
}
|
|
|
|
|
|
2026-02-25 02:34:27 +01:00
|
|
|
public get author(): Reference {
|
2026-04-03 13:34:19 +02:00
|
|
|
return Reference.fromString(this.data.author, this.instanceDomain);
|
2026-02-25 02:34:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get follower(): Reference {
|
2026-04-03 13:34:19 +02:00
|
|
|
return Reference.fromString(this.data.follower, this.instanceDomain);
|
2026-02-25 02:34:27 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-03 13:34:19 +02:00
|
|
|
public static override fromJSON(
|
|
|
|
|
json: JSONObject,
|
|
|
|
|
instanceDomain: string,
|
|
|
|
|
): Promise<FollowReject> {
|
2025-04-08 16:01:10 +02:00
|
|
|
return FollowRejectSchema.parseAsync(json).then(
|
2026-04-03 13:34:19 +02:00
|
|
|
(u) => new FollowReject(u, instanceDomain),
|
2025-04-08 16:01:10 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class Unfollow extends Entity {
|
2025-05-23 17:29:27 +02:00
|
|
|
public static override name = "Unfollow";
|
2025-04-08 16:01:10 +02:00
|
|
|
|
2026-04-03 13:34:19 +02:00
|
|
|
public constructor(
|
|
|
|
|
public override data: z.infer<typeof UnfollowSchema>,
|
|
|
|
|
instanceDomain: string,
|
|
|
|
|
) {
|
|
|
|
|
super(data, instanceDomain);
|
2025-04-08 16:01:10 +02:00
|
|
|
}
|
|
|
|
|
|
2026-02-25 02:34:27 +01:00
|
|
|
public get author(): Reference {
|
2026-04-03 13:34:19 +02:00
|
|
|
return Reference.fromString(this.data.author, this.instanceDomain);
|
2026-02-25 02:34:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public get followee(): Reference {
|
2026-04-03 13:34:19 +02:00
|
|
|
return Reference.fromString(this.data.followee, this.instanceDomain);
|
2026-02-25 02:34:27 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-03 13:34:19 +02:00
|
|
|
public static override fromJSON(
|
|
|
|
|
json: JSONObject,
|
|
|
|
|
instanceDomain: string,
|
|
|
|
|
): Promise<Unfollow> {
|
|
|
|
|
return UnfollowSchema.parseAsync(json).then(
|
|
|
|
|
(u) => new Unfollow(u, instanceDomain),
|
|
|
|
|
);
|
2025-04-08 16:01:10 +02:00
|
|
|
}
|
|
|
|
|
}
|