chatcn

Threads

Flat and nested threading for conversations. Use flat threads for simple reply chains and nested threads for Reddit-style indented discussions with voting.

5
Alice2:07 AM

Has anyone tried the new streaming API?

3
Bob2:09 AM

Yeah, it's great for real-time updates

1
Carol2:10 AM

Agreed, docs could be better though

2
Dan2:09 AM

I found a bug with token counting

Flat Thread

The ChatNestedThread component can render a flat thread by using a single nesting level. This is the simplest threading model, similar to Slack-style threads.

Alice2:12 AM

Should we migrate to the new API version?

You2:13 AM

I think so. The new endpoints are much cleaner.

Bob2:14 AM

Agreed. Let's plan the migration for next sprint.

Nested Thread

The ChatNestedThread component supports indented sub-threads, collapsible branches, and vote counts. Each reply level is indented further, and threads can be collapsed to focus on top-level discussion.

5
Alice2:07 AM

What's the best approach for caching?

3
You2:09 AM

Redis for hot data, CDN for static assets.

2
Bob2:10 AM

Don't forget to set TTLs!

1
Carol2:09 AM

We could also look into stale-while-revalidate.

ThreadedMessage Data Shape

The ThreadedMessage interface extends the base message fields with threading-specific properties:

2
Alice2:12 AM

Example root message (parentId: null, depth: 0)

1
Bob2:14 AM

First-level reply (depth: 1)

0
Carol2:15 AM

Nested reply (depth: 2)

FieldTypeDescription
parentIdstring | nullID of the parent message, null for root
childrenThreadedMessage[]Array of child replies
depthnumberNesting level (0 = root)
votesnumber?Optional net vote count for the message
userVote"up" | "down" | null?Current user's vote direction
isCollapsedboolean?Whether this thread branch is collapsed