Unverified Commit 8a7a6a54 authored by Hong Minhee's avatar Hong Minhee
Browse files

Excluding same-server recipients

parent f9e91100
Loading
Loading
Loading
Loading
+20 −7
Original line number Diff line number Diff line
@@ -4,14 +4,27 @@
  },
  "ensure_final_newline_on_save": true,
  "format_on_save": "on",
  "formatter": {
    "external": {
      "command": "deno",
      "arguments": [
        "fmt",
        "-"
  "formatter": "language_server",
  "languages": {
    "TypeScript": {
      "language_servers": [
        "deno",
        "!typescript-language-server",
        "!eslint",
        "..."
      ]
    },
    "TSX": {
      "language_servers": [
        "deno",
        "!typescript-language-server",
        "!eslint",
        "..."
      ]
    }
  },
  "preferred_line_length": 80
  "show_wrap_guides": true,
  "wrap_guides": [
    80
  ]
}
+6 −0
Original line number Diff line number Diff line
@@ -23,6 +23,12 @@ To be released.
        ``Promise<`@${string}@${string}` | `${string}@${string}`>``
        (was ``Promise<`@${string}@${string}`>``).

 -  Added `excludeBaseUris` option to `Context.sendActivity()` and
    `Federation.sendActivity()` methods.

     -  Added `SendActivityOptions.excludeBaseUris` property.
     -  Added `ExtractInboxesParameters.excludeBaseUris` property.

 -  Added more log messages using the [LogTape] library.  Currently the below
    logger categories are used:

+28 −0
Original line number Diff line number Diff line
@@ -231,6 +231,34 @@ the digest of the followers collection in the payload.
[FEP-8fcf]: https://codeberg.org/fediverse/fep/src/branch/main/fep/8fcf/fep-8fcf.md


Excluding same-server recipients
--------------------------------

*This API is available since Fedify 0.9.0.*

In most cases, you will not want to deliver activities via ActivityPub to
recipients on the same server with the sender.  To exclude same-server
recipients, you can pass the `excludeBaseUris` option to the
`~Context.sendActivity()` method:

~~~~ typescript
await ctx.sendActivity(
  { handle: senderHandle },
  "followers",
  activity,
  { excludeBaseUris: [ctx.getInboxUri()] },  // [!code highlight]
);
~~~~

Excluded recipients do not receive the activity, even if they are included in
the recipients parameter.

> [!NOTE]
> Only the `origin` parts of the specified URIs are compared with the
> inbox URLs of the recipients.  Even if they have `pathname` or `query` parts,
> they are ignored when comparing the URIs.


Error handling
--------------

+12 −0
Original line number Diff line number Diff line
@@ -260,6 +260,18 @@ export interface SendActivityOptions {
   * 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.
   *
   * @since 0.3.0
   */
  immediate?: boolean;

  /**
   * The base URIs to exclude from the recipients' inboxes.  It is useful
   * for excluding the recipients having the same shared inbox with the sender.
   *
   * Note that the only `origin` parts of the `URL`s are compared.
   *
   * @since 0.9.0
   */
  excludeBaseUris?: URL[];
}
+2 −1
Original line number Diff line number Diff line
@@ -1193,7 +1193,7 @@ export class Federation<TContextData> {
    { keyId, privateKey }: { keyId: URL; privateKey: CryptoKey },
    recipients: Recipient | Recipient[],
    activity: Activity,
    { preferSharedInbox, immediate, collectionSync }:
    { preferSharedInbox, immediate, excludeBaseUris, collectionSync }:
      SendActivityInternalOptions = {},
  ): Promise<void> {
    const logger = getLogger(["fedify", "federation", "outbox"]);
@@ -1216,6 +1216,7 @@ export class Federation<TContextData> {
    const inboxes = extractInboxes({
      recipients: Array.isArray(recipients) ? recipients : [recipients],
      preferSharedInbox,
      excludeBaseUris,
    });
    logger.debug("Sending activity {activityId} to inboxes:\n{inboxes}", {
      inboxes: globalThis.Object.keys(inboxes),
Loading