newOS for Developers

Back to Mood Management

List Mood Posts

beginner

Paginated content listing with sorting options

GET /mood/postsGET /mood/attachments

Overview

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; // boolean

Parameters

ParameterTypeDefaultDescription
idstringRequiredFolder/mood ID
sortBystring"created"Sort field name
reversebooleantrueDescending order (newest first)
noTextNodesbooleanfalseFilter out text/plain posts
noPrivatebooleanfalseFilter out posts marked private
loadAllbooleantrueAuto-paginate all results
accessstring"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+post

Response

// 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 whenreadAll: true.