FoundKey/packages/backend/src/remote/activitypub/kernel/undo/accept.ts
Johann150 1516ddfc9b
refactor: remove CacheableUser & co
The CacheableUser, CacheableLocalUser and CacheableRemoteUser are
identical types to User, ILocalUser and IRemoteUser so it seems
nonsensical to have different types for them.
2023-05-18 13:25:57 +02:00

27 lines
760 B
TypeScript

import unfollow from '@/services/following/delete.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { Followings } from '@/models/index.js';
import { DbResolver } from '@/remote/activitypub/db-resolver.js';
import { IAccept } from '@/remote/activitypub/type.js';
export default async (actor: IRemoteUser, activity: IAccept): Promise<string> => {
const dbResolver = new DbResolver();
const follower = await dbResolver.getUserFromApId(activity.object);
if (follower == null) {
return 'skip: follower not found';
}
const following = await Followings.countBy({
followerId: follower.id,
followeeId: actor.id,
});
if (following) {
await unfollow(follower, actor);
return 'ok: unfollowed';
}
return 'skip: not followed';
};