Skip to content

Commit 2706448

Browse files
committed
Change the element type of the liked collection
https://fosstodon.org/@hongminhee/113116797292204563
1 parent 1b12e7d commit 2706448

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

CHANGES.md

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ To be released.
3131
- `new Question()` constructor now accepts `quoteUrl` option.
3232
- `Question.clone()` method now accepts `quoteUrl` option.
3333

34+
- The element type of the liked collection is now `Object` or `URL` instead of
35+
`Like`.
36+
37+
- Changed the type of `Federation.setLikedDispatcher()` method's second
38+
parameter to `CollectionDispatcher<Object | URL,
39+
RequestContext<TContextData>, TContextData, void>` (was
40+
`CollectionDispatcher<Like, RequestContext<TContextData>, TContextData,
41+
void>`).
42+
3443
- Removed `expand` option of `Object.toJsonLd()` method, which was deprecated
3544
in version 0.14.0. Use `format: "expand"` option instead.
3645

docs/manual/collections.md

+22-11
Original file line numberDiff line numberDiff line change
@@ -553,35 +553,46 @@ ctx.getFollowersUri("alice")
553553
Liked
554554
-----
555555

556-
*This API is available since Fedify 0.11.0.*
556+
*This API is available since Fedify 0.15.0.*
557557

558558
The liked collection is a collection of objects that an actor has liked.
559559
The liked collection is similar to the outbox collection, but it's a collection
560-
of `Like` activities instead of any activities.
560+
of `Object`s instead of `Activity` objects.
561561

562562
Cursors and counters for the liked collection are implemented in the same way as
563563
the outbox collection, so we don't repeat the explanation here.
564564

565565
The below example shows how to construct a liked collection:
566566

567567
~~~~ typescript
568+
import type { Object } from "@fedify/fedify";
569+
568570
federation
569571
.setLikedDispatcher("/users/{handle}/liked", async (ctx, handle, cursor) => {
570572
// Work with the database to find the objects that the actor has liked
571573
// (the below `getLikedPostsByUserHandle` is a hypothetical function):
572-
const objects = await getLikedByUserHandle(handle);
573-
// Turn the ActivityStreams objects into `Like` activities:
574-
const items = objects.map(object =>
575-
new Like({
576-
id: new URL(`#post-${object.id}`, ctx.url),
577-
actor: ctx.getActorUri(handle),
578-
object: new URL(object.uri),
579-
})
580-
);
574+
const items: Object[] = await getLikedByUserHandle(handle);
581575
return { items };
582576
});
583577
~~~~
584578

579+
Or you can yield the object URIs instead of the objects:
580+
581+
~~~~ typescript
582+
import type { Object } from "@fedify/fedify";
583+
584+
federation
585+
.setLikedDispatcher("/users/{handle}/liked", async (ctx, handle, cursor) => {
586+
// Work with the database to find the objects that the actor has liked
587+
// (the below `getLikedPostsByUserHandle` is a hypothetical function):
588+
const objects: Object[] = await getLikedByUserHandle(handle);
589+
// Turn the objects into `URL` objects:
590+
const items: URL[] = objects.map(obj => obj.id).filter(id => id != null);
591+
return { items };
592+
});
593+
~~~~
594+
595+
585596
### Constructing liked collection URIs
586597

587598
To construct a liked collection URI, you can use the `Context.getLikedUri()`

src/federation/middleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ export interface Federation<TContextData> {
542542
setLikedDispatcher(
543543
path: `${string}{handle}${string}`,
544544
dispatcher: CollectionDispatcher<
545-
Like,
545+
Object | URL,
546546
RequestContext<TContextData>,
547547
TContextData,
548548
void

0 commit comments

Comments
 (0)