diff --git a/src/client.ts b/src/client.ts index e663068c5..73232b7e7 100644 --- a/src/client.ts +++ b/src/client.ts @@ -197,6 +197,10 @@ import { ReactionSort, QueryReactionsAPIResponse, QueryReactionsOptions, + QueryMessageHistoryFilters, + QueryMessageHistorySort, + QueryMessageHistoryOptions, + QueryMessageHistoryResponse, } from './types'; import { InsightMetrics, postInsights } from './insights'; import { Thread } from './thread'; @@ -3647,4 +3651,23 @@ export class StreamChat { + return await this.post(this.baseURL + '/messages/history', { + filter, + sort: normalizeQuerySort(sort), + ...options, + }); + } } diff --git a/src/types.ts b/src/types.ts index d3f35c6c2..4bfe05860 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3089,3 +3089,44 @@ export type PollVotesAPIResponse = { vote: PollVote; }; + +export type QueryMessageHistoryFilters = QueryFilters< + { + message_id?: + | RequireOnlyOne, '$eq' | '$in'>> + | PrimitiveFilter; + } & { + user_id?: + | RequireOnlyOne, '$eq' | '$in'>> + | PrimitiveFilter; + } & { + created_at?: + | RequireOnlyOne< + Pick, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'> + > + | PrimitiveFilter; + } +>; + +export type QueryMessageHistorySort = QueryMessageHistorySortBase | Array; + +export type QueryMessageHistorySortBase = { + created_at?: AscDesc; + user_id?: AscDesc; +}; + +export type QueryMessageHistoryOptions = Pager; + +export type MessageHistoryEntry = { + message_id: string; + message_updated_at: string; + attachments?: Attachment[]; + message_updated_by_id?: string; + text?: string; +}; + +export type QueryMessageHistoryResponse = { + message_history: MessageHistoryEntry[]; + next?: string; + prev?: string; +};