From 638d81b66ee48bab0264ab9bb71fd3feddad5a14 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Tue, 11 Dec 2018 20:18:12 +0900 Subject: Show user fields (#3590) --- src/remote/activitypub/models/person.ts | 23 +++++++++++++++++++++++ src/remote/activitypub/models/tag.ts | 1 + 2 files changed, 24 insertions(+) (limited to 'src/remote/activitypub') diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index 9bbc41e628..6f62da5ca7 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -17,6 +17,7 @@ import registerInstance from '../../../services/register-instance'; import Instance from '../../../models/instance'; import getDriveFileUrl from '../../../misc/get-drive-file-url'; import { IEmoji } from '../../../models/emoji'; +import { ITag } from './tag'; const log = debug('misskey:activitypub'); @@ -135,6 +136,10 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise { + console.log(`cat not extract fields: ${e}`); + }); + const isBot = object.type == 'Service'; // Create user @@ -164,6 +169,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise emoji.name); + const fields = await extractFields(person.attachment).catch(e => { + console.log(`cat not extract fields: ${e}`); + }); + // Update user await User.update({ _id: exist._id }, { $set: { @@ -346,6 +356,7 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: obje name: person.name, url: person.url, endpoints: person.endpoints, + fields, isBot: object.type == 'Service', isCat: (person as any).isCat === true, isLocked: person.manuallyApprovesFollowers, @@ -382,6 +393,18 @@ export async function resolvePerson(uri: string, verifier?: string, resolver?: R return await createPerson(uri, resolver); } +export async function extractFields(attachments: ITag[]) { + if (!attachments) return []; + + return attachments.filter(a => a.type === 'PropertyValue' && a.name && a.value) + .map(a => { + return { + name: a.name, + value: htmlToMFM(a.value) + }; + }); +} + export async function updateFeatured(userId: mongo.ObjectID) { const user = await User.findOne({ _id: userId }); if (!isRemoteUser(user)) return; diff --git a/src/remote/activitypub/models/tag.ts b/src/remote/activitypub/models/tag.ts index 5cdbfa43b1..7c9b41eb22 100644 --- a/src/remote/activitypub/models/tag.ts +++ b/src/remote/activitypub/models/tag.ts @@ -7,6 +7,7 @@ export type ITag = { id: string; type: string; name?: string; + value?: string; updated?: Date; icon?: IIcon; }; -- cgit v1.2.3-freya