From 30bd467b7143502b5aacc86de7e724ac4aa9c6c3 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 5 Apr 2018 23:19:47 +0900 Subject: [PATCH] wip --- src/api/post/create.ts | 40 +++++++++++++++------------- src/remote/activitypub/act/create.ts | 6 ++--- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/api/post/create.ts b/src/api/post/create.ts index dbeb87ae8..7b7fceda2 100644 --- a/src/api/post/create.ts +++ b/src/api/post/create.ts @@ -31,7 +31,7 @@ export default async (user: IUser, content: { visibility?: string; uri?: string; app?: IApp; -}) => new Promise(async (res, rej) => { +}, silent = false) => new Promise(async (res, rej) => { if (content.createdAt == null) content.createdAt = new Date(); if (content.visibility == null) content.visibility = 'public'; @@ -120,26 +120,28 @@ export default async (user: IUser, content: { _id: false }); - const note = await renderNote(user, post); - const content = renderCreate(note); - content['@context'] = context; + if (!silent) { + const note = await renderNote(user, post); + const content = renderCreate(note); + content['@context'] = context; - Promise.all(followers.map(({ follower }) => { - if (isLocalUser(follower)) { - // Publish event to followers stream - stream(follower._id, 'post', postObj); - } else { - // フォロワーがリモートユーザーかつ投稿者がローカルユーザーなら投稿を配信 - if (isLocalUser(user)) { - createHttp({ - type: 'deliver', - user, - content, - to: follower.account.inbox - }).save(); + Promise.all(followers.map(({ follower }) => { + if (isLocalUser(follower)) { + // Publish event to followers stream + stream(follower._id, 'post', postObj); + } else { + // フォロワーがリモートユーザーかつ投稿者がローカルユーザーなら投稿を配信 + if (isLocalUser(user)) { + createHttp({ + type: 'deliver', + user, + content, + to: follower.account.inbox + }).save(); + } } - } - })); + })); + } } // チャンネルへの投稿 diff --git a/src/remote/activitypub/act/create.ts b/src/remote/activitypub/act/create.ts index 9669348d5..fe58f58f8 100644 --- a/src/remote/activitypub/act/create.ts +++ b/src/remote/activitypub/act/create.ts @@ -58,7 +58,7 @@ async function createImage(resolver: Resolver, actor: IRemoteUser, image) { return await uploadFromUrl(image.url, actor); } -async function createNote(resolver: Resolver, actor: IRemoteUser, note) { +async function createNote(resolver: Resolver, actor: IRemoteUser, note, silent = false) { if ( ('attributedTo' in note && actor.account.uri !== note.attributedTo) || typeof note.id !== 'string' @@ -86,7 +86,7 @@ async function createNote(resolver: Resolver, actor: IRemoteUser, note) { const inReplyTo = await resolver.resolve(note.inReplyTo) as any; const actor = await resolvePerson(inReplyTo.attributedTo); if (isRemoteUser(actor)) { - reply = await createNote(resolver, actor, inReplyTo); + reply = await createNote(resolver, actor, inReplyTo, true); } } } @@ -102,5 +102,5 @@ async function createNote(resolver: Resolver, actor: IRemoteUser, note) { viaMobile: false, geo: undefined, uri: note.id - }); + }, silent); }