Skip to content

Conversation

sij411
Copy link
Contributor

@sij411 sij411 commented Aug 10, 2025

Summary

Example for using custom collection dispatchers by printing posts and tagged posts

Related Issue

Changes

  • Added main.ts : prints mock-up posts and tagged posts

Benefits

It demonstrates users how to use custom collection dispatchers

Checklist

  • Did you add a changelog entry to the CHANGES.md?
  • Did you write some relevant docs about this change (if it's a new feature)?
  • Did you write a regression test to reproduce the bug (if it's a bug fix)?
  • Did you write some tests for this change (if it's a new feature)?
  • Did you run deno task test-all on your machine?

Additional Notes

Results look like this:

Custom collection data: {
  type: "Collection",
  id: "https://example.com/users/someone/tags/ActivityPub",
  "@context": [
    "https://www.w3.org/ns/activitystreams",
    "https://w3id.org/security/data-integrity/v1",
    {
      toot: "http://joinmastodon.org/ns#",
      misskey: "https://misskey-hub.net/ns#",
      fedibird: "http://fedibird.com/ns#",
      ChatMessage: "http://litepub.social/ns#ChatMessage",
      sensitive: "as:sensitive",
      votersCount: "toot:votersCount",
      Emoji: "toot:Emoji",
      Hashtag: "as:Hashtag",
      quoteUrl: "as:quoteUrl",
      _misskey_quote: "misskey:_misskey_quote",
      quoteUri: "fedibird:quoteUri",
      emojiReactions: { "@id": "fedibird:emojiReactions", "@type": "@id" }
    }
  ],
  totalItems: 2,
  items: [
    {
      "@context": [
        "https://www.w3.org/ns/activitystreams",
        "https://w3id.org/security/data-integrity/v1",
        {
          toot: "http://joinmastodon.org/ns#",
          misskey: "https://misskey-hub.net/ns#",
          fedibird: "http://fedibird.com/ns#",
          sensitive: "as:sensitive",
          Emoji: "toot:Emoji",
          Hashtag: "as:Hashtag",
          quoteUrl: "as:quoteUrl",
          _misskey_quote: "misskey:_misskey_quote",
          quoteUri: "fedibird:quoteUri",
          emojiReactions: [Object]
        }
      ],
      id: "https://example.com/posts/post-1",
      type: "Note",
      content: "ActivityPub is a decentralized social networking protocol...",
      tag: [
        "https://example.com/tags/ActivityPub",
        "https://example.com/tags/Decentralization"
      ]
    },
    {
      "@context": [
        "https://www.w3.org/ns/activitystreams",
        "https://w3id.org/security/data-integrity/v1",
        {
          toot: "http://joinmastodon.org/ns#",
          misskey: "https://misskey-hub.net/ns#",
          fedibird: "http://fedibird.com/ns#",
          sensitive: "as:sensitive",
          Emoji: "toot:Emoji",
          Hashtag: "as:Hashtag",
          quoteUrl: "as:quoteUrl",
          _misskey_quote: "misskey:_misskey_quote",
          quoteUri: "fedibird:quoteUri",
          emojiReactions: [Object]
        }
      ],
      id: "https://example.com/posts/post-3",
      type: "Note",
      content: "WebFinger is a protocol for discovering information...",
      tag: "https://example.com/tags/ActivityPub"
    }
  ]
}

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @sij411, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

I've created a new example to illustrate the functionality of custom collection dispatchers in Fedify. This example provides a practical demonstration of how to define custom logic for serving and counting ActivityPub collections, which is essential for building flexible and scalable federated applications. The changes include a new TypeScript file with mock data and dispatcher implementations, along with a corresponding README for guidance.

Highlights

  • New Custom Collections Example: I've introduced a new example that showcases how to implement and utilize custom collection dispatchers within the Fedify framework. This is crucial for developers who need fine-grained control over how ActivityPub collections are served and counted.
  • Demonstration of Dispatcher and Counter: The core of this example is the main.ts file, which defines mock data for 'posts' and demonstrates how to create and use CustomCollectionDispatcher and CustomCollectionCounter functions. It includes a basic pagination mechanism for the dispatcher and a simple counter.
  • Documentation for the Example: To make the example easy to understand and run, I've also added a README.md file in the examples/custom-collections directory. This README provides a brief explanation of custom collections and clear instructions on how to execute the example.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions bot added component/collections Collections related examples Example code related priority/medium Medium priority issues type/documentation Improvements or additions to documentation labels Aug 10, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds an example for using custom collection dispatchers in Fedify. The example code in main.ts is a good starting point, but has a few areas for improvement. I've added comments to make the mock functions more realistic by making them async, to improve the robustness of cursor handling in the dispatcher, and to make the 'tagged posts' example a proper demonstration of a custom collection dispatcher. These changes will make the example clearer, more correct, and more useful for developers.

Copy link
Contributor

github-actions bot commented Aug 10, 2025

The docs for this pull request have been published:

https://d770f3ed.fedify.pages.dev

Copy link
Contributor

@ThisIsMissEm ThisIsMissEm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should actually show using the dispatcher callbacks, so missing some federation.set... lines. The AI comments are also pretty good

Copy link
Contributor

@ThisIsMissEm ThisIsMissEm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor note about Note and Create, but otherwise looking good.

Copy link
Contributor

@ThisIsMissEm ThisIsMissEm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Note is good on second pass, but I noticed some other things.

Copy link
Contributor

The latest push to this pull request has been published to JSR and npm as a pre-release:

Package Version JSR npm
@fedify/fedify 1.9.0-pr.364.1367+7bbeb85a JSR npm
@fedify/cli 1.9.0-pr.364.1367+7bbeb85a JSR
@fedify/amqp 1.9.0-pr.364.1367+7bbeb85a JSR npm
@fedify/elysia 1.9.0-pr.364.1367+7bbeb85a npm
@fedify/express 1.9.0-pr.364.1367+7bbeb85a JSR npm
@fedify/h3 1.9.0-pr.364.1367+7bbeb85a JSR npm
@fedify/nestjs 1.9.0-pr.364.1367+7bbeb85a npm
@fedify/next 1.9.0-pr.364.1367+7bbeb85a npm
@fedify/postgres 1.9.0-pr.364.1367+7bbeb85a JSR npm
@fedify/redis 1.9.0-pr.364.1367+7bbeb85a JSR npm
@fedify/sqlite 1.9.0-pr.364.1367+7bbeb85a JSR npm
@fedify/testing 1.9.0-pr.364.1367+7bbeb85a JSR npm

@dahlia dahlia merged commit 33745bc into fedify-dev:main Aug 13, 2025
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/collections Collections related examples Example code related priority/medium Medium priority issues type/documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Examples for custom collection dispatchers
3 participants