Skip to main content
reference

ThreadClient

Helper wrapper around raw Wasm bindings. Manages all the necessary IDs exposing high level Threads API.

Constructors

constructor

constructor(threadId: string,platform: Endpoint,eventDispatcher: EventDispatcher)

NameTypeDescription
threadIdstring
platformEndpoint`Endpoint` instance
eventDispatcherEventDispatcher

Fields

threadId

get threadId(): string

Static Methods

createThread

Creates a new Thread in current Context.

static async createThread(threadApi: ThreadApi, newThread: {
contextId: string;
managers: UserWithPubKey[];
privateMeta: Uint8Array;
publicMeta: Uint8Array;
users: UserWithPubKey[];
})

NameTypeDescription
threadApiThreadApiThreadApi `ThreadApi` instance
newThread.contextIdstring
newThread.managersUserWithPubKey[]list of `UserWithPubKey` objects which indicates who will have access (and management rights) to the updated Thread
newThread.privateMetaUint8Arrayprivate metadata of the Thread
newThread.publicMetaUint8Arraypublic metadata of the Thread
newThread.usersUserWithPubKey[]list of `UserWithPubKey` objects which indicates who will have access to the updated Thread

TypeDescription
Promise<string> promise of newly created Thread ID

deleteMessage

Deletes message with matching `messageId`.

static async deleteMessage(threadApi: ThreadApi, messageId: string)

NameTypeDescription
threadApiThreadApiThreadApi `ThreadApi` instance
messageIdstringID of message to delete

TypeDescription
Promise<void> a promise that resolves with void

getMessage

Returns message with matching `messageId`.

static async getMessage(threadApi: ThreadApi, messageId: string)

NameTypeDescription
threadApiThreadApiThreadApi `ThreadApi` instance
messageIdstringID of the message to get

TypeDescription
Promise<Message> `Promise<Message>

getThreads

Returns a list of Threads in given Context.

static async getThreads(threadApi: ThreadApi, contextId: string, pageIndex: number, options: ListOptions)

NameTypeDescription
threadApiThreadApiThreadApi `ThreadApi` instance
contextIdstringID of the Context to get Threads from
pageIndexnumber
optionsListOptionsoptional `options` object

TypeDescription
Promise<PagingList<Thread>> - promise of

on

Registers an event listener for Thread-related events.

static on(eventDispatcher: EventDispatcher, eventType: T, callback: (payload: Extract<ThreadCreatedEvent, {type: T;}> | Extract<ThreadUpdatedEvent, {type: T;}> | Extract<ThreadDeletedEvent, {type: T;}> | Extract<ThreadStatsEvent, {type: T;}>)=>void)

NameTypeDescription
eventDispatcherEventDispatcher
eventTypeTtype of event to listen for
callback(payload: Extract<ThreadCreatedEvent, {type: T;}> | Extract<ThreadUpdatedEvent, {type: T;}> | Extract<ThreadDeletedEvent, {type: T;}> | Extract<ThreadStatsEvent, {type: T;}>)=>voidcallback function to execute when the event occurs

TypeDescription
SubscribeForChannel<"thread"> & { removeEventListener: ()=>void; } object containing the

subscribeToThreadEvents

Subscribes to events related to Threads: - `threadCreated` - `threadDeleted` - `threadStatsChanged` - `threadUpdated`

static async subscribeToThreadEvents(api: ThreadApi, eventDispatcher: EventDispatcher)

NameTypeDescription
apiThreadApiinstance of Thread API
eventDispatcherEventDispatchereventDispatcher

TypeDescription
Promise<SubscribeForChannel<"thread">> `SubscribeForChannel<'thread'>

unsubscribeFromThreadEvents

Unsubscribes from events related to the Thread.

static async unsubscribeFromThreadEvents(threadApi: ThreadApi, eventDispatcher: EventDispatcher)

NameTypeDescription
threadApiThreadApiinstance of Thread API
eventDispatcherEventDispatchereventDispatcher

TypeDescription
Promise<void> a promise that resolves with void

Methods

deleteThread

Deletes current Thread from Context.

async deleteThread()

TypeDescription
Promise<void> a promise that resolves with void

getMessages

Returns list of messages inside Thread.

async getMessages(pageIndex: number, options: ListOptions)

NameTypeDescription
pageIndexnumber
optionsListOptionsoptional options object

TypeDescription
Promise<PagingList<Message>> `PagingList<Message>

getThreadInfo

Fetches info about current Thread.

async getThreadInfo()

TypeDescription
Promise<Thread> `Thread`

on

Registers an event listener for Thread message-related events.

on(eventType: T, callback: (payload: Extract<ThreadNewMessageEvent, {type: T;}> | Extract<ThreadMessageDeletedEvent, {type: T;}> | Extract<ThreadMessageUpdatedEvent, {type: T;}>)=>void)

NameTypeDescription
eventTypeTtype of event to listen for
callback(payload: Extract<ThreadNewMessageEvent, {type: T;}> | Extract<ThreadMessageDeletedEvent, {type: T;}> | Extract<ThreadMessageUpdatedEvent, {type: T;}>)=>voidcallback function to execute when the event occurs

TypeDescription
SubscribeForChannel<"threadMessages"> & { removeEventListener: ()=>void; } object containing the

sendMessage

Sends a message to Thread.

async sendMessage(newMessage: ThreadMessagePayload)

NameTypeDescription
newMessageThreadMessagePayload`ThreadMessagePayload`

TypeDescription
Promise<string> promise of new messages's

subscribeToMessageEvents

Subscribes to message events in given Thread: - `threadNewMessage` - `threadMessageDeleted` - `threadMessageUpdated`

async subscribeToMessageEvents()

TypeDescription
Promise<SubscribeForChannel<"threadMessages">> <'threadMessages'> `Promise<SubscribeForChannel<'threadMessages'>>

unsubscribeFromMessageEvents

Unsubscribes from message-related events in the Thread.

async unsubscribeFromMessageEvents()

TypeDescription
Promise<void> a promise that resolves with void

updateThread

Updates Thread by overriding fields with new ones. While updating, the server will check version number. Updates of Thread with different version number will be rejected. Version number is incremented after every update.

async updateThread(updatedData: {
managers: UserWithPubKey[];
options: {
force: boolean;
forceGenerateNewKey: boolean;
};
privateMeta: Uint8Array;
publicMeta: Uint8Array;
users: UserWithPubKey[];
version: number;
})

NameTypeDescription
updatedData.managersUserWithPubKey[]list of users with permissions to modify the Thread
updatedData.options{ force: boolean; forceGenerateNewKey: boolean; }
updatedData.privateMetaUint8Array(encrypted) metadata
updatedData.publicMetaUint8Arraypublic (unencrypted) metadata
updatedData.usersUserWithPubKey[]list of users with access to the Thread
updatedData.versionnumber

TypeDescription
Promise<void>