diff --git a/src/channel.ts b/src/channel.ts index 0a023e8ec..560571c2a 100644 --- a/src/channel.ts +++ b/src/channel.ts @@ -31,7 +31,6 @@ import type { CreateDraftResponse, DeleteMessageOptions, Event, - EventAPIResponse, EventHandler, EventPayload, EventType, @@ -39,6 +38,7 @@ import type { GetRepliesRequest, LocalMessage, MarkReadRequest, + MarkReadResponseEvent, MarkUnreadRequest, MessagePaginationOptions, MessageRequest, @@ -133,7 +133,7 @@ export type CustomDeleteMessageRequestFn = ( export type CustomMarkReadRequestFn = (params: { channel: Channel; options?: MarkReadRequest; -}) => Promise; +}) => Promise<{ event: MarkReadResponseEvent } | null>; export type ChannelInstanceConfig = { requestHandlers?: { diff --git a/src/messageDelivery/MessageDeliveryReporter.ts b/src/messageDelivery/MessageDeliveryReporter.ts index ce8a759f0..48ce22ed9 100644 --- a/src/messageDelivery/MessageDeliveryReporter.ts +++ b/src/messageDelivery/MessageDeliveryReporter.ts @@ -3,16 +3,15 @@ import { Channel } from '../channel'; import type { ThreadUserReadState } from '../thread'; import { Thread } from '../thread'; import type { - EventAPIResponse, LocalMessage, MarkDeliveredRequest, MarkReadRequest, + MarkReadResponse, StreamAPIError, StreamResponse, } from '../types'; import { throttle, userHasReadReceipts } from '../utils'; import { isAPIError, isErrorRetryable } from '../errors'; -import type { MarkReadResponse as Gen_MarkReadResponse } from '../gen/models'; const MAX_DELIVERED_MESSAGE_COUNT_IN_PAYLOAD = 100 as const; const MARK_AS_DELIVERED_BUFFER_TIMEOUT = 1000 as const; @@ -306,16 +305,11 @@ export class MessageDeliveryReporter { ? { ...options, thread_id: collection.id } : options; - let result: EventAPIResponse | StreamResponse | null = null; + let result: Partial> | null = null; if (isThreadCollection) { - const markReadRequestHandler = collection.configState.getLatestValue() - .requestHandlers?.markReadRequest as - | ((params: { - thread: Thread; - options?: MarkReadRequest; - }) => Promise | void) - | undefined; + const markReadRequestHandler = + collection.configState.getLatestValue().requestHandlers?.markReadRequest; result = markReadRequestHandler ? ((await markReadRequestHandler({ options: requestOptions, @@ -323,13 +317,8 @@ export class MessageDeliveryReporter { })) ?? null) : await channel.markRead(requestOptions); } else { - const markReadRequestHandler = channel.configState.getLatestValue().requestHandlers - ?.markReadRequest as - | ((params: { - channel: Channel; - options?: MarkReadRequest; - }) => Promise | void) - | undefined; + const markReadRequestHandler = + channel.configState.getLatestValue().requestHandlers?.markReadRequest; result = markReadRequestHandler ? ((await markReadRequestHandler({ channel, options: requestOptions })) ?? null) : await channel.markRead(requestOptions); diff --git a/src/pagination/paginators/ReminderPaginator.ts b/src/pagination/paginators/ReminderPaginator.ts index dd6fe21b7..73ec8ba5e 100644 --- a/src/pagination/paginators/ReminderPaginator.ts +++ b/src/pagination/paginators/ReminderPaginator.ts @@ -5,7 +5,7 @@ import type { PaginatorOptions, } from './BasePaginator'; import type { - QueryRemindersOptions, + QueryRemindersRequest, ReminderFilters, ReminderResponseData, ReminderSort, @@ -25,7 +25,7 @@ const DEFAULT_SORT: ReminderSort = [{ direction: 1, field: 'created_at' }]; export class ReminderPaginator extends BasePaginator< ReminderResponseData, - QueryRemindersOptions + QueryRemindersRequest > { private client: StreamChat; protected _filters: ReminderFilters | undefined; @@ -52,7 +52,7 @@ export class ReminderPaginator extends BasePaginator< constructor( client: StreamChat, - options?: PaginatorOptions, + options?: PaginatorOptions, ) { super({ initialCursor: ZERO_PAGE_CURSOR, @@ -83,8 +83,8 @@ export class ReminderPaginator extends BasePaginator< protected getNextQueryShape({ direction, }: Required< - Pick, 'direction'> - >): QueryRemindersOptions { + Pick, 'direction'> + >): QueryRemindersRequest { const cursor = this.cursor?.[direction]; return { filter: this.filters, @@ -96,7 +96,7 @@ export class ReminderPaginator extends BasePaginator< query = async ({ queryShape, - }: PaginationQueryParams): Promise< + }: PaginationQueryParams): Promise< PaginationQueryReturnValue > => { const { reminders: items, next, prev } = await this.client.queryReminders(queryShape); diff --git a/src/thread.ts b/src/thread.ts index 6039a5bfb..3e533f137 100644 --- a/src/thread.ts +++ b/src/thread.ts @@ -7,10 +7,10 @@ import { import { applyReactionLocally } from './entityStore'; import type { DraftResponse, - EventAPIResponse, EventType, LocalMessage, MarkReadRequest, + MarkReadResponseEvent, MessageResponse, ReactionRequest, ReadStateResponse, @@ -75,7 +75,7 @@ const DEFAULT_ITEM_ORDER: SortParamRequest[] = [{ field: 'created_at', direction export type CustomThreadMarkReadRequestFn = (params: { thread: Thread; options?: MarkReadRequest; -}) => Promise | void; +}) => Promise<{ event: MarkReadResponseEvent } | null> | void; export type ThreadInstanceConfig = { requestHandlers?: { @@ -139,7 +139,7 @@ export class Thread extends WithSubscriptions { participants: threadData.thread_participants, read: formatReadState( !threadData.read || threadData.read.length === 0 - ? getPlaceholderReadResponse(client.userID) + ? getPlaceholderReadResponse(client.userId) : threadData.read, ), // Use the parent message's reply_count, not the top-level threadData.reply_count. The @@ -180,7 +180,7 @@ export class Thread extends WithSubscriptions { isStateStale: false, parentMessage: formattedParentMessage, participants: [], - read: formatReadState(getPlaceholderReadResponse(client.userID)), + read: formatReadState(getPlaceholderReadResponse(client.userId)), replyCount: parentMessage.reply_count ?? 0, title: '', updatedAt: parentMessage.updated_at ? new Date(parentMessage.updated_at) : null, @@ -305,7 +305,7 @@ export class Thread extends WithSubscriptions { } get ownUnreadCount() { - return ownUnreadCountSelector(this.client.userID)(this.state.getLatestValue()); + return ownUnreadCountSelector(this.client.userId)(this.state.getLatestValue()); } public activate = () => { @@ -429,7 +429,7 @@ export class Thread extends WithSubscriptions { this.state.subscribeWithSelector( (nextValue) => ({ active: nextValue.active, - unreadMessageCount: ownUnreadCountSelector(this.client.userID)(nextValue), + unreadMessageCount: ownUnreadCountSelector(this.client.userId)(nextValue), }), ({ active, unreadMessageCount }) => { if (!active || !unreadMessageCount) return; @@ -452,8 +452,8 @@ export class Thread extends WithSubscriptions { const { channel } = this.state.getLatestValue(); if ( - !this.client.userID || - this.client.userID !== event.user?.id || + !this.client.userId || + this.client.userId !== event.user?.id || event.channel?.cid !== channel.cid ) { return; @@ -491,11 +491,11 @@ export class Thread extends WithSubscriptions { private subscribeNewReplies = () => this.client.on('message.new', (event) => { - if (!this.client.userID || event.message?.parent_id !== this.id) { + if (!this.client.userId || event.message?.parent_id !== this.id) { return; } - const isOwnMessage = event.message.user?.id === this.client.userID; + const isOwnMessage = event.message.user?.id === this.client.userId; const { active, read } = this.state.getLatestValue(); this.upsertReplyLocally({ @@ -526,7 +526,7 @@ export class Thread extends WithSubscriptions { user: event.user, unreadMessageCount: 0, }; - } else if (active && userId === this.client.userID) { + } else if (active && userId === this.client.userId) { // Do not increment unread count for the current user in an active thread } else { // Increment unread count for all users except the author of the new message diff --git a/src/types.ts b/src/types.ts index e679cc767..ddfdf07bf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1107,35 +1107,3 @@ export type GiphyVersions = keyof Images; export type TranslationLanguage = TranslateMessageRequest['language']; export * from './gen/models'; - -export type EventAPIResponse = APIResponse & { - event: Event; -}; - -export type PartializeKeys = Partial> & Omit; - -type ErrorResponseDetails = { - code: number; - messages: string[]; -}; - -export type APIErrorResponse = { - duration: string; - message: string; - more_info: string; - StatusCode: number; - code?: number; - details?: ErrorResponseDetails; -}; - -export type DraftMessagePayload = PartializeKeys< - Omit, - 'id' -> & { - user_id?: string; -}; - -export type QueryRemindersOptions = Pager & { - filter?: ReminderFilters; - sort?: ReminderSort; -}; diff --git a/src/utils.ts b/src/utils.ts index 48ef780c4..e750e3e5d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -802,7 +802,7 @@ export const generateChannelTempCid = (channelType: string, members: string[]) = export const isDate = (value: unknown): value is Date => !!(value as Date).getTime; export const isLocalMessage = (message: unknown): message is LocalMessage => - isDate((message as LocalMessage).created_at); + typeof (message as LocalMessage | undefined)?.status === 'string'; export const runDetached = ( callback: Promise,