From 0de40f3a76ef159b099a90b65ded3073dbbd2b78 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 5 Apr 2018 23:24:51 +0900 Subject: [PATCH] wip --- src/api/following/create.ts | 16 +++------------- src/api/following/delete.ts | 9 ++------- src/api/post/create.ts | 9 ++------- src/queue/index.ts | 9 +++++++++ 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/api/following/create.ts b/src/api/following/create.ts index 353a6c8920..d919f4487f 100644 --- a/src/api/following/create.ts +++ b/src/api/following/create.ts @@ -7,7 +7,7 @@ import notify from '../../publishers/notify'; import context from '../../remote/activitypub/renderer/context'; import renderFollow from '../../remote/activitypub/renderer/follow'; import renderAccept from '../../remote/activitypub/renderer/accept'; -import { createHttp } from '../../queue'; +import { deliver } from '../../queue'; export default async function(follower: IUser, followee: IUser, activity?) { const following = await Following.insert({ @@ -60,23 +60,13 @@ export default async function(follower: IUser, followee: IUser, activity?) { const content = renderFollow(follower, followee); content['@context'] = context; - createHttp({ - type: 'deliver', - user: follower, - content, - to: followee.account.inbox - }).save(); + deliver(follower, content, followee.account.inbox).save(); } if (isRemoteUser(follower) && isLocalUser(followee)) { const content = renderAccept(activity); content['@context'] = context; - createHttp({ - type: 'deliver', - user: followee, - content, - to: follower.account.inbox - }).save(); + deliver(followee, content, follower.account.inbox).save(); } } diff --git a/src/api/following/delete.ts b/src/api/following/delete.ts index 4cdff7ce1b..364a4803b9 100644 --- a/src/api/following/delete.ts +++ b/src/api/following/delete.ts @@ -6,7 +6,7 @@ import event from '../../publishers/stream'; import context from '../../remote/activitypub/renderer/context'; import renderFollow from '../../remote/activitypub/renderer/follow'; import renderUndo from '../../remote/activitypub/renderer/undo'; -import { createHttp } from '../../queue'; +import { deliver } from '../../queue'; export default async function(follower: IUser, followee: IUser, activity?) { const following = await Following.findOne({ @@ -59,11 +59,6 @@ export default async function(follower: IUser, followee: IUser, activity?) { const content = renderUndo(renderFollow(follower, followee)); content['@context'] = context; - createHttp({ - type: 'deliver', - user: follower, - content, - to: followee.account.inbox - }).save(); + deliver(follower, content, followee.account.inbox).save(); } } diff --git a/src/api/post/create.ts b/src/api/post/create.ts index 7b7fceda2a..9723dbe452 100644 --- a/src/api/post/create.ts +++ b/src/api/post/create.ts @@ -2,7 +2,7 @@ import Post, { pack, IPost } from '../../models/post'; import User, { isLocalUser, IUser } from '../../models/user'; import stream from '../../publishers/stream'; import Following from '../../models/following'; -import { createHttp } from '../../queue'; +import { deliver } from '../../queue'; import renderNote from '../../remote/activitypub/renderer/note'; import renderCreate from '../../remote/activitypub/renderer/create'; import context from '../../remote/activitypub/renderer/context'; @@ -132,12 +132,7 @@ export default async (user: IUser, content: { } else { // フォロワーがリモートユーザーかつ投稿者がローカルユーザーなら投稿を配信 if (isLocalUser(user)) { - createHttp({ - type: 'deliver', - user, - content, - to: follower.account.inbox - }).save(); + deliver(user, content, follower.account.inbox).save(); } } })); diff --git a/src/queue/index.ts b/src/queue/index.ts index 86600dc265..689985e0ed 100644 --- a/src/queue/index.ts +++ b/src/queue/index.ts @@ -28,6 +28,15 @@ export function createDb(data) { return queue.create('db', data); } +export function deliver(user, content, to) { + return createHttp({ + type: 'deliver', + user, + content, + to + }); +} + export default function() { queue.process('db', db);