Skip to main content

Overview

useFetchManyChatMessages returns a function that fetches a single page of conversation messages and resolves to the raw response. It stores nothing — no Redux, no socket subscription — so you own the resulting state. This is the low-level fetcher shared by useLiveChatMessages (the live store-backed view) and useFetchManyChatMessagesWrapper (a batteries-included paginated list). Use it directly when you need full control; most apps will prefer the wrapper.
Because results never enter the live store, this is the right tool for filtered or read-only queries (e.g. only messages that have replies) that should not be polluted by live socket traffic. It is a point-in-time query — call it again to refresh.

Usage Example

import { useFetchManyChatMessages } from "@sublay/react-js";
import { useState, useEffect } from "react";

function MessagesWithReplies({ conversationId }: { conversationId: string }) {
  const fetchMessages = useFetchManyChatMessages();
  const [messages, setMessages] = useState([]);

  useEffect(() => {
    fetchMessages({ conversationId, filters: { hasReplies: true } }).then((res) =>
      setMessages(res.messages)
    );
  }, [conversationId]);

  return (
    <ul>
      {messages.map((m) => <li key={m.id}>{m.content}</li>)}
    </ul>
  );
}

Parameters

conversationId
string
required
The ID of the conversation to query.
parentId
string | null
Restrict to thread replies of this message.
before
string | null
Keyset cursor (ISO timestamp): messages created before this. Mutually exclusive with after.
after
string | null
Keyset cursor (ISO timestamp): messages created after this. Mutually exclusive with before.
limit
number
Page size (1–100). Defaults to 50.
sort
"asc" | "desc"
Sort by creation time.
includeFiles
boolean
When true, the server populates the files field on each message.
filters
MessageFilters
Optional filters. filters.hasReplies (boolean): when true, returns only messages that have thread replies (threadReplyCount > 0); when false, only messages with none. Filters by thread replies, not quotings.
Threads are one level deep, so hasReplies: true together with parentId always returns an empty list — the response’s notice field explains why.

Returns

A Promise resolving to:
messages
ChatMessage[]
Messages for the requested page. When spaceReputation is requested, each embedded sender carries an added spaceReputation number. See ChatMessage and Reputation.
hasMore
boolean
Whether more messages exist in the requested direction.
oldestCreatedAt
string | null
ISO timestamp of the oldest message in this page; null if empty.
newestCreatedAt
string | null
ISO timestamp of the newest message in this page; null if empty.
notice
string
Present only when a filter combination can’t return results — e.g. hasReplies: true together with parentId. Explains why the list is empty.