1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-11-30 15:58:09 +09:00

Allow to undo Create activity

This commit is contained in:
Akihiko Odaki 2018-04-04 19:51:41 +09:00
parent 210cb57aa5
commit 783453897f
5 changed files with 30 additions and 17 deletions

View File

@ -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;

View File

@ -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()))
]);

View File

@ -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<void> => {
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<void> => {
await unfollow(result.object);
}
}));
return null;
};

View File

@ -0,0 +1,10 @@
import deletePost from './post';
export default async ({ object }) => {
switch (object.$ref) {
case 'posts':
return deletePost(object);
}
return null;
};

View File

@ -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;
};