blob: 73a164030b4ac3efe864230e1636367ce51fde7f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import unfollow from '../../../../services/following/delete';
import cancelRequest from '../../../../services/following/requests/cancel';
import { IFollow } from '../../type';
import { IRemoteUser } from '../../../../models/entities/user';
import { FollowRequests, Followings } from '../../../../models';
import DbResolver from '../../db-resolver';
export default async (actor: IRemoteUser, activity: IFollow): Promise<string> => {
const dbResolver = new DbResolver();
const followee = await dbResolver.getUserFromApId(activity.object);
if (followee == null) {
return `skip: followee not found`;
}
if (followee.host != null) {
return `skip: フォロー解除しようとしているユーザーはローカルユーザーではありません`;
}
const req = await FollowRequests.findOne({
followerId: actor.id,
followeeId: followee.id
});
const following = await Followings.findOne({
followerId: actor.id,
followeeId: followee.id
});
if (req) {
await cancelRequest(followee, actor);
return `ok: follow request canceled`;
}
if (following) {
await unfollow(actor, followee);
return `ok: unfollowed`;
}
return `skip: リクエストもフォローもされていない`;
};
|