Recv Update
This commit is contained in:
parent
63d8bbe29d
commit
ffda39c093
|
@ -62,16 +62,15 @@ export default async (job: bq.Job, done: any): Promise<void> => {
|
||||||
}) as IRemoteUser;
|
}) as IRemoteUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update activityの場合は、ここで署名検証/更新処理まで実施して終了
|
// Update<Person> activityの場合は、ここで署名検証/更新処理まで実施して終了
|
||||||
if (activity.type === 'Update') {
|
if (activity.type === 'Update'
|
||||||
if (activity.object && activity.object.type === 'Person') {
|
&& activity.object && activity.object.type === 'Person') {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
console.warn('Update activity received, but user not registed.');
|
console.warn('Update activity received, but user not registed.');
|
||||||
} else if (!httpSignature.verifySignature(signature, user.publicKey.publicKeyPem)) {
|
} else if (!httpSignature.verifySignature(signature, user.publicKey.publicKeyPem)) {
|
||||||
console.warn('Update activity received, but signature verification failed.');
|
console.warn('Update activity received, but signature verification failed.');
|
||||||
} else {
|
} else {
|
||||||
updatePerson(activity.actor, null, activity.object);
|
updatePerson(activity.actor, null, activity.object);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -11,6 +11,7 @@ import reject from './reject';
|
||||||
import add from './add';
|
import add from './add';
|
||||||
import remove from './remove';
|
import remove from './remove';
|
||||||
import block from './block';
|
import block from './block';
|
||||||
|
import update from './update';
|
||||||
|
|
||||||
const self = async (actor: IRemoteUser, activity: Object): Promise<void> => {
|
const self = async (actor: IRemoteUser, activity: Object): Promise<void> => {
|
||||||
switch (activity.type) {
|
switch (activity.type) {
|
||||||
|
@ -58,6 +59,10 @@ const self = async (actor: IRemoteUser, activity: Object): Promise<void> => {
|
||||||
await block(actor, activity);
|
await block(actor, activity);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'Update':
|
||||||
|
await update(actor, activity);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'Collection':
|
case 'Collection':
|
||||||
case 'OrderedCollection':
|
case 'OrderedCollection':
|
||||||
// TODO
|
// TODO
|
||||||
|
|
|
@ -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<void> => {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue