@@ -44,6 +44,7 @@ async function sendFollow(
4444 { identifier: senderId },
4545 recipient,
4646 new Follow({
47+ id: new URL(`https://example.com/${senderId}/follows/${recipient.id}`),
4748 actor: ctx.getActorUri(senderId),
4849 object: recipient.id,
4950 }),
@@ -60,7 +61,7 @@ async function sendFollow(
6061Specifying a sender
6162-------------------
6263
63- The first argument of the ` ~ Context.sendActivity()` method is the sender
64+ The first argument of the ` Context.sendActivity() ` method is the sender
6465of the activity. It can be three types of values:
6566
6667### ` { identifier: string } `
@@ -130,6 +131,79 @@ However, you probably don't want to use this option directly; instead,
130131you should use above two options to specify the sender.
131132
132133
134+ Specifying an activity
135+ ----------------------
136+
137+ The third argument of the ` Context.sendActivity() ` method is the activity
138+ to send. It can be an instance of any subclass of the ` Activity ` class, such
139+ as ` Follow ` , ` Create ` , ` Like ` , and so on.
140+
141+ Every activity must have the ` actor ` property, which corresponds to the sender
142+ of the activity. [ You can get the actor's URI by calling
143+ the ` Context.getActorUri() ` method.] ( ./actor.md#constructing-actor-uris )
144+
145+ Every activity should have the ` id ` property, which is a unique IRI for the
146+ activity. If you don't specify the ` id ` property, Fedify automatically
147+ generates a unique IRI for the activity—but it is recommended to specify
148+ the ` id ` property explicitly.
149+
150+ > [ !TIP]
151+ > The activity's ` id ` does not have to be necessarily dereferenceable—it's
152+ > totally fine to use a URL with a fragment identifier, such as
153+ > ` https://example.com/123#follow ` .
154+
155+ The most of cases, an activity should have the ` to ` property, which corresponds
156+ to the recipient of the activity. If it's a public activity, you can set
157+ the ` to ` property to the ` PUBLIC_COLLECTION ` constant, which represents
158+ the public addressing. There's also the ` cc ` property, which corresponds to
159+ the secondary recipients of the activity. Those two properties can be multiple,
160+ and you can set them to ` Actor ` objects, ` Collection ` objects, or ` URL ` objects.
161+
162+ > [ !TIP]
163+ > If you want to mimic the behavior of Mastodon's post privacy settings,
164+ > here's a table that shows how to set the ` to ` and ` cc ` properties:
165+ >
166+ > | Privacy setting | ` to ` property | ` cc ` property |
167+ > | ------------------| -----------------------------| -----------------------------|
168+ > | Public | ` PUBLIC_COLLECTION ` | ` Context.getFollowersUri() ` |
169+ > | Quiet public[ ^ 1 ] | ` Context.getFollowersUri() ` | ` PUBLIC_COLLECTION ` |
170+ > | Followers-only | ` Context.getFollowersUri() ` | Mentioned actors |
171+ > | Direct message | Mentioned actors | |
172+
173+ To wrap up, the following is an example of sending a ` Create ` activity:
174+
175+ ~~~~ typescript twoslash
176+ import {
177+ type Context , Create , Note , type Actor , PUBLIC_COLLECTION ,
178+ } from " @fedify/fedify" ;
179+ const ctx = null as unknown as Context <void >;
180+ const senderId: string = " " ;
181+ const noteId: string = " " ;
182+ const content: string = " " ;
183+ const recipients: Actor [] = [];
184+ // ---cut-before---
185+ await ctx .sendActivity (
186+ { identifier: senderId },
187+ recipients ,
188+ new Create ({
189+ id: new URL (` #create ` , ctx .getObjectUri (Note , { id: noteId })),
190+ actor: ctx .getActorUri (senderId ),
191+ object: new Note ({
192+ id: ctx .getObjectUri (Note , { id: noteId }),
193+ attribution: ctx .getActorUri (senderId ),
194+ to: PUBLIC_COLLECTION ,
195+ cc: ctx .getFollowersUri (senderId ),
196+ content ,
197+ }),
198+ }),
199+ );
200+ ~~~~
201+
202+ [ ^ 1 ] : Previously known as <q >Unlisted</q > in Mastodon—renamed to <q >Quiet
203+ public</q > in Mastodon 4.3.0. It's a public post that doesn't appear
204+ in the public timeline and the hashtag pages.
205+
206+
133207Enqueuing an outgoing activity
134208------------------------------
135209
0 commit comments