Skip to content

Commit

Permalink
Add PUBLIC_COLLECTION constant for public addressing
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Apr 10, 2024
1 parent 13cd1a0 commit 674666c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Version 0.7.0

To be released.

- Added `PUBLIC_COLLECTION` constant for [public addressing].

[public addressing]: https://www.w3.org/TR/activitypub/#public-addressing


Version 0.6.0
-------------
Expand Down
13 changes: 8 additions & 5 deletions docs/manual/send.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ recipient's personal inbox. To deliver an activity to the shared inbox,
you can pass the `preferSharedInbox` option:

~~~~ typescript
import { Actor, Context, Create, Note } from "@fedify/fedify";
import { Actor, Context, Create, Note, PUBLIC_COLLECTION } from "@fedify/fedify";

async function sendNote(
ctx: Context<void>,
Expand All @@ -144,10 +144,10 @@ async function sendNote(
recipient,
new Create({
actor: ctx.getActorUri(senderHandle),
to: new URL("https://www.w3.org/ns/activitystreams#Public"),
to: PUBLIC_COLLECTION,
object: new Note({
attribution: ctx.getActorUri(senderHandle),
to: new URL("https://www.w3.org/ns/activitystreams#Public"),
to: PUBLIC_COLLECTION,
}),
}),
{ preferSharedInbox: true }, // [!code highlight]
Expand All @@ -156,9 +156,12 @@ async function sendNote(
~~~~

> [!TIP]
> <https://www.w3.org/ns/activitystreams#Public> is a special IRI that
> `PUBLIC_COLLECTION` constant contains a `URL` object of
> <https://www.w3.org/ns/activitystreams#Public>, a special IRI that
> represents the public audience. By setting the `to` property to this IRI,
> the activity is visible to everyone.
> the activity is visible to everyone. See also the [*Public Addressing*
> section](https://www.w3.org/TR/activitypub/#public-addressing) in the
> ActivityPub specification.
> [!NOTE]
> To deliver an activity to the shared inbox, the recipient server must support
Expand Down
11 changes: 11 additions & 0 deletions vocab/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* The special public collection for [public addressing]. *Do not mutate this
* object.*
*
* [public addressing]: https://www.w3.org/TR/activitypub/#public-addressing
*
* @since 0.7.0
*/
export const PUBLIC_COLLECTION = new URL(
"https://www.w3.org/ns/activitystreams#Public",
);
1 change: 1 addition & 0 deletions vocab/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
* @module
*/
export * from "./actor.ts";
export * from "./constants.ts";
export * from "./lookup.ts";
export * from "./vocab.ts";

0 comments on commit 674666c

Please sign in to comment.