Unverified Commit 4573e798 authored by Hong Minhee's avatar Hong Minhee
Browse files

Let Context.sendActivity() use auth doc loader

parent b4f5d910
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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.
+13 −5
Original line number Diff line number Diff line
@@ -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 {
@@ -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(
@@ -729,7 +737,7 @@ export class Federation<TContextData> {
            privateKey,
            activity,
            inbox,
            documentLoader: this.#documentLoader,
            documentLoader,
          }),
        );
      }