diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2018-04-07 16:26:50 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-07 16:26:50 +0900 |
| commit | 2547891f940a2872fcfb2b33cd33d4f7a42ca7bc (patch) | |
| tree | 5cba4ae9cdfd63e7e1ef74a002a7b742183e8d3c /src/remote/activitypub/act/delete | |
| parent | Merge pull request #1410 from akihikodaki/objec (diff) | |
| parent | Refactor (diff) | |
| download | misskey-2547891f940a2872fcfb2b33cd33d4f7a42ca7bc.tar.gz misskey-2547891f940a2872fcfb2b33cd33d4f7a42ca7bc.tar.bz2 misskey-2547891f940a2872fcfb2b33cd33d4f7a42ca7bc.zip | |
Merge pull request #1397 from syuilo/refactor
Refactor
Diffstat (limited to 'src/remote/activitypub/act/delete')
| -rw-r--r-- | src/remote/activitypub/act/delete/index.ts | 36 | ||||
| -rw-r--r-- | src/remote/activitypub/act/delete/note.ts | 30 |
2 files changed, 66 insertions, 0 deletions
diff --git a/src/remote/activitypub/act/delete/index.ts b/src/remote/activitypub/act/delete/index.ts new file mode 100644 index 0000000000..e34577b310 --- /dev/null +++ b/src/remote/activitypub/act/delete/index.ts @@ -0,0 +1,36 @@ +import Resolver from '../../resolver'; +import deleteNote from './note'; +import Post from '../../../../models/post'; +import { IRemoteUser } from '../../../../models/user'; + +/** + * 削除アクティビティを捌きます + */ +export default async (actor: IRemoteUser, activity): Promise<void> => { + if ('actor' in activity && actor.account.uri !== activity.actor) { + throw new Error('invalid actor'); + } + + const resolver = new Resolver(); + + const object = await resolver.resolve(activity.object); + + const uri = (object as any).id; + + switch (object.type) { + case 'Note': + deleteNote(actor, uri); + break; + + case 'Tombstone': + const post = await Post.findOne({ uri }); + if (post != null) { + deleteNote(actor, uri); + } + break; + + default: + console.warn(`Unknown type: ${object.type}`); + break; + } +}; diff --git a/src/remote/activitypub/act/delete/note.ts b/src/remote/activitypub/act/delete/note.ts new file mode 100644 index 0000000000..8e9447b481 --- /dev/null +++ b/src/remote/activitypub/act/delete/note.ts @@ -0,0 +1,30 @@ +import * as debug from 'debug'; + +import Post from '../../../../models/post'; +import { IRemoteUser } from '../../../../models/user'; + +const log = debug('misskey:activitypub'); + +export default async function(actor: IRemoteUser, uri: string): Promise<void> { + log(`Deleting the Note: ${uri}`); + + const post = await Post.findOne({ uri }); + + if (post == null) { + throw new Error('post not found'); + } + + if (!post.userId.equals(actor._id)) { + throw new Error('投稿を削除しようとしているユーザーは投稿の作成者ではありません'); + } + + Post.update({ _id: post._id }, { + $set: { + deletedAt: new Date(), + text: null, + textHtml: null, + mediaIds: [], + poll: null + } + }); +} |