feat(federation): Add queue to note delivery

This commit is contained in:
Jesse Wierzbinski 2024-11-25 11:29:48 +01:00
parent 3ef361f521
commit 8a920218ea
No known key found for this signature in database
4 changed files with 51 additions and 16 deletions

View file

@ -41,6 +41,7 @@ import {
parseTextMentions,
} from "~/classes/functions/status";
import { config } from "~/packages/config-manager";
import { DeliveryJobType, deliveryQueue } from "~/worker.ts";
import { Application } from "./application.ts";
import { Attachment } from "./attachment.ts";
import { BaseInterface } from "./base.ts";
@ -310,9 +311,16 @@ export class Note extends BaseInterface<typeof Notes, NoteTypeWithRelations> {
public async federateToUsers(): Promise<void> {
const users = await this.getUsersToFederateTo();
for (const user of users) {
await this.author.federateToUser(this.toVersia(), user);
}
await deliveryQueue.addBulk(
users.map((user) => ({
data: {
entity: this.toVersia(),
recipientId: user.id,
senderId: this.author.id,
},
name: DeliveryJobType.FederateEntity,
})),
);
}
/**

View file

@ -1015,9 +1015,9 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
},
);
} catch (e) {
getLogger(["federation", "outbox"])
getLogger(["federation", "delivery"])
.error`Federating ${chalk.gray(entity.type)} to ${user.getUri()} ${chalk.bold.red("failed")}`;
getLogger(["federation", "outbox"]).error`${e}`;
getLogger(["federation", "delivery"]).error`${e}`;
sentry?.captureException(e);
return { ok: false };