stream-chat
Advanced tools
Comparing version 8.50.0 to 8.51.0
@@ -41,2 +41,3 @@ export declare const EVENT_MAP: { | ||
'reaction.updated': boolean; | ||
'thread.updated': boolean; | ||
'typing.start': boolean; | ||
@@ -43,0 +44,0 @@ 'typing.stop': boolean; |
@@ -17,3 +17,4 @@ export * from './base64'; | ||
export * from './store'; | ||
export * from './thread'; | ||
export { Thread } from './thread'; | ||
export type { ThreadState, ThreadReadState, ThreadRepliesPagination, ThreadUserReadState } from './thread'; | ||
export * from './thread_manager'; | ||
@@ -20,0 +21,0 @@ export * from './token_manager'; |
import type { Channel } from './channel'; | ||
import type { StreamChat } from './client'; | ||
import { StateStore } from './store'; | ||
import type { AscDesc, DefaultGenerics, ExtendableGenerics, FormatMessageResponse, MessagePaginationOptions, MessageResponse, ThreadResponse, UserResponse } from './types'; | ||
import type { AscDesc, DefaultGenerics, ExtendableGenerics, FormatMessageResponse, MessagePaginationOptions, MessageResponse, ThreadResponse, ThreadResponseCustomData, UserResponse } from './types'; | ||
declare type QueryRepliesOptions<SCG extends ExtendableGenerics> = { | ||
@@ -21,2 +21,3 @@ sort?: { | ||
createdAt: Date; | ||
custom: ThreadResponseCustomData; | ||
deletedAt: Date | null; | ||
@@ -35,2 +36,3 @@ isLoading: boolean; | ||
replyCount: number; | ||
title: string; | ||
updatedAt: Date | null; | ||
@@ -51,2 +53,3 @@ }; | ||
export declare type ThreadReadState<SCG extends ExtendableGenerics = DefaultGenerics> = Record<string, ThreadUserReadState<SCG> | undefined>; | ||
export declare const THREAD_RESPONSE_RESERVED_KEYS: Record<keyof ThreadResponse, true>; | ||
export declare class Thread<SCG extends ExtendableGenerics = DefaultGenerics> { | ||
@@ -70,2 +73,3 @@ readonly state: StateStore<ThreadState<SCG>>; | ||
registerSubscriptions: () => void; | ||
private subscribeThreadUpdated; | ||
private subscribeMarkActiveThreadRead; | ||
@@ -72,0 +76,0 @@ private subscribeReloadActiveStaleThread; |
{ | ||
"name": "stream-chat", | ||
"version": "8.50.0", | ||
"version": "8.51.0", | ||
"description": "JS SDK for the Stream Chat API", | ||
@@ -5,0 +5,0 @@ "author": "GetStream", |
@@ -41,2 +41,3 @@ export const EVENT_MAP = { | ||
'reaction.updated': true, | ||
'thread.updated': true, | ||
'typing.start': true, | ||
@@ -43,0 +44,0 @@ 'typing.stop': true, |
@@ -17,3 +17,4 @@ export * from './base64'; | ||
export * from './store'; | ||
export * from './thread'; | ||
export { Thread } from './thread'; | ||
export type { ThreadState, ThreadReadState, ThreadRepliesPagination, ThreadUserReadState } from './thread'; | ||
export * from './thread_manager'; | ||
@@ -20,0 +21,0 @@ export * from './token_manager'; |
@@ -14,2 +14,3 @@ import type { Channel } from './channel'; | ||
ThreadResponse, | ||
ThreadResponseCustomData, | ||
UserResponse, | ||
@@ -31,2 +32,3 @@ } from './types'; | ||
createdAt: Date; | ||
custom: ThreadResponseCustomData; | ||
deletedAt: Date | null; | ||
@@ -45,2 +47,3 @@ isLoading: boolean; | ||
replyCount: number; | ||
title: string; | ||
updatedAt: Date | null; | ||
@@ -71,3 +74,40 @@ }; | ||
const MARK_AS_READ_THROTTLE_TIMEOUT = 1000; | ||
// TODO: remove this once we move to API v2 | ||
export const THREAD_RESPONSE_RESERVED_KEYS: Record<keyof ThreadResponse, true> = { | ||
channel: true, | ||
channel_cid: true, | ||
created_at: true, | ||
created_by_user_id: true, | ||
parent_message_id: true, | ||
title: true, | ||
updated_at: true, | ||
latest_replies: true, | ||
active_participant_count: true, | ||
deleted_at: true, | ||
last_message_at: true, | ||
participant_count: true, | ||
reply_count: true, | ||
read: true, | ||
thread_participants: true, | ||
created_by: true, | ||
parent_message: true, | ||
}; | ||
// TODO: remove this once we move to API v2 | ||
const constructCustomDataObject = <T extends ThreadResponse>(threadData: T) => { | ||
const custom: ThreadResponseCustomData = {}; | ||
for (const key in threadData) { | ||
if (THREAD_RESPONSE_RESERVED_KEYS[key as keyof ThreadResponse]) { | ||
continue; | ||
} | ||
const customKey = key as keyof ThreadResponseCustomData; | ||
custom[customKey] = threadData[customKey]; | ||
} | ||
return custom; | ||
}; | ||
export class Thread<SCG extends ExtendableGenerics = DefaultGenerics> { | ||
@@ -94,8 +134,11 @@ public readonly state: StateStore<ThreadState<SCG>>; | ||
this.state = new StateStore<ThreadState<SCG>>({ | ||
// local only | ||
active: false, | ||
isLoading: false, | ||
isStateStale: false, | ||
// 99.9% should never change | ||
channel, | ||
createdAt: new Date(threadData.created_at), | ||
// rest | ||
deletedAt: threadData.deleted_at ? new Date(threadData.deleted_at) : null, | ||
isLoading: false, | ||
isStateStale: false, | ||
pagination: repliesPaginationFromInitialThread(threadData), | ||
@@ -110,2 +153,4 @@ parentMessage: formatMessage(threadData.parent_message), | ||
updatedAt: threadData.updated_at ? new Date(threadData.updated_at) : null, | ||
title: threadData.title, | ||
custom: constructCustomDataObject(threadData), | ||
}); | ||
@@ -195,2 +240,3 @@ | ||
this.unsubscribeFunctions.add(this.subscribeThreadUpdated()); | ||
this.unsubscribeFunctions.add(this.subscribeMarkActiveThreadRead()); | ||
@@ -205,2 +251,20 @@ this.unsubscribeFunctions.add(this.subscribeReloadActiveStaleThread()); | ||
private subscribeThreadUpdated = () => { | ||
return this.client.on('thread.updated', (event) => { | ||
if (!event.thread || event.thread.parent_message_id !== this.id) { | ||
return; | ||
} | ||
const threadData = event.thread; | ||
this.state.partialNext({ | ||
title: threadData.title, | ||
updatedAt: new Date(threadData.updated_at), | ||
deletedAt: threadData.deleted_at ? new Date(threadData.deleted_at) : null, | ||
// TODO: use threadData.custom once we move to API v2 | ||
custom: constructCustomDataObject(threadData), | ||
}); | ||
}).unsubscribe; | ||
}; | ||
private subscribeMarkActiveThreadRead = () => { | ||
@@ -207,0 +271,0 @@ return this.state.subscribeWithSelector( |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
7526585
78387