summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-04-07 15:54:11 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-04-07 15:54:11 +0900
commit7dc06b3d4383321ef85fa9bf2a1bc1d16ecab8c2 (patch)
treeaf20961ef02617b39e6f77c036d95bc1ebd7c967 /src
parentAdd todo (diff)
downloadsharkey-7dc06b3d4383321ef85fa9bf2a1bc1d16ecab8c2.tar.gz
sharkey-7dc06b3d4383321ef85fa9bf2a1bc1d16ecab8c2.tar.bz2
sharkey-7dc06b3d4383321ef85fa9bf2a1bc1d16ecab8c2.zip
Refactor
Diffstat (limited to 'src')
-rw-r--r--src/remote/activitypub/act/undo/follow.ts25
-rw-r--r--src/remote/activitypub/act/undo/index.ts (renamed from src/remote/activitypub/act/undo.ts)2
2 files changed, 26 insertions, 1 deletions
diff --git a/src/remote/activitypub/act/undo/follow.ts b/src/remote/activitypub/act/undo/follow.ts
new file mode 100644
index 0000000000..b1c462a3b0
--- /dev/null
+++ b/src/remote/activitypub/act/undo/follow.ts
@@ -0,0 +1,25 @@
+import parseAcct from '../../../../acct/parse';
+import User from '../../../../models/user';
+import config from '../../../../config';
+import unfollow from '../../../../services/following/delete';
+
+export default async (actor, activity): Promise<void> => {
+ const prefix = config.url + '/@';
+ const id = activity.object.id || activity.object;
+
+ if (!id.startsWith(prefix)) {
+ return null;
+ }
+
+ const { username, host } = parseAcct(id.slice(prefix.length));
+ if (host !== null) {
+ throw new Error();
+ }
+
+ const followee = await User.findOne({ username, host });
+ if (followee === null) {
+ throw new Error();
+ }
+
+ await unfollow(actor, followee, activity);
+};
diff --git a/src/remote/activitypub/act/undo.ts b/src/remote/activitypub/act/undo/index.ts
index 9d9f6b0359..ecd9944b42 100644
--- a/src/remote/activitypub/act/undo.ts
+++ b/src/remote/activitypub/act/undo/index.ts
@@ -1,4 +1,4 @@
-import unfollow from './unfollow';
+import unfollow from './follow';
export default async (actor, activity): Promise<void> => {
if ('actor' in activity && actor.account.uri !== activity.actor) {