From 671c5e7c12feb187c17633baa239bddd2d92a6c1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 29 Apr 2018 04:44:58 +0900 Subject: [PATCH] wip --- src/remote/activitypub/kernel/announce/note.ts | 15 +++++++++++---- src/remote/activitypub/models/note.ts | 13 ++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/remote/activitypub/kernel/announce/note.ts b/src/remote/activitypub/kernel/announce/note.ts index e2f3806d7..fe645b07b 100644 --- a/src/remote/activitypub/kernel/announce/note.ts +++ b/src/remote/activitypub/kernel/announce/note.ts @@ -5,6 +5,7 @@ import post from '../../../../services/note/create'; import { IRemoteUser } from '../../../../models/user'; import { IAnnounce, INote } from '../../type'; import { fetchNote, resolveNote } from '../../models/note'; +import { resolvePerson } from '../../models/person'; const log = debug('misskey:activitypub'); @@ -30,16 +31,22 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity: //#region Visibility let visibility = 'public'; - if (!activity.to.includes('https://www.w3.org/ns/activitystreams#Public')) visibility = 'home'; - if (activity.cc.length == 0) visibility = 'followers'; - // TODO - if (visibility != 'public') throw new Error('unspported visibility'); + let visibleUsers = []; + if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) { + if (note.cc.includes('https://www.w3.org/ns/activitystreams#Public')) { + visibility = 'home'; + } else { + visibility = 'specified'; + visibleUsers = await Promise.all(note.to.map(uri => resolvePerson(uri))); + } + } if (activity.cc.length == 0) visibility = 'followers'; //#endergion await post(actor, { createdAt: new Date(activity.published), renote, visibility, + visibleUsers, uri }); } diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index c0f67cb2f..9a0cc4e0c 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -65,10 +65,16 @@ export async function createNote(value: any, resolver?: Resolver, silent = false //#region Visibility let visibility = 'public'; - if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) visibility = 'home'; + let visibleUsers = []; + if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) { + if (note.cc.includes('https://www.w3.org/ns/activitystreams#Public')) { + visibility = 'home'; + } else { + visibility = 'specified'; + visibleUsers = await Promise.all(note.to.map(uri => resolvePerson(uri))); + } + } if (note.cc.length == 0) visibility = 'followers'; - // TODO - if (visibility != 'public') return null; //#endergion // 添付メディア @@ -99,6 +105,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false viaMobile: false, geo: undefined, visibility, + visibleUsers, uri: note.id }, silent); }