Loading CHANGES.md +5 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,11 @@ To be released. - `Context.sendActivity()` method - `Federation.sendActivity()` method - Added `immediate` option to `Context.sendActivity()` and `Federation.sendActivity()` methods. - Added `SendActivityOptions` interface. Version 0.2.0 ------------- Loading federation/context.ts +19 −1 Original line number Diff line number Diff line Loading @@ -95,7 +95,7 @@ export interface Context<TContextData> { sender: { keyId: URL; privateKey: CryptoKey } | { handle: string }, recipients: Actor | Actor[], activity: Activity, options?: { preferSharedInbox?: boolean }, options?: SendActivityOptions, ): Promise<void>; } Loading @@ -113,3 +113,21 @@ export interface RequestContext<TContextData> extends Context<TContextData> { */ readonly url: URL; } /** * Options for {@link Context.sendActivity} method and * {@link Federation.sendActivity} method. */ export interface SendActivityOptions { /** * Whether to prefer the shared inbox for the recipients. */ preferSharedInbox?: boolean; /** * Whether to send the activity immediately, without enqueuing it. * If `true`, the activity will be sent immediately and the retrial * policy will not be applied. */ immediate?: boolean; } federation/middleware.ts +19 −3 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ import { InboxListener, NodeInfoDispatcher, } from "./callback.ts"; import { Context, RequestContext } from "./context.ts"; import { Context, RequestContext, SendActivityOptions } from "./context.ts"; import { CollectionCallbacks, handleActor, Loading Loading @@ -282,7 +282,7 @@ export class Federation<TContextData> { sender: { keyId: URL; privateKey: CryptoKey } | { handle: string }, recipients: Actor | Actor[], activity: Activity, options: { preferSharedInbox?: boolean } = {}, options: SendActivityOptions = {}, ): Promise<void> => { let senderPair: { keyId: URL; privateKey: CryptoKey }; if ("handle" in sender) { Loading Loading @@ -630,7 +630,7 @@ export class Federation<TContextData> { { keyId, privateKey }: { keyId: URL; privateKey: CryptoKey }, recipients: Actor | Actor[], activity: Activity, { preferSharedInbox }: { preferSharedInbox?: boolean } = {}, { preferSharedInbox, immediate }: SendActivityOptions = {}, ): Promise<void> { if (activity.id == null) { activity = activity.clone({ Loading @@ -642,6 +642,22 @@ export class Federation<TContextData> { recipients: Array.isArray(recipients) ? recipients : [recipients], preferSharedInbox, }); if (immediate) { const promises: Promise<void>[] = []; for (const inbox of inboxes) { promises.push( sendActivity({ keyId, privateKey, activity, inbox, documentLoader: this.#documentLoader, }), ); } await Promise.all(promises); return; } for (const inbox of inboxes) { const message: OutboxMessage = { type: "outbox", Loading Loading
CHANGES.md +5 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,11 @@ To be released. - `Context.sendActivity()` method - `Federation.sendActivity()` method - Added `immediate` option to `Context.sendActivity()` and `Federation.sendActivity()` methods. - Added `SendActivityOptions` interface. Version 0.2.0 ------------- Loading
federation/context.ts +19 −1 Original line number Diff line number Diff line Loading @@ -95,7 +95,7 @@ export interface Context<TContextData> { sender: { keyId: URL; privateKey: CryptoKey } | { handle: string }, recipients: Actor | Actor[], activity: Activity, options?: { preferSharedInbox?: boolean }, options?: SendActivityOptions, ): Promise<void>; } Loading @@ -113,3 +113,21 @@ export interface RequestContext<TContextData> extends Context<TContextData> { */ readonly url: URL; } /** * Options for {@link Context.sendActivity} method and * {@link Federation.sendActivity} method. */ export interface SendActivityOptions { /** * Whether to prefer the shared inbox for the recipients. */ preferSharedInbox?: boolean; /** * Whether to send the activity immediately, without enqueuing it. * If `true`, the activity will be sent immediately and the retrial * policy will not be applied. */ immediate?: boolean; }
federation/middleware.ts +19 −3 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ import { InboxListener, NodeInfoDispatcher, } from "./callback.ts"; import { Context, RequestContext } from "./context.ts"; import { Context, RequestContext, SendActivityOptions } from "./context.ts"; import { CollectionCallbacks, handleActor, Loading Loading @@ -282,7 +282,7 @@ export class Federation<TContextData> { sender: { keyId: URL; privateKey: CryptoKey } | { handle: string }, recipients: Actor | Actor[], activity: Activity, options: { preferSharedInbox?: boolean } = {}, options: SendActivityOptions = {}, ): Promise<void> => { let senderPair: { keyId: URL; privateKey: CryptoKey }; if ("handle" in sender) { Loading Loading @@ -630,7 +630,7 @@ export class Federation<TContextData> { { keyId, privateKey }: { keyId: URL; privateKey: CryptoKey }, recipients: Actor | Actor[], activity: Activity, { preferSharedInbox }: { preferSharedInbox?: boolean } = {}, { preferSharedInbox, immediate }: SendActivityOptions = {}, ): Promise<void> { if (activity.id == null) { activity = activity.clone({ Loading @@ -642,6 +642,22 @@ export class Federation<TContextData> { recipients: Array.isArray(recipients) ? recipients : [recipients], preferSharedInbox, }); if (immediate) { const promises: Promise<void>[] = []; for (const inbox of inboxes) { promises.push( sendActivity({ keyId, privateKey, activity, inbox, documentLoader: this.#documentLoader, }), ); } await Promise.all(promises); return; } for (const inbox of inboxes) { const message: OutboxMessage = { type: "outbox", Loading