ThreadApi
Class representing instance of Threads API
Methods
createThread
Creates a new Thread in the given Context and returns the new Thread's ID. A random 256-bit thread key is generated client-side and encrypted separately for each listed user with ECIES using their public key - the server stores only the encrypted per-user key entries and cannot read the key. privateMeta is encrypted client-side with the thread key; publicMeta is stored unencrypted on the server. Entry point of the messaging workflow: follow with sendMessage and listMessages. Adjust members or metadata later with updateThread.
Params
contextId
string
ID of the Context to create the Thread in, from Context.contextId returned by Connection.listContexts
users
UserWithPubKey[]
members allowed to read and post in the Thread; build the entries from Connection.listContextUsers
managers
UserWithPubKey[]
members who can additionally update or delete the Thread; build the entries from Connection.listContextUsers
publicMeta
Uint8Array
metadata stored unencrypted on the server - readable by the Bridge, so never place secrets here
privateMeta
Uint8Array
metadata encrypted client-side with the thread key; only Thread members can decrypt it
policies
ContainerPolicy
fine-grained access rules (who may post, update or delete items) overriding the Context defaults
Returns
Promise<string> ·
ID of the new Thread - pass to sendMessage, listMessages, getThread or updateThread
updateThread
Replaces the member lists, metadata and (optionally) the encryption key of an existing Thread. The thread key list is re-encrypted for the new user set (ECIES on each user's public key). With forceGenerateNewKey a fresh thread key is generated, so removed users cannot decrypt messages sent after the update. The update is a full replacement, not a diff - fetch the current state with getThread, modify it, and pass the Thread's version back so concurrent modifications are detected. Set forceGenerateNewKey whenever you remove users.
Params
threadId
string
ID of the Thread to update, returned by createThread or from Thread.threadId in listThreads
users
UserWithPubKey[]
full replacement list of members allowed to read and post; users missing from this list lose access
managers
UserWithPubKey[]
full replacement list of members with management rights (update / delete the Thread)
publicMeta
Uint8Array
new metadata stored unencrypted on the server - never place secrets here
privateMeta
Uint8Array
new metadata encrypted client-side with the thread key
version
number
current Thread version, from Thread.version returned by getThread - lets the server reject stale updates
force
boolean
true skips the version check and overwrites any concurrent modification
forceGenerateNewKey
boolean
when true, a fresh thread key is generated by the WASM core and redistributed, so users removed by this update cannot decrypt messages sent afterwards - set it whenever you revoke access
policies
ContainerPolicy
new access policies; omit to keep the current ones
deleteThread
Permanently deletes a Thread together with all its messages. The server removes the Thread record, its encrypted per-user key entries and every stored message ciphertext - there is no undo. Requires management rights to the Thread (see the managers list of createThread / updateThread). To merely revoke access, keep the Thread and remove users with updateThread instead.
Params
threadId
string
ID of the Thread to delete, returned by createThread or from Thread.threadId in listThreads
getThread
Fetches a single Thread with its metadata, member lists and version. Downloads the Thread record from the Bridge and decrypts privateMeta client-side with the user's copy of the thread key; publicMeta arrives as stored, unencrypted. Use it to display Thread details or to obtain the current version required by updateThread.
Params
threadId
string
ID of the Thread to fetch, returned by createThread or from Thread.threadId in listThreads
Returns
Promise<Thread> ·
decrypted Thread data - version feeds updateThread; threadId feeds sendMessage and listMessages
listThreads
Lists the Threads of a Context that the user is a member of, one page at a time. Downloads the Thread records from the Bridge and decrypts each privateMeta client-side with the corresponding thread key. Typically the first ThreadApi call after connecting - pick a Thread from the result and read it with listMessages.
Params
contextId
string
ID of the Context to enumerate, from Context.contextId returned by Connection.listContexts
pagingQuery
PagingQuery
pagination and sorting; start with { skip: 0, limit: 100, sortOrder: "desc" } and page using skip or lastId
Returns
Promise<PagingList<Thread>> ·
one page of Threads plus totalAvailable; use Thread.threadId with sendMessage or listMessages
getMessage
Fetches and decrypts a single message. Downloads the message from the Bridge and decrypts data and privateMeta client-side with the thread key; per-field SHA-256 checksums and the author's ECDSA signature protect the content against tampering, and Message.authorPubKey identifies the signer. Use it to resolve a single message ID delivered by an event subscription (subscribeFor); for bulk reading prefer listMessages.
Params
messageId
string
ID of the message, returned by sendMessage or from Message.info.messageId in listMessages
Returns
Promise<Message> ·
decrypted message - payload in data, metadata and author info alongside
listMessages
Lists the messages of a Thread, one page at a time. Downloads the message records from the Bridge and decrypts each message's data and privateMeta client-side with the thread key; signatures and checksums are verified during decryption. The standard way to render a conversation - typically called right after picking a Thread from listThreads.
Params
threadId
string
ID of the Thread to read, returned by createThread or from Thread.threadId in listThreads
pagingQuery
PagingQuery
pagination and sorting; start with { skip: 0, limit: 100, sortOrder: "desc" } and page using skip or lastId
Returns
Promise<PagingList<Message>> ·
one page of decrypted messages plus totalAvailable; use Message.info.messageId with updateMessage or deleteMessage
sendMessage
Sends a new message to a Thread and returns the new message's ID. data and privateMeta are encrypted client-side with the thread key and signed with the sender's private key before upload - the server stores only ciphertext; publicMeta is stored unencrypted. Core call of the messaging workflow after createThread; other members receive the message via listMessages or a subscribeFor event subscription.
Params
threadId
string
ID of the destination Thread, returned by createThread or from Thread.threadId in listThreads
publicMeta
Uint8Array
message metadata stored unencrypted on the server - readable by the Bridge, so never place secrets here
privateMeta
Uint8Array
message metadata encrypted client-side with the thread key; only Thread members can decrypt it
data
Uint8Array
message payload, encrypted client-side with the thread key before upload
Returns
Promise<string> ·
ID of the new message - pass to getMessage, updateMessage or deleteMessage
deleteMessage
Permanently deletes a single message from its Thread. The server removes the message ciphertext and its metadata - there is no undo. Allowed for the message author or users granted the right by the Thread's policies (see createThread); to change content instead of removing it, use updateMessage.
Params
messageId
string
ID of the message to delete, returned by sendMessage or from Message.info.messageId in listMessages
updateMessage
Replaces the content and metadata of an existing message. The new data and privateMeta are encrypted client-side with the thread key and re-signed before upload, exactly as in sendMessage; the previous content is overwritten on the server. Use it for edit functionality - the message keeps its ID, so existing references from listMessages or events remain valid.
Params
messageId
string
ID of the message to update, returned by sendMessage or from Message.info.messageId in listMessages
publicMeta
Uint8Array
new message metadata stored unencrypted on the server - never place secrets here
privateMeta
Uint8Array
new message metadata encrypted client-side with the thread key
data
Uint8Array
new message payload, encrypted client-side with the thread key before upload
subscribeFor
Subscribes this connection to Thread events matching the given subscription queries. Registers the subscriptions on the Bridge over the connection's event channel; matching events are then pushed by the server and surface through EventQueue.waitEvent. Required order: buildSubscriptionQuery (one query per event-type/selector pair) → subscribeFor(queries) → consume events from the EventQueue → unsubscribeFrom when no longer needed.
Params
subscriptionQueries
string[]
query strings produced by buildSubscriptionQuery; hand-written strings are not supported
Returns
Promise<string[]> ·
subscription IDs, index-aligned with subscriptionQueries - keep them to unsubscribeFrom later
unsubscribeFrom
Cancels Thread event subscriptions previously created on this connection, so the server stops pushing the matching events. Subscriptions also end implicitly when the connection is closed; call this only to stop receiving a subset of events while keeping the connection alive.
Params
subscriptionIds
string[]
IDs returned by subscribeFor; unknown IDs cause a NativeError rejection
buildSubscriptionQuery
Builds a subscription-query string describing one class of Thread events (e.g. "all message events in Thread X"). The query is assembled locally by the WASM core in the server's expected format - nothing is sent yet; pass the result to subscribeFor to activate it.
Params
eventType
ThreadEventType
which Thread event class to listen for (Thread create/update/delete, message events, …)
selectorType
ThreadEventSelectorType
what selectorId refers to (e.g. a whole Context or a single Thread), narrowing the event scope
selectorId
string
ID of the selected scope - a Thread ID returned by createThread or a Context ID from Connection.listContexts, depending on selectorType
Returns
Promise<string> ·
query string consumed by subscribeFor
We use cookies on our website. We use them to ensure proper functioning of the site and, if you agree, for purposes such as analytics, marketing, and targeting ads.