From a89c20657262441701bb50cd83d9d317940fc857 Mon Sep 17 00:00:00 2001 From: mei23 Date: Fri, 17 Aug 2018 06:40:08 +0900 Subject: [PATCH] Fix Announce Activity --- .../activitypub/kernel/announce/note.ts | 4 +++- src/remote/activitypub/renderer/announce.ts | 20 ++++++++++++++----- src/services/note/create.ts | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/remote/activitypub/kernel/announce/note.ts b/src/remote/activitypub/kernel/announce/note.ts index 7aa6aa570..60f2b9baa 100644 --- a/src/remote/activitypub/kernel/announce/note.ts +++ b/src/remote/activitypub/kernel/announce/note.ts @@ -40,11 +40,13 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity: 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 if (note.to.includes(`${actor.uri}/followers`)) { // TODO: person.followerと照合するべき? + visibility = 'followers'; } else { visibility = 'specified'; visibleUsers = await Promise.all(note.to.map(uri => resolvePerson(uri))); } - } if (activity.cc.length == 0) visibility = 'followers'; + } //#endergion await post(actor, { diff --git a/src/remote/activitypub/renderer/announce.ts b/src/remote/activitypub/renderer/announce.ts index 7a3f88644..6d5a67b5c 100644 --- a/src/remote/activitypub/renderer/announce.ts +++ b/src/remote/activitypub/renderer/announce.ts @@ -1,5 +1,15 @@ -export default (id: string, object: any) => ({ - type: 'Announce', - id, - object -}); +import config from '../../../config'; +import { INote } from '../../../models/note'; + +export default (object: any, note: INote) => { + const attributedTo = `${config.url}/users/${note.userId}`; + + return { + id: `${config.url}/notes/${note._id}`, + type: 'Announce', + published: note.createdAt.toISOString(), + to: ['https://www.w3.org/ns/activitystreams#Public'], + cc: [attributedTo, `${attributedTo}/followers`], + object + }; +}; diff --git a/src/services/note/create.ts b/src/services/note/create.ts index d11a02ada..dd0086786 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -235,8 +235,8 @@ export default async (user: IUser, data: Option, silent = false) => new Promise< async function renderActivity(data: Option, note: INote) { const content = data.renote && data.text == null - ? renderAnnounce(note._id.toHexString(), data.renote.uri ? data.renote.uri : await renderNote(data.renote)) - : renderCreate(await renderNote(note)); + ? renderAnnounce(data.renote.uri ? data.renote.uri : await renderNote(data.renote), note) + : renderCreate(await renderNote(note)); return packAp(content); }