Unverified Commit df5e9468 authored by Hong Minhee's avatar Hong Minhee
Browse files

Featured tags collection dispatcher

parent 526b3abc
Loading
Loading
Loading
Loading
+60 −1
Original line number Diff line number Diff line
@@ -25,6 +25,10 @@ To be released.
     -  Added `Context.getFeaturedUri()` method.
     -  Added `{ type: "featured"; handle: string }` case to `ParseUriResult`
        type.
     -  Added `Federation.setFeaturedTagsDispatcher()` method.
     -  Added `Context.getFeaturedTagsUri()` method.
     -  Added `{ type: "featuredTags"; handle: string }` case to
        `ParseUriResult` type.

 -  Frequently used JSON-LD contexts are now preloaded.  [[#74]]

@@ -49,15 +53,64 @@ To be released.
     -  `Collection.current`
     -  `Collection.first`
     -  `Collection.last`
     -  `Collection.items`
     -  `CollectionPage.partOf`
     -  `CollectionPage.next`
     -  `CollectionPage.prev`

 -  Added `featured` property to `Actor` types in Activity Vocabulary API.
    [[#78]]

     -  Added `Application.getFeatured()` method.
     -  Added `Application.featuredId` property.
     -  `new Application()` constructor now accepts `featured` option.
     -  `Application.clone()` method now accepts `featured` option.
     -  Added `Group.getFeatured()` method.
     -  Added `Group.featuredId` property.
     -  `new Group()` constructor now accepts `featured` option.
     -  `Group.clone()` method now accepts `featured` option.
     -  Added `Organization.getFeatured()` method.
     -  Added `Organization.featuredId` property.
     -  `new Organization()` constructor now accepts `featured` option.
     -  `Organization.clone()` method now accepts `featured` option.
     -  Added `Person.getFeatured()` method.
     -  Added `Person.featuredId` property.
     -  `new Person()` constructor now accepts `featured` option.
     -  `Person.clone()` method now accepts `featured` option.
     -  Added `Service.getFeatured()` method.
     -  Added `Service.featuredId` property.
     -  `new Service()` constructor now accepts `featured` option.
     -  `Service.clone()` method now accepts `featured` option.

 -  Added `featuredTags` property to `Actor` types in Activity Vocabulary API.
    [[#78]]

     -  Added `Application.getFeaturedTags()` method.
     -  Added `Application.featuredTagsId` property.
     -  `new Application()` constructor now accepts `featuredTags` option.
     -  `Application.clone()` method now accepts `featuredTags` option.
     -  Added `Group.getFeaturedTags()` method.
     -  Added `Group.featuredTagsId` property.
     -  `new Group()` constructor now accepts `featuredTags` option.
     -  `Group.clone()` method now accepts `featuredTags` option.
     -  Added `Organization.getFeaturedTags()` method.
     -  Added `Organization.featuredTagsId` property.
     -  `new Organization()` constructor now accepts `featuredTags` option.
     -  `Organization.clone()` method now accepts `featuredTags` option.
     -  Added `Person.getFeaturedTags()` method.
     -  Added `Person.featuredTagsId` property.
     -  `new Person()` constructor now accepts `featuredTags` option.
     -  `Person.clone()` method now accepts `featuredTags` option.
     -  Added `Service.getFeaturedTags()` method.
     -  Added `Service.featuredTagsId` property.
     -  `new Service()` constructor now accepts `featuredTags` option.
     -  `Service.clone()` method now accepts `featuredTags` option.

 -  Added `target` property to `Activity` class in Activity Vocabulary API.

     -  Added `Activity.getTarget()` method.
     -  Added `Activity.getTargets()` method.
     -  Added `Activity.targetId` property.
     -  Added `Activity.targetIds` property.
     -  `new Activity()` constructor now accepts `target` option.
     -  `new Activity()` constructor now accepts `targets` option.
     -  `Activity.clone()` method now accepts `target` option.
@@ -67,6 +120,8 @@ To be released.

     -  Added `Activity.getResult()` method.
     -  Added `Activity.getResults()` method.
     -  Added `Activity.resultId` property.
     -  Added `Activity.resultIds` property.
     -  `new Activity()` constructor now accepts `result` option.
     -  `new Activity()` constructor now accepts `results` option.
     -  `Activity.clone()` method now accepts `result` option.
@@ -76,6 +131,8 @@ To be released.

     -  Added `Activity.getOrigin()` method.
     -  Added `Activity.getOrigins()` method.
     -  Added `Activity.originId` property.
     -  Added `Activity.originIds` property.
     -  `new Activity()` constructor now accepts `origin` option.
     -  `new Activity()` constructor now accepts `origins` option.
     -  `Activity.clone()` method now accepts `origin` option.
@@ -85,6 +142,8 @@ To be released.

     -  Added `Activity.getInstrument()` method.
     -  Added `Activity.getInstruments()` method.
     -  Added `Activity.instrumentId` property.
     -  Added `Activity.instrumentIds` property.
     -  `new Activity()` constructor now accepts `instrument` option.
     -  `new Activity()` constructor now accepts `instruments` option.
     -  `Activity.clone()` method now accepts `instrument` option.
+2193 −220

File changed.

Preview size limit exceeded, changes collapsed.

+9 −1
Original line number Diff line number Diff line
@@ -173,8 +173,16 @@ export async function* generateDecoder(
  for (const property of type.properties) {
    const variable = await getFieldName(property.uri, "");
    yield await generateField(property, types, "const ");
    yield `
    for (const v of values[${JSON.stringify(property.uri)}] ?? []) {
    const arrayVariable = `${variable}__array`;
    yield `
    const ${arrayVariable} = values[${JSON.stringify(property.uri)}];
    for (
      const v of ${arrayVariable} == null
        ? []
        : ${arrayVariable}.length === 1 && "@list" in ${arrayVariable}[0]
        ? ${arrayVariable}[0]["@list"]
        : ${arrayVariable}
    ) {
      if (v == null) continue;
    `;
    if (!areAllScalarTypes(property.range, types)) {
+32 −0
Original line number Diff line number Diff line
@@ -528,3 +528,35 @@ federation
    return { items };
  });
~~~~


Featured tags
-------------

*This API is available since Fedify 0.11.0.*

The featured tags collection is a collection of tags that an actor has featured
on top of their profile.  The featured tags collection is similar to the
featured collection, but it's a collection of `Hashtag` objects instead of
any ActivityStreams objects.

Cursor and counter for the featured tags collection are implemented in the same
way as the outbox collection, so we don't repeat the explanation here.

The below example shows how to construct a featured tags collection:

~~~~ typescript
federation
  .setFeaturedTagsDispatcher("/users/{handle}/tags", async (ctx, handle, cursor) => {
    // Work with the database to find the tags that the actor has featured
    // (the below `getFeaturedTagsByUserHandle` is a hypothetical function):
    const hashtags = await getFeaturedTagsByUserHandle(handle);
    const items = hashtags.map(hashtag =>
      new Hashtag({
        href: new URL(`/tags/${encodeURIComponent(hashtag)}`, ctx.url),
        name: `#${hashtag}`,
      })
    );
    return { items };
  });
~~~~
+7 −0
Original line number Diff line number Diff line
@@ -38,8 +38,12 @@ callbacks that take a `Context` object as the first parameter:
 -  [Actor dispatcher](./actor.md)
 -  [Inbox listeners](./inbox.md)
 -  [Outbox collection dispatcher](./collections.md#outbox)
 -  [Inbox collection dispatcher](./collections.md#inbox)
 -  [Following collection dispatcher](./collections.md#following)
 -  [Followers collection dispatcher](./collections.md#followers)
 -  [Liked collection dispatcher](./collections.md#liked)
 -  [Featured collection dispatcher](./collections.md#featured)
 -  [Featured tags collection dispatcher](./collections.md#featured-tags)
 -  [NodeInfo dispatcher](./nodeinfo.md)

Those are not all; there are more callbacks that take a `Context` object.
@@ -70,6 +74,9 @@ shows the methods:
 -  `~Context.getOutboxUri()`
 -  `~Context.getFollowingUri()`
 -  `~Context.getFollowersUri()`
 -  `~Context.getLikedUri()`
 -  `~Context.getFeaturedUri()`
 -  `~Context.getFeaturedTagsUri()`

You could hard-code the URIs, but it is better to use those methods to build
the URIs because the URIs are subject to change in the future.
Loading