Skip to content

Commit

Permalink
Let Context.sendActivity() use auth doc loader
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Apr 9, 2024
1 parent b4f5d91 commit 4573e79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ To be released.
- `Context.sendActivity()` method now throws `TypeError` instead of silently
failing when the given `Activity` object lacks the actor property.

- `Context.sendActivity()` method now uses an authenticated document
loader under the hood.

- Added outbox error handler to `Federation`.

- Added `onOutboxError` option to `new Federation()` constructor.
Expand Down
18 changes: 13 additions & 5 deletions federation/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,20 @@ export class Federation<TContextData> {
async #listenQueue(message: OutboxMessage): Promise<void> {
let activity: Activity | null = null;
try {
const keyId = new URL(message.keyId);
const privateKey = await importJwk(message.privateKey, "private");
const documentLoader = this.#authenticatedDocumentLoaderFactory(
{ keyId, privateKey },
);
activity = await Activity.fromJsonLd(message.activity, {
documentLoader: this.#documentLoader,
documentLoader,
});
await sendActivity({
keyId: new URL(message.keyId),
privateKey: await importJwk(message.privateKey, "private"),
keyId,
privateKey,
activity,
inbox: new URL(message.inbox),
documentLoader: this.#documentLoader,
documentLoader,
});
} catch (e) {
try {
Expand Down Expand Up @@ -721,6 +726,9 @@ export class Federation<TContextData> {
preferSharedInbox,
});
if (immediate || this.#queue == null) {
const documentLoader = this.#authenticatedDocumentLoaderFactory(
{ keyId, privateKey },
);
const promises: Promise<void>[] = [];
for (const inbox of inboxes) {
promises.push(
Expand All @@ -729,7 +737,7 @@ export class Federation<TContextData> {
privateKey,
activity,
inbox,
documentLoader: this.#documentLoader,
documentLoader,
}),
);
}
Expand Down

0 comments on commit 4573e79

Please sign in to comment.