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)
Name | Type | Description |
---|---|---|
threadId | string | |
platform | Endpoint | `Endpoint` instance |
eventDispatcher | EventDispatcher |
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[];
})
Name | Type | Description |
---|---|---|
threadApi | ThreadApi | ThreadApi `ThreadApi` instance |
newThread.contextId | string | |
newThread.managers | UserWithPubKey[] | list of `UserWithPubKey` objects which indicates who will have access (and management rights) to the updated Thread |
newThread.privateMeta | Uint8Array | private metadata of the Thread |
newThread.publicMeta | Uint8Array | public metadata of the Thread |
newThread.users | UserWithPubKey[] | list of `UserWithPubKey` objects which indicates who will have access to the updated Thread |
Type | Description |
---|---|
Promise<string> | promise of newly created Thread ID |
deleteMessage
Deletes message with matching `messageId`.
static async deleteMessage(threadApi: ThreadApi, messageId: string)
Name | Type | Description |
---|---|---|
threadApi | ThreadApi | ThreadApi `ThreadApi` instance |
messageId | string | ID of message to delete |
Type | Description |
---|---|
Promise<void> | a promise that resolves with void |
getMessage
Returns message with matching `messageId`.
static async getMessage(threadApi: ThreadApi, messageId: string)
Name | Type | Description |
---|---|---|
threadApi | ThreadApi | ThreadApi `ThreadApi` instance |
messageId | string | ID of the message to get |
Type | Description |
---|---|
Promise<Message> | `Promise<Message> |
getThreads
Returns a list of Threads in given Context.
static async getThreads(threadApi: ThreadApi, contextId: string, pageIndex: number, options: ListOptions)
Name | Type | Description |
---|---|---|
threadApi | ThreadApi | ThreadApi `ThreadApi` instance |
contextId | string | ID of the Context to get Threads from |
pageIndex | number | |
options | ListOptions | optional `options` object |
Type | Description |
---|---|
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)
Name | Type | Description |
---|---|---|
eventDispatcher | EventDispatcher | |
eventType | T | type of event to listen for |
callback | (payload: Extract<ThreadCreatedEvent, {type: T;}> | Extract<ThreadUpdatedEvent, {type: T;}> | Extract<ThreadDeletedEvent, {type: T;}> | Extract<ThreadStatsEvent, {type: T;}>)=>void | callback function to execute when the event occurs |
Type | Description |
---|---|
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)
Name | Type | Description |
---|---|---|
api | ThreadApi | instance of Thread API |
eventDispatcher | EventDispatcher | eventDispatcher |
Type | Description |
---|---|
Promise<SubscribeForChannel<"thread">> | `SubscribeForChannel<'thread'> |
unsubscribeFromThreadEvents
Unsubscribes from events related to the Thread.
static async unsubscribeFromThreadEvents(threadApi: ThreadApi, eventDispatcher: EventDispatcher)
Name | Type | Description |
---|---|---|
threadApi | ThreadApi | instance of Thread API |
eventDispatcher | EventDispatcher | eventDispatcher |
Type | Description |
---|---|
Promise<void> | a promise that resolves with void |
Methods
deleteThread
Deletes current Thread from Context.
async deleteThread()
Type | Description |
---|---|
Promise<void> | a promise that resolves with void |
getMessages
Returns list of messages inside Thread.
async getMessages(pageIndex: number, options: ListOptions)
Name | Type | Description |
---|---|---|
pageIndex | number | |
options | ListOptions | optional options object |
Type | Description |
---|---|
Promise<PagingList<Message>> | `PagingList<Message> |
getThreadInfo
Fetches info about current Thread.
async getThreadInfo()
Type | Description |
---|---|
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)
Name | Type | Description |
---|---|---|
eventType | T | type of event to listen for |
callback | (payload: Extract<ThreadNewMessageEvent, {type: T;}> | Extract<ThreadMessageDeletedEvent, {type: T;}> | Extract<ThreadMessageUpdatedEvent, {type: T;}>)=>void | callback function to execute when the event occurs |
Type | Description |
---|---|
SubscribeForChannel<"threadMessages"> & {
removeEventListener: ()=>void;
} | object containing the |
sendMessage
Sends a message to Thread.
async sendMessage(newMessage: ThreadMessagePayload)
Name | Type | Description |
---|---|---|
newMessage | ThreadMessagePayload | `ThreadMessagePayload` |
Type | Description |
---|---|
Promise<string> | promise of new messages's |
subscribeToMessageEvents
Subscribes to message events in given Thread: - `threadNewMessage` - `threadMessageDeleted` - `threadMessageUpdated`
async subscribeToMessageEvents()
Type | Description |
---|---|
Promise<SubscribeForChannel<"threadMessages">> | <'threadMessages'> `Promise<SubscribeForChannel<'threadMessages'>> |
unsubscribeFromMessageEvents
Unsubscribes from message-related events in the Thread.
async unsubscribeFromMessageEvents()
Type | Description |
---|---|
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;
})
Name | Type | Description |
---|---|---|
updatedData.managers | UserWithPubKey[] | list of users with permissions to modify the Thread |
updatedData.options | {
force: boolean;
forceGenerateNewKey: boolean;
} | |
updatedData.privateMeta | Uint8Array | (encrypted) metadata |
updatedData.publicMeta | Uint8Array | public (unencrypted) metadata |
updatedData.users | UserWithPubKey[] | list of users with access to the Thread |
updatedData.version | number |
Type | Description |
---|---|
Promise<void> |