mirror of
https://github.com/MisskeyIO/misskey
synced 2024-12-11 13:18:51 +09:00
Receive Update activity
This commit is contained in:
parent
15eaebe522
commit
3efffbcf22
@ -5,7 +5,7 @@ const httpSignature = require('http-signature');
|
||||
import parseAcct from '../../../misc/acct/parse';
|
||||
import User, { IRemoteUser } from '../../../models/user';
|
||||
import perform from '../../../remote/activitypub/perform';
|
||||
import { resolvePerson } from '../../../remote/activitypub/models/person';
|
||||
import { resolvePerson, updatePerson } from '../../../remote/activitypub/models/person';
|
||||
import { toUnicode } from 'punycode';
|
||||
import { URL } from 'url';
|
||||
|
||||
@ -44,11 +44,6 @@ export default async (job: bq.Job, done: any): Promise<void> => {
|
||||
}
|
||||
|
||||
user = await User.findOne({ usernameLower: username, host: host.toLowerCase() }) as IRemoteUser;
|
||||
|
||||
// アクティビティを送信してきたユーザーがまだMisskeyサーバーに登録されていなかったら登録する
|
||||
if (user === null) {
|
||||
user = await resolvePerson(activity.actor) as IRemoteUser;
|
||||
}
|
||||
} else {
|
||||
// アクティビティ内のホストの検証
|
||||
const host = toUnicode(new URL(signature.keyId).hostname.toLowerCase());
|
||||
@ -64,11 +59,26 @@ export default async (job: bq.Job, done: any): Promise<void> => {
|
||||
host: { $ne: null },
|
||||
'publicKey.id': signature.keyId
|
||||
}) as IRemoteUser;
|
||||
}
|
||||
|
||||
// アクティビティを送信してきたユーザーがまだMisskeyサーバーに登録されていなかったら登録する
|
||||
if (user === null) {
|
||||
user = await resolvePerson(activity.actor) 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);
|
||||
}
|
||||
}
|
||||
done();
|
||||
return;
|
||||
}
|
||||
|
||||
// アクティビティを送信してきたユーザーがまだMisskeyサーバーに登録されていなかったら登録する
|
||||
if (user === null) {
|
||||
user = await resolvePerson(activity.actor) as IRemoteUser;
|
||||
}
|
||||
|
||||
if (user === null) {
|
||||
|
@ -216,10 +216,12 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<IU
|
||||
|
||||
/**
|
||||
* Personの情報を更新します。
|
||||
*
|
||||
* Misskeyに対象のPersonが登録されていなければ無視します。
|
||||
* @param uri URI of Person
|
||||
* @param resolver Resolver
|
||||
* @param hint Hint of Person object (この値が正当なPersonの場合、Remote resolveをせずに更新に利用します)
|
||||
*/
|
||||
export async function updatePerson(uri: string, resolver?: Resolver): Promise<void> {
|
||||
export async function updatePerson(uri: string, resolver?: Resolver, hint?: object): Promise<void> {
|
||||
if (typeof uri !== 'string') throw 'uri is not string';
|
||||
|
||||
// URIがこのサーバーを指しているならスキップ
|
||||
@ -237,7 +239,7 @@ export async function updatePerson(uri: string, resolver?: Resolver): Promise<vo
|
||||
|
||||
if (resolver == null) resolver = new Resolver();
|
||||
|
||||
const object = await resolver.resolve(uri) as any;
|
||||
const object = hint || await resolver.resolve(uri) as any;
|
||||
|
||||
const err = validatePerson(object, uri);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user