@@ -553,35 +553,46 @@ ctx.getFollowersUri("alice")
553
553
Liked
554
554
-----
555
555
556
- * This API is available since Fedify 0.11 .0.*
556
+ * This API is available since Fedify 0.15 .0.*
557
557
558
558
The liked collection is a collection of objects that an actor has liked.
559
559
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 .
561
561
562
562
Cursors and counters for the liked collection are implemented in the same way as
563
563
the outbox collection, so we don't repeat the explanation here.
564
564
565
565
The below example shows how to construct a liked collection:
566
566
567
567
~~~~ typescript
568
+ import type { Object } from " @fedify/fedify" ;
569
+
568
570
federation
569
571
.setLikedDispatcher (" /users/{handle}/liked" , async (ctx , handle , cursor ) => {
570
572
// Work with the database to find the objects that the actor has liked
571
573
// (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 );
581
575
return { items };
582
576
});
583
577
~~~~
584
578
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
+
585
596
### Constructing liked collection URIs
586
597
587
598
To construct a liked collection URI, you can use the ` Context.getLikedUri() `
0 commit comments