From 783453897f04869c213dfa7aef7e8d33490ff47a Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Wed, 4 Apr 2018 19:51:41 +0900 Subject: [PATCH] Allow to undo Create activity --- .../activitypub/act/{delete/index.ts => delete.ts} | 9 +++------ src/remote/activitypub/act/delete/post.ts | 10 ---------- src/remote/activitypub/act/undo/index.ts | 5 ++++- src/remote/activitypub/delete/index.ts | 10 ++++++++++ src/remote/activitypub/delete/post.ts | 13 +++++++++++++ 5 files changed, 30 insertions(+), 17 deletions(-) rename src/remote/activitypub/act/{delete/index.ts => delete.ts} (70%) delete mode 100644 src/remote/activitypub/act/delete/post.ts create mode 100644 src/remote/activitypub/delete/index.ts create mode 100644 src/remote/activitypub/delete/post.ts diff --git a/src/remote/activitypub/act/delete/index.ts b/src/remote/activitypub/act/delete.ts similarity index 70% rename from src/remote/activitypub/act/delete/index.ts rename to src/remote/activitypub/act/delete.ts index eabf9a043..f9eb4dd08 100644 --- a/src/remote/activitypub/act/delete/index.ts +++ b/src/remote/activitypub/act/delete.ts @@ -1,5 +1,5 @@ -import create from '../../create'; -import deletePost from './post'; +import create from '../create'; +import deleteObject from '../delete'; export default async (resolver, actor, activity) => { if ('actor' in activity && actor.account.uri !== activity.actor) { @@ -14,10 +14,7 @@ export default async (resolver, actor, activity) => { return; } - switch (result.object.$ref) { - case 'posts': - await deletePost(result.object); - } + await deleteObject(result); })); return null; diff --git a/src/remote/activitypub/act/delete/post.ts b/src/remote/activitypub/act/delete/post.ts deleted file mode 100644 index 1b748afe8..000000000 --- a/src/remote/activitypub/act/delete/post.ts +++ /dev/null @@ -1,10 +0,0 @@ -import Post from '../../../../models/post'; -import queue from '../../../../queue'; - -export default ({ $id }) => Promise.all([ - Post.findOneAndDelete({ _id: $id }), - new Promise((resolve, reject) => queue.create('db', { - type: 'deletePostDependents', - id: $id - }).delay(65536).save(error => error ? reject(error) : resolve())) -]); diff --git a/src/remote/activitypub/act/undo/index.ts b/src/remote/activitypub/act/undo/index.ts index 11c7ec0c8..aa60d3a4f 100644 --- a/src/remote/activitypub/act/undo/index.ts +++ b/src/remote/activitypub/act/undo/index.ts @@ -1,4 +1,5 @@ import act from '../../act'; +import deleteObject from '../../delete'; import unfollow from './unfollow'; import Resolver from '../../resolver'; @@ -12,7 +13,7 @@ export default async (resolver: Resolver, actor, activity): Promise => { await Promise.all(results.map(async promisedResult => { const result = await promisedResult; - if (result === null) { + if (result === null || await deleteObject(result) !== null) { return; } @@ -21,4 +22,6 @@ export default async (resolver: Resolver, actor, activity): Promise => { await unfollow(result.object); } })); + + return null; }; diff --git a/src/remote/activitypub/delete/index.ts b/src/remote/activitypub/delete/index.ts new file mode 100644 index 000000000..bc9104284 --- /dev/null +++ b/src/remote/activitypub/delete/index.ts @@ -0,0 +1,10 @@ +import deletePost from './post'; + +export default async ({ object }) => { + switch (object.$ref) { + case 'posts': + return deletePost(object); + } + + return null; +}; diff --git a/src/remote/activitypub/delete/post.ts b/src/remote/activitypub/delete/post.ts new file mode 100644 index 000000000..f6c816647 --- /dev/null +++ b/src/remote/activitypub/delete/post.ts @@ -0,0 +1,13 @@ +import Post from '../../../models/post'; +import queue from '../../../queue'; + +export default async ({ $id }) => { + const promisedDeletion = Post.findOneAndDelete({ _id: $id }); + + await new Promise((resolve, reject) => queue.create('db', { + type: 'deletePostDependents', + id: $id + }).delay(65536).save(error => error ? reject(error) : resolve())); + + return promisedDeletion; +};