refactor deliver to extract actor from activity

This commit is contained in:
Johann150 2023-04-18 21:56:09 +02:00
parent a786fd99fc
commit ff4b6d932e
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
2 changed files with 10 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import { Webhook, webhookEventTypes } from '@/models/entities/webhook.js';
import { IActivity } from '@/remote/activitypub/type.js';
import { envOption } from '@/env.js';
import { MINUTE } from '@/const.js';
import { DbResolver } from '@/remote/activitypub/db-resolver.js';
import processDeliver from './processors/deliver.js';
import processInbox from './processors/inbox.js';
@ -83,10 +84,17 @@ webhookDeliverQueue
.on('error', (job: any, err: Error) => webhookLogger.error(`error ${err}`, { job, e: renderError(err) }))
.on('stalled', (job) => webhookLogger.warn(`stalled ${getJobInfo(job)} to=${job.data.to}`));
export function deliver(user: ThinUser, content: unknown, to: string | null) {
export async function deliver(_user: ThinUser, content: unknown, to: string | null) {
if (content == null) return null;
if (to == null) return null;
// extract user from the Activity
const userUri = content.actor;
if (!userUri) throw new Error("Cannot deliver activity without actor.");
const user = await new DbResolver().getUserFromApId(userUri);
if (!user) throw new Error("Actor not found, cannot deliver.");
if (user.host != null) throw new Error("Cannot deliver for remote actor.");
const data = {
user: {
id: user.id,

View file

@ -9,7 +9,7 @@ export type DeliverJobData = {
/** Actor */
user: ThinUser;
/** Activity */
content: unknown;
content: IActivity;
/** inbox URL to deliver */
to: string;
};