summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/kernel/undo/follow.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/remote/activitypub/kernel/undo/follow.ts')
-rw-r--r--src/remote/activitypub/kernel/undo/follow.ts24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/remote/activitypub/kernel/undo/follow.ts b/src/remote/activitypub/kernel/undo/follow.ts
index 2a42f83907..73a164030b 100644
--- a/src/remote/activitypub/kernel/undo/follow.ts
+++ b/src/remote/activitypub/kernel/undo/follow.ts
@@ -1,26 +1,20 @@
-import config from '../../../../config';
import unfollow from '../../../../services/following/delete';
import cancelRequest from '../../../../services/following/requests/cancel';
import { IFollow } from '../../type';
import { IRemoteUser } from '../../../../models/entities/user';
-import { Users, FollowRequests, Followings } from '../../../../models';
+import { FollowRequests, Followings } from '../../../../models';
+import DbResolver from '../../db-resolver';
-export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
- const id = typeof activity.object === 'string' ? activity.object : activity.object.id;
- if (id == null) throw new Error('missing id');
-
- if (!id.startsWith(config.url + '/')) {
- return;
- }
-
- const followee = await Users.findOne(id.split('/').pop());
+export default async (actor: IRemoteUser, activity: IFollow): Promise<string> => {
+ const dbResolver = new DbResolver();
+ const followee = await dbResolver.getUserFromApId(activity.object);
if (followee == null) {
- throw new Error('followee not found');
+ return `skip: followee not found`;
}
if (followee.host != null) {
- throw new Error('フォロー解除しようとしているユーザーはローカルユーザーではありません');
+ return `skip: フォロー解除しようとしているユーザーはローカルユーザーではありません`;
}
const req = await FollowRequests.findOne({
@@ -35,9 +29,13 @@ export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
if (req) {
await cancelRequest(followee, actor);
+ return `ok: follow request canceled`;
}
if (following) {
await unfollow(actor, followee);
+ return `ok: unfollowed`;
}
+
+ return `skip: リクエストもフォローもされていない`;
};