From ffda39c0936d8e023f64603edabeb8e0eb9fc370 Mon Sep 17 00:00:00 2001 From: mei23 Date: Mon, 21 Jan 2019 04:49:15 +0900 Subject: [PATCH] Recv Update --- src/queue/processors/http/process-inbox.ts | 19 +++++------ src/remote/activitypub/kernel/index.ts | 5 +++ src/remote/activitypub/kernel/update/index.ts | 34 +++++++++++++++++++ 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 src/remote/activitypub/kernel/update/index.ts diff --git a/src/queue/processors/http/process-inbox.ts b/src/queue/processors/http/process-inbox.ts index 1ab5f094eec6..e28f356922d7 100644 --- a/src/queue/processors/http/process-inbox.ts +++ b/src/queue/processors/http/process-inbox.ts @@ -62,16 +62,15 @@ export default async (job: bq.Job, done: any): Promise => { }) as IRemoteUser; } - // Update activityの場合は、ここで署名検証/更新処理まで実施して終了 - if (activity.type === 'Update') { - if (activity.object && activity.object.type === 'Person') { - if (user == null) { - console.warn('Update activity received, but user not registed.'); - } else if (!httpSignature.verifySignature(signature, user.publicKey.publicKeyPem)) { - console.warn('Update activity received, but signature verification failed.'); - } else { - updatePerson(activity.actor, null, activity.object); - } + // Update activityの場合は、ここで署名検証/更新処理まで実施して終了 + if (activity.type === 'Update' + && activity.object && activity.object.type === 'Person') { + if (user == null) { + console.warn('Update activity received, but user not registed.'); + } else if (!httpSignature.verifySignature(signature, user.publicKey.publicKeyPem)) { + console.warn('Update activity received, but signature verification failed.'); + } else { + updatePerson(activity.actor, null, activity.object); } done(); return; diff --git a/src/remote/activitypub/kernel/index.ts b/src/remote/activitypub/kernel/index.ts index 61bb89f5e9f0..b7ac358cfccb 100644 --- a/src/remote/activitypub/kernel/index.ts +++ b/src/remote/activitypub/kernel/index.ts @@ -11,6 +11,7 @@ import reject from './reject'; import add from './add'; import remove from './remove'; import block from './block'; +import update from './update'; const self = async (actor: IRemoteUser, activity: Object): Promise => { switch (activity.type) { @@ -58,6 +59,10 @@ const self = async (actor: IRemoteUser, activity: Object): Promise => { await block(actor, activity); break; + case 'Update': + await update(actor, activity); + break; + case 'Collection': case 'OrderedCollection': // TODO diff --git a/src/remote/activitypub/kernel/update/index.ts b/src/remote/activitypub/kernel/update/index.ts new file mode 100644 index 000000000000..b3c68ab6dad3 --- /dev/null +++ b/src/remote/activitypub/kernel/update/index.ts @@ -0,0 +1,34 @@ +import { IRemoteUser } from '../../../../models/user'; +import * as debug from 'debug'; +import { IUpdate } from '../../type'; +import { extractPollFromQuestion } from '../../models/question'; +import Note from '../../../../models/note'; + +const log = debug('misskey:activitypub'); + +export default async (actor: IRemoteUser, activity: IUpdate): Promise => { + const id = typeof activity.object == 'string' ? activity.object : activity.object.id; + const type = (activity.object as any).type; + + log(`Update<${type}>: ${id}`); + + switch (type) { + case 'Question': + const note = await Note.findOne({ + questionUri: id + }); + + if (note === null) throw 'note not found'; + + const poll = await extractPollFromQuestion(id); + + await Note.update({ + _id: note._id + }, { + $set: { + poll + } + }); + break; + } +};