Follows API
Reference for VitNode Content Engine follows - the follow option, threadReply rootFollowers, the generated follow and followers routes, account follow preferences and the React exports.
Exact contracts for record follows: what to declare, which routes and React exports it generates, the request and response shapes, and who gets delivered what. For a walkthrough, see Follows.
follow on defineContentType()
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
follow | boolean | no | false | Lets signed-in members follow records of this type. Adds GET, PUT and DELETE /{id}/follow and GET /{id}/followers. |
follow: true needs publicApi; without it defineContentType() throws a ContentEngineError. The resolved definition carries follow: { enabled: true }, and the public module type includes the four routes only when it is true, so fetcher({ path: "/{id}/follow" }) does not compile for a type without follows.
threadReply additions
Two options on the existing threadReply preset:
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
recipients.rootFollowers | boolean | no | false | Notify active followers of the thread's root. |
messages.followed | string | with rootFollowers | - | API message key shown to a follower who is neither the replied-to author nor the root's author. Receives {actor} and {title}. |
buildContentNotifications() throws when rootFollowers is set and the root content type has no follow, when root is not the type thread.root points at, or when messages.followed is missing. Rule ids, target, title, grouping and every other option behave as before.
replies: {
id: "forum.comment_reply",
preset: "threadReply",
recipients: {
authorField: "author",
rootAuthorField: "author",
rootFollowers: true,
},
messages: {
label: "@vitnode/forum.notifications.comment_reply.label",
comment: "@vitnode/forum.notifications.comment_reply.comment",
reply: "@vitnode/forum.notifications.comment_reply.reply",
followed: "@vitnode/forum.notifications.comment_reply.followed",
},
target: ({ content }) => commentPermalink(content.slug),
email: true,
},A follower's notification is stored with relation: "followed" and, for every event of the rule, a followSince timestamp. Saved events without them keep working and reach direct recipients only.
Record routes
Mounted under the type's public module. For Forum topics the module is content/topics; for Blog articles it is content/blog.
| Method | Path | Success |
|---|---|---|
GET | /api/@vitnode/forum/content/topics/{id}/follow | 200 with the follow state |
PUT | /api/@vitnode/forum/content/topics/{id}/follow | 200 with the saved state |
DELETE | /api/@vitnode/forum/content/topics/{id}/follow | 204, no body |
GET | /api/@vitnode/forum/content/topics/{id}/followers | 200 with a followers page |
All four use the member session and answer with Cache-Control: private, no-store. {id} is the record id in the type's id strategy: a number for serial, a string for uuid and bigint. Slugs are not accepted.
PUT body
| Body | Effect |
|---|---|
{} | Follow with the account's default delivery. An active follow keeps its own. |
{ "delivery": { "inApp": false, "email": "weekly" } } | Save this delivery. A delivery-only change keeps when the follow started. |
{ "anonymous": true } | Hide the follow from the followers list. Combine it with delivery in one request. |
email is "none", "immediate", "daily" or "weekly". { "inApp": false, "email": "none" } keeps the follow with no follow notifications. Without anonymous, an active follow keeps its setting, and a new or restarted one is anonymous exactly when the member browses anonymously: their Browse anonymously privacy choice, after their roles allow or force it.
import { fetcher } from "@vitnode/core/tanstack/fetcher";
await fetcher({
plugin: "@vitnode/forum",
module: "content/topics",
method: "put",
path: "/{id}/follow",
args: {
params: { id: topic.id },
body: { delivery: { inApp: false, email: "weekly" } },
},
});Response
{
"following": true,
"delivery": { "inApp": false, "email": "weekly" },
"anonymous": false,
"followerCount": 128,
"availableDelivery": {
"inApp": true,
"emailModes": ["none", "immediate", "daily", "weekly"]
}
}A viewer who never followed or unfollowed gets "following": false and "delivery": null; anonymous is then what a new follow would use, so true for a member who browses anonymously. followerCount counts every active follow of the record, anonymous ones included. delivery is the saved choice. availableDelivery is what the site offers now: emailModes is ["none"] without an email adapter or when the AdminCP disables email for the rule's notification type; ContentFollowButton then shows no email rows. A saved mode outside it stays saved.
Followers list
GET /{id}/followers returns a record's active followers, newest first, 30 per page. Pass the previous page's nextCursor as ?cursor= for the next one.
{
"edges": [
{
"user": { "id": 4, "name": "Alex", "nameCode": "alex", "avatarColor": "2563eb" },
"followedAt": "2026-11-30T19:12:04.000Z",
"viewer": true,
"anonymous": true
}
],
"anonymousCount": 9,
"nextCursor": null
}The list holds public follows plus the viewer's own, which is marked viewer: true and keeps its anonymous flag. Other anonymous followers are left out and counted in anonymousCount. user is the public person shape that comments use.
Errors
| Status | When |
|---|---|
400 | Malformed id, or a body that fails validation. |
401 | Not signed in. |
404 | GET, PUT or GET /followers on a missing, unpublished, hidden or unreadable record. All look the same. |
DELETE never reads the record: it answers 204 for a missing record and after the member lost access, so members can always stop a follow.
State transitions
| Operation | No row | Active follow | Unfollowed |
|---|---|---|---|
PUT {} | Insert with account defaults | Keep saved delivery | Restart with defaults, new start time |
PUT { delivery } | Insert with delivery | Replace delivery | Restart with delivery, new start |
| Auto-follow on reply | Insert with defaults, if on; anonymous when browsing anonymously | Keep saved delivery | Keep the opt-out |
DELETE | Nothing to do | Set unfollowedAt | Keep the opt-out |
Each is one conflict-handled statement on the (userId, contentTypeId, itemId) key, so an auto-follow racing an explicit save never overwrites it.
Account follow preferences
| Method | Path | Body / response |
|---|---|---|
GET | /api/@vitnode/core/notifications/follow-preferences | 200 with the preferences |
PUT | /api/@vitnode/core/notifications/follow-preferences | Body { autoFollowOnReply, defaultDelivery }, 200 with the saved values |
{
"autoFollowOnReply": false,
"defaultDelivery": { "inApp": true, "email": "none" },
"followEmailEnabled": true
}The values above are the defaults for every account, including ones created before follows existed. followEmailEnabled is read-only here: PUT /notifications/preferences sets it with followEmailEnabled in the same request as the per-type email patch, which is what the Email switch on /settings/notifications sends. Guests get 401; a malformed body gets 400.
Auto-follow
With autoFollowOnReply on, a member's comment or nested reply follows the thread root when:
- it was written through the public write service (the generated
POST /route orcreateContentPublicWriteService), and - it was published, or opened an approval submission, and
- the root type has
followand the member can read the root.
The follow is written in the same transaction as the comment, so a rolled-back write leaves neither. Plain drafts, edits, AdminCP creates and service writes without a member do not follow.
Delivery
Followers are notified on the rule's first publication of a comment. A follow counts when it is active and started before that moment. The worker reads followers 1000 at a time by user id, publishes one event per page and stores the next page in the same transaction.
| Recipient reason | In-app | |
|---|---|---|
| Direct reply or root author | Notification preferences | Notification preferences |
| Active follow only | Saved follow inApp | Saved follow email |
| Both | On when either allows it | The direct mode, or the follow's when the direct one is none |
AdminCP type enablement, channel availability and the email adapter apply to both paths. When the AdminCP locks the type for members, its in-app setting can turn follow in-app off and its email mode caps the follow's: a follow never gets email more often than the locked mode. The account email mute turns follow email off. Waiting email is checked again before it is sent, so an unfollow, a re-follow after the comment, a changed mode or lost access drops it.
React exports
From @vitnode/core/tanstack/follow:
| Export | Description |
|---|---|
ContentFollowButton | Split control: a Follow/Following toggle (unfollow offers Undo), the follower count, which opens a virtualized followers list loaded on first open, and a panel with in-app notifications, the email modes (only when the site sends email) and Follow anonymously, saved on Save. Props: contentTypeId, id, read, save, unfollow, followers, className. |
useContentFollow | The query and mutation behind the button, for a custom control. |
contentFollowQueryOptions | Query options for one viewer's follow of one record. |
contentFollowQueryKey | ["content-follow", userId, contentTypeId, id]. |
contentFollowersQueryOptions | Infinite query options for one record's followers list, keyed under the viewer's follow. |
invalidateContentFollows | Refreshes every follow query. The shared comment hook calls it after a successful comment. |
readContentFollowResponse | Parses a follow response or throws ContentFollowRequestError. |
Follow state and the followers list belong to one viewer: never warm them in a shared public loader.
Events
| Event | Payload |
|---|---|
notifications.follow_saved | { userId, contentTypeId, itemId, delivery, auto } |
notifications.unfollowed | { userId, contentTypeId, itemId } |
notifications.follow_preferences_updated | { userId, autoFollowOnReply, defaultDelivery } |
Storage and cleanup
Follows live in core_content_follows, one row per member and record, with itemId stored as the canonical id text. Deleting a record removes its follows in the deleting transaction; deleting an account removes the member's follows by cascade.
Related
- Follows: turn follows on and check them with two members.
- Notifications API: every
threadReplyoption. - Built-in events: the follow events with the rest of core's.