From 63c93323ecdeaa4b6183d75dd3f13469e1ef3ebd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 24 Nov 2017 13:41:10 +0100 Subject: Correctly forward like/dislikes and undo --- .../activitypub-http-broadcast-handler.ts | 11 +++------ .../activitypub-http-job-scheduler.ts | 27 +++++++++++++++++----- .../activitypub-http-unicast-handler.ts | 10 +++----- 3 files changed, 27 insertions(+), 21 deletions(-) (limited to 'server/lib/jobs/activitypub-http-job-scheduler') diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts index 5b4c65b81..49d4bf5c6 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-broadcast-handler.ts @@ -1,21 +1,16 @@ import { logger } from '../../../helpers' -import { buildSignedActivity } from '../../../helpers/activitypub' import { doRequest } from '../../../helpers/requests' -import { database as db } from '../../../initializers' -import { ActivityPubHttpPayload, maybeRetryRequestLater } from './activitypub-http-job-scheduler' +import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' async function process (payload: ActivityPubHttpPayload, jobId: number) { logger.info('Processing ActivityPub broadcast in job %d.', jobId) - const accountSignature = await db.Account.load(payload.signatureAccountId) - if (!accountSignature) throw new Error('Unknown signature account id.') - - const signedBody = await buildSignedActivity(accountSignature, payload.body) + const body = await computeBody(payload) const options = { method: 'POST', uri: '', - json: signedBody + json: body } for (const uri of payload.uris) { diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts index ccf109935..f1fe774cc 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-job-scheduler.ts @@ -1,11 +1,13 @@ -import { JobScheduler, JobHandler } from '../job-scheduler' +import { JobCategory } from '../../../../shared' +import { buildSignedActivity } from '../../../helpers/activitypub' +import { logger } from '../../../helpers/logger' +import { ACTIVITY_PUB } from '../../../initializers/constants' +import { database as db } from '../../../initializers/database' +import { JobHandler, JobScheduler } from '../job-scheduler' import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-handler' -import * as activitypubHttpUnicastHandler from './activitypub-http-unicast-handler' import * as activitypubHttpFetcherHandler from './activitypub-http-fetcher-handler' -import { JobCategory } from '../../../../shared' -import { ACTIVITY_PUB } from '../../../initializers/constants' -import { logger } from '../../../helpers/logger' +import * as activitypubHttpUnicastHandler from './activitypub-http-unicast-handler' type ActivityPubHttpPayload = { uris: string[] @@ -40,8 +42,21 @@ function maybeRetryRequestLater (err: Error, payload: ActivityPubHttpPayload, ur } } +async function computeBody (payload: ActivityPubHttpPayload) { + let body = payload.body + + if (payload.signatureAccountId) { + const accountSignature = await db.Account.load(payload.signatureAccountId) + if (!accountSignature) throw new Error('Unknown signature account id.') + body = await buildSignedActivity(accountSignature, payload.body) + } + + return body +} + export { ActivityPubHttpPayload, activitypubHttpJobScheduler, - maybeRetryRequestLater + maybeRetryRequestLater, + computeBody } diff --git a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts index f7f3dabbd..4c95197c4 100644 --- a/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts +++ b/server/lib/jobs/activitypub-http-job-scheduler/activitypub-http-unicast-handler.ts @@ -1,21 +1,17 @@ import { logger } from '../../../helpers' import { doRequest } from '../../../helpers/requests' -import { ActivityPubHttpPayload, maybeRetryRequestLater } from './activitypub-http-job-scheduler' -import { database as db } from '../../../initializers/database' -import { buildSignedActivity } from '../../../helpers/activitypub' +import { ActivityPubHttpPayload, computeBody, maybeRetryRequestLater } from './activitypub-http-job-scheduler' async function process (payload: ActivityPubHttpPayload, jobId: number) { logger.info('Processing ActivityPub unicast in job %d.', jobId) - const accountSignature = await db.Account.load(payload.signatureAccountId) - if (!accountSignature) throw new Error('Unknown signature account id.') + const body = await computeBody(payload) - const signedBody = await buildSignedActivity(accountSignature, payload.body) const uri = payload.uris[0] const options = { method: 'POST', uri, - json: signedBody + json: body } try { -- cgit v1.2.3