import { renderActivity } from "../../../remote/activitypub/renderer/index.js";
import renderAcceptFollow from "../../../remote/activitypub/renderer/accept-follow.js";
import { deliver } from "../../../queue/index.js";
import { publishMainStream } from "../../stream.js";
import { insertFollowingDoc } from "../create.js";
import { FollowRequests, Users } from "../../../models/index.js";
import { IdentifiableError } from "../../../misc/identifiable-error.js";
export default async function(followee, follower) {
    const request = await FollowRequests.findOneBy({
        followeeId: followee.id,
        followerId: follower.id
    });
    if (request == null) {
        throw new IdentifiableError("8884c2dd-5795-4ac9-b27e-6a01d38190f9", "No follow request.");
    }
    await insertFollowingDoc(followee, follower);
    if (Users.isRemoteUser(follower) && Users.isLocalUser(followee)) {
        const content = renderActivity(renderAcceptFollow(follower, followee, request.requestId));
        deliver(followee, content, follower.inbox);
    }
    Users.pack(followee.id, followee, {
        detail: true
    }).then((packed)=>publishMainStream(followee.id, "meUpdated", packed));
}
