From 22830965e341c9c961e072b2e92cb7c404f8624d Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sun, 20 Jan 2019 03:07:12 +0900 Subject: AP Undo Like (#3933) * AP Undo Like * rename --- src/remote/activitypub/kernel/undo/index.ts | 6 +++++- src/remote/activitypub/kernel/undo/like.ts | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/remote/activitypub/kernel/undo/like.ts (limited to 'src/remote/activitypub') diff --git a/src/remote/activitypub/kernel/undo/index.ts b/src/remote/activitypub/kernel/undo/index.ts index ba56dd6328..471988f052 100644 --- a/src/remote/activitypub/kernel/undo/index.ts +++ b/src/remote/activitypub/kernel/undo/index.ts @@ -1,9 +1,10 @@ import * as debug from 'debug'; import { IRemoteUser } from '../../../../models/user'; -import { IUndo, IFollow, IBlock } from '../../type'; +import { IUndo, IFollow, IBlock, ILike } from '../../type'; import unfollow from './follow'; import unblock from './block'; +import undoLike from './like'; import Resolver from '../../resolver'; const log = debug('misskey:activitypub'); @@ -35,6 +36,9 @@ export default async (actor: IRemoteUser, activity: IUndo): Promise => { case 'Block': unblock(actor, object as IBlock); break; + case 'Like': + undoLike(actor, object as ILike); + break; } return null; diff --git a/src/remote/activitypub/kernel/undo/like.ts b/src/remote/activitypub/kernel/undo/like.ts new file mode 100644 index 0000000000..b324ec854c --- /dev/null +++ b/src/remote/activitypub/kernel/undo/like.ts @@ -0,0 +1,21 @@ +import * as mongo from 'mongodb'; +import { IRemoteUser } from '../../../../models/user'; +import { ILike } from '../../type'; +import Note from '../../../../models/note'; +import deleteReaction from '../../../../services/note/reaction/delete'; + +/** + * Process Undo.Like activity + */ +export default async (actor: IRemoteUser, activity: ILike): Promise => { + const id = typeof activity.object == 'string' ? activity.object : activity.object.id; + + const noteId = new mongo.ObjectID(id.split('/').pop()); + + const note = await Note.findOne({ _id: noteId }); + if (note === null) { + throw 'note not found'; + } + + await deleteReaction(actor, note); +}; -- cgit v1.2.3-freya