newOS for Developers
Back to Mood Management
List Mood Posts
beginnerPaginated content listing with sorting options
GET /mood/postsGET /mood/attachmentsOverview
The readPosts action retrieves posts attached to a mood with pagination, sorting, and filtering options. It uses a progressive handler pattern that first returns cached data, then syncs with the server.
Two API endpoints are used: attachmentsList for authenticated users and attachmentsPublicListfor public access.
Request
import { readPosts } from "newgraph-signals/actions/folder";
// Read posts from a folder with options
const progress = readPosts({
id: "folder-uuid",
sortBy: "created", // Sort field (default: "created")
reverse: true, // Descending order (default: true)
noTextNodes: false, // Filter out text-only posts
noPrivate: false, // Filter out private posts
loadAll: true, // Load all pages automatically
access: "auto" // "private" | "public" | "auto"
});
// Access results
progress.value; // EnrichedPost[]
progress.done; // boolean - all pages loaded
progress.page; // current page number
progress.loading; // booleanParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| id | string | Required | Folder/mood ID |
| sortBy | string | "created" | Sort field name |
| reverse | boolean | true | Descending order (newest first) |
| noTextNodes | boolean | false | Filter out text/plain posts |
| noPrivate | boolean | false | Filter out posts marked private |
| loadAll | boolean | true | Auto-paginate all results |
| access | string | "auto" | "private" | "public" | "auto" |
Advanced Sorting
// Built-in advanced sort options
const advancedSort = {
// Sort by author reputation, then by rating
"users": orderBy(posts, ["author.watts", "rating"], ["desc", "desc"]),
// Group by author, sort groups by total points
"points": groupBy(posts, "author.id")
.orderBy(group => sumProp(group, "points"))
}
// Usage
readPosts({ id: folderId, sortBy: "users" });
readPosts({ id: folderId, sortBy: "points" });Cache Query
import { folderPosts } from "newgraph-signals/actions/folder";
// Direct cache query for folder posts
const posts = await folderPosts(folderId, {
sortBy: "created",
reverse: true,
noTextNodes: true,
noPrivate: true
});
// This queries via edge pattern:
// folder+{folderId}+attachment+postResponse
// EnrichedPost array
[
{
"id": "post-uuid",
"content": "Post content text",
"contentType": "text/plain",
"contentUrl": "https://...",
"author": { "id": "...", "username": "..." },
"rating": 42,
"relativeRating": 0.75, // Calculated for /card posts
"created": "2024-01-15T10:30:00Z"
},
// ... more posts
]Edge Cases
Card Posts: Posts with content starting with
/cardget a relativeRating calculated based on min/max ratings in the folder.Auto Access: When
access: "auto", the function automatically chooses authenticated or public endpoint based on login state.Deleted Posts: Posts with
deleted: true are filtered out in the cache query.Page Size: Default page size is 50, or 1000 when
readAll: true.