summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/kernel/undo
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2018-04-11 20:27:09 +0900
committerGitHub <noreply@github.com>2018-04-11 20:27:09 +0900
commitd43fe853c3605696e2e57e240845d0fc9c284f61 (patch)
tree838914e262c0fca5737588a7bba64e2b9f3d8e5f /src/remote/activitypub/kernel/undo
parentUpdate README.md (diff)
parentwip #1443 (diff)
downloadmisskey-d43fe853c3605696e2e57e240845d0fc9c284f61.tar.gz
misskey-d43fe853c3605696e2e57e240845d0fc9c284f61.tar.bz2
misskey-d43fe853c3605696e2e57e240845d0fc9c284f61.zip
Merge pull request #1 from syuilo/master
追従
Diffstat (limited to 'src/remote/activitypub/kernel/undo')
-rw-r--r--src/remote/activitypub/kernel/undo/follow.ts24
-rw-r--r--src/remote/activitypub/kernel/undo/index.ts37
2 files changed, 61 insertions, 0 deletions
diff --git a/src/remote/activitypub/kernel/undo/follow.ts b/src/remote/activitypub/kernel/undo/follow.ts
new file mode 100644
index 0000000000..a85cb0305d
--- /dev/null
+++ b/src/remote/activitypub/kernel/undo/follow.ts
@@ -0,0 +1,24 @@
+import User, { IRemoteUser } from '../../../../models/user';
+import config from '../../../../config';
+import unfollow from '../../../../services/following/delete';
+import { IFollow } from '../../type';
+
+export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
+ const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
+
+ if (!id.startsWith(config.url + '/')) {
+ return null;
+ }
+
+ const followee = await User.findOne({ _id: id.split('/').pop() });
+
+ if (followee === null) {
+ throw new Error('followee not found');
+ }
+
+ if (followee.host != null) {
+ throw new Error('フォロー解除しようとしているユーザーはローカルユーザーではありません');
+ }
+
+ await unfollow(actor, followee, activity);
+};
diff --git a/src/remote/activitypub/kernel/undo/index.ts b/src/remote/activitypub/kernel/undo/index.ts
new file mode 100644
index 0000000000..71f547aeb9
--- /dev/null
+++ b/src/remote/activitypub/kernel/undo/index.ts
@@ -0,0 +1,37 @@
+import * as debug from 'debug';
+
+import { IRemoteUser } from '../../../../models/user';
+import { IUndo } from '../../type';
+import unfollow from './follow';
+import Resolver from '../../resolver';
+
+const log = debug('misskey:activitypub');
+
+export default async (actor: IRemoteUser, activity: IUndo): Promise<void> => {
+ if ('actor' in activity && actor.uri !== activity.actor) {
+ throw new Error('invalid actor');
+ }
+
+ const uri = activity.id || activity;
+
+ log(`Undo: ${uri}`);
+
+ const resolver = new Resolver();
+
+ let object;
+
+ try {
+ object = await resolver.resolve(activity.object);
+ } catch (e) {
+ log(`Resolution failed: ${e}`);
+ throw e;
+ }
+
+ switch (object.type) {
+ case 'Follow':
+ unfollow(actor, object);
+ break;
+ }
+
+ return null;
+};