From aa573c00631181c2e974ef8b3c061678dc9571f1 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 8 Feb 2020 21:40:06 +0900 Subject: [PATCH] =?UTF-8?q?Create=20Activity=E3=81=A7attributedTo=E3=81=AE?= =?UTF-8?q?=E8=A3=9C=E5=AE=8C=E3=81=A8audience=E3=81=AE=E3=82=B3=E3=83=94?= =?UTF-8?q?=E3=83=BC=E3=82=92=E8=A1=8C=E3=81=86=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=20(#5873)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * attributedTo * Create * copy audiences between activity <=> object * やっぱり匿名GETのpublicは必要 * fix --- src/remote/activitypub/kernel/create/index.ts | 17 +++++++++++++++++ src/remote/activitypub/kernel/create/note.ts | 2 +- src/remote/activitypub/models/note.ts | 16 +++++----------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/remote/activitypub/kernel/create/index.ts b/src/remote/activitypub/kernel/create/index.ts index 5210afe28b..108cfedf41 100644 --- a/src/remote/activitypub/kernel/create/index.ts +++ b/src/remote/activitypub/kernel/create/index.ts @@ -3,6 +3,7 @@ import { IRemoteUser } from '../../../../models/entities/user'; import createNote from './note'; import { ICreate, getApId, validPost } from '../../type'; import { apLogger } from '../../logger'; +import { toArray, concat, unique } from '../../../../prelude/array'; const logger = apLogger; @@ -11,6 +12,22 @@ export default async (actor: IRemoteUser, activity: ICreate): Promise => { logger.info(`Create: ${uri}`); + // copy audiences between activity <=> object. + if (typeof activity.object === 'object') { + const to = unique(concat([toArray(activity.to), toArray(activity.object.to)])); + const cc = unique(concat([toArray(activity.cc), toArray(activity.object.cc)])); + + activity.to = to; + activity.cc = cc; + activity.object.to = to; + activity.object.cc = cc; + } + + // If there is no attributedTo, use Activity actor. + if (typeof activity.object === 'object' && !activity.object.attributedTo) { + activity.object.attributedTo = activity.actor; + } + const resolver = new Resolver(); const object = await resolver.resolve(activity.object).catch(e => { diff --git a/src/remote/activitypub/kernel/create/note.ts b/src/remote/activitypub/kernel/create/note.ts index e393440162..d7027b8f3f 100644 --- a/src/remote/activitypub/kernel/create/note.ts +++ b/src/remote/activitypub/kernel/create/note.ts @@ -15,7 +15,7 @@ export default async function(resolver: Resolver, actor: IRemoteUser, note: IObj try { const exist = await fetchNote(note); if (exist == null) { - await createNote(note, resolver, silent, activity); + await createNote(note, resolver, silent); } } finally { unlock(); diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index 3bd6fc679b..70ceb5e503 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -17,7 +17,7 @@ import { deliverQuestionUpdate } from '../../../services/note/polls/update'; import { extractDbHost, toPuny } from '../../../misc/convert-host'; import { Notes, Emojis, Polls, MessagingMessages } from '../../../models'; import { Note } from '../../../models/entities/note'; -import { IObject, getOneApId, getApId, validPost, ICreate, isCreate, IPost } from '../type'; +import { IObject, getOneApId, getApId, validPost, IPost } from '../type'; import { Emoji } from '../../../models/entities/emoji'; import { genId } from '../../../misc/gen-id'; import { fetchMeta } from '../../../misc/fetch-meta'; @@ -78,7 +78,7 @@ export async function fetchNote(value: string | IObject, resolver?: Resolver): P /** * Noteを作成します。 */ -export async function createNote(value: string | IObject, resolver?: Resolver, silent = false, activity?: ICreate): Promise { +export async function createNote(value: string | IObject, resolver?: Resolver, silent = false): Promise { if (resolver == null) resolver = new Resolver(); const object: any = await resolver.resolve(value); @@ -112,18 +112,12 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s const noteAudience = await parseAudience(actor, note.to, note.cc); let visibility = noteAudience.visibility; - let visibleUsers = noteAudience.visibleUsers; - let apMentions = noteAudience.mentionedUsers; + const visibleUsers = noteAudience.visibleUsers; + const apMentions = noteAudience.mentionedUsers; // Audience (to, cc) が指定されてなかった場合 if (visibility === 'specified' && visibleUsers.length === 0) { - if (activity && isCreate(activity)) { - // Create 起因ならば Activity を見る - const activityAudience = await parseAudience(actor, activity.to, activity.cc); - visibility = activityAudience.visibility; - visibleUsers = activityAudience.visibleUsers; - apMentions = activityAudience.mentionedUsers; - } else if (typeof value === 'string') { // 入力がstringならばresolverでGETが発生している + if (typeof value === 'string') { // 入力がstringならばresolverでGETが発生している // こちらから匿名GET出来たものならばpublic visibility = 'public'; }