From 9460eac57e53bb92375728a650d5dd8c059fa3d6 Mon Sep 17 00:00:00 2001 From: Ali Momen Sani Date: Mon, 13 May 2024 09:45:20 +0200 Subject: [PATCH 1/5] feat: add query message histories --- src/client.ts | 23 +++++++++++++++++++++++ src/types.ts | 45 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/client.ts b/src/client.ts index e663068c5..ccab9f909 100644 --- a/src/client.ts +++ b/src/client.ts @@ -197,6 +197,10 @@ import { ReactionSort, QueryReactionsAPIResponse, QueryReactionsOptions, + QueryMessageHistoriesFilters, + QueryMessageHistoriesSort, + QueryMessageHistoriesOptions, + QueryMessageHistoriesResponse, } from './types'; import { InsightMetrics, postInsights } from './insights'; import { Thread } from './thread'; @@ -3647,4 +3651,23 @@ export class StreamChat { + return await this.post(this.baseURL + '/message-histories', { + filter, + sort: normalizeQuerySort(sort), + ...options, + }); + } } diff --git a/src/types.ts b/src/types.ts index bd124c54d..4e02cf64d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1667,9 +1667,9 @@ export type UserFilters['name']>; notifications_muted?: | RequireOnlyOne<{ - $eq?: PrimitiveFilter['notifications_muted']>; - }> - | boolean; + $eq?: PrimitiveFilter['notifications_muted']>; + }> + | boolean; teams?: | RequireOnlyOne<{ $contains?: PrimitiveFilter; @@ -3093,3 +3093,42 @@ export type PollVotesAPIResponse = { vote: PollVote; }; + +export type QueryMessageHistoriesFilters = QueryFilters< + { + message_id?: + | RequireOnlyOne, '$eq' | '$in'>> + | PrimitiveFilter; + } & { + user_id?: + | RequireOnlyOne, '$eq' | '$in'>> + | PrimitiveFilter; + } & { + created_at?: + | RequireOnlyOne, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'>> + | PrimitiveFilter; + } +>; + +export type QueryMessageHistoriesSort = QueryMessageHistoriesSortBase | Array; + +export type QueryMessageHistoriesSortBase = { + created_at?: AscDesc; + user_id?: AscDesc; +}; + +export type QueryMessageHistoriesOptions = Pager; + +export type MessageHistory = { + created_at: string; + message_id: string; + attachments?: Attachment[]; + text?: string; + user_id?: string; +}; + +export type QueryMessageHistoriesResponse = { + message_histories: MessageHistory[]; + next?: string; + prev?: string; +}; From 699c3fbaf8001465dbb1de5aea7fb21b3d28dc12 Mon Sep 17 00:00:00 2001 From: Ali Momen Sani Date: Mon, 13 May 2024 14:13:34 +0200 Subject: [PATCH 2/5] MessageHistories -> MessageHistory --- src/client.ts | 24 ++++++++++++------------ src/types.ts | 10 +++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/client.ts b/src/client.ts index ccab9f909..2db7a466f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -197,10 +197,10 @@ import { ReactionSort, QueryReactionsAPIResponse, QueryReactionsOptions, - QueryMessageHistoriesFilters, - QueryMessageHistoriesSort, - QueryMessageHistoriesOptions, - QueryMessageHistoriesResponse, + QueryMessageHistoryFilters, + QueryMessageHistorySort, + QueryMessageHistoryOptions, + QueryMessageHistoryResponse, } from './types'; import { InsightMetrics, postInsights } from './insights'; import { Thread } from './thread'; @@ -3657,14 +3657,14 @@ export class StreamChat { - return await this.post(this.baseURL + '/message-histories', { + * @returns {APIResponse & QueryMessageHistoryResponse} The message histories + */ + async queryMessageHistory( + filter: QueryMessageHistoryFilters = {}, + sort: QueryMessageHistorySort = [], + options: QueryMessageHistoryOptions = {}, + ): Promise { + return await this.post(this.baseURL + '/message-histories', { filter, sort: normalizeQuerySort(sort), ...options, diff --git a/src/types.ts b/src/types.ts index 4e02cf64d..163140b74 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3094,7 +3094,7 @@ export type CastVoteAPIResponse; }; -export type QueryMessageHistoriesFilters = QueryFilters< +export type QueryMessageHistoryFilters = QueryFilters< { message_id?: | RequireOnlyOne, '$eq' | '$in'>> @@ -3110,14 +3110,14 @@ export type QueryMessageHistoriesFilters = QueryFilters< } >; -export type QueryMessageHistoriesSort = QueryMessageHistoriesSortBase | Array; +export type QueryMessageHistorySort = QueryMessageHistorySortBase | Array; -export type QueryMessageHistoriesSortBase = { +export type QueryMessageHistorySortBase = { created_at?: AscDesc; user_id?: AscDesc; }; -export type QueryMessageHistoriesOptions = Pager; +export type QueryMessageHistoryOptions = Pager; export type MessageHistory = { created_at: string; @@ -3127,7 +3127,7 @@ export type MessageHistory = { +export type QueryMessageHistoryResponse = { message_histories: MessageHistory[]; next?: string; prev?: string; From bd04401ec22b07d94ec6592165add067f5b0e524 Mon Sep 17 00:00:00 2001 From: Ali Momen Sani Date: Mon, 13 May 2024 15:11:59 +0200 Subject: [PATCH 3/5] change url --- src/client.ts | 2 +- src/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.ts b/src/client.ts index 2db7a466f..73232b7e7 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3664,7 +3664,7 @@ export class StreamChat { - return await this.post(this.baseURL + '/message-histories', { + return await this.post(this.baseURL + '/messages/history', { filter, sort: normalizeQuerySort(sort), ...options, diff --git a/src/types.ts b/src/types.ts index 163140b74..ba7a403e3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3128,7 +3128,7 @@ export type MessageHistory = { - message_histories: MessageHistory[]; + message_history: MessageHistory[]; next?: string; prev?: string; }; From 1a493ee6b3e18d3344038ca90777badf9d2d1beb Mon Sep 17 00:00:00 2001 From: Ali Momen Sani Date: Tue, 14 May 2024 12:13:11 +0200 Subject: [PATCH 4/5] use MessageHistoryEntry instead of MessageHistory to represent one entry in the history --- src/types.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/types.ts b/src/types.ts index ba7a403e3..3e01666a8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3097,16 +3097,16 @@ export type CastVoteAPIResponse, '$eq' | '$in'>> - | PrimitiveFilter; + | RequireOnlyOne, '$eq' | '$in'>> + | PrimitiveFilter; } & { user_id?: - | RequireOnlyOne, '$eq' | '$in'>> - | PrimitiveFilter; + | RequireOnlyOne, '$eq' | '$in'>> + | PrimitiveFilter; } & { created_at?: - | RequireOnlyOne, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'>> - | PrimitiveFilter; + | RequireOnlyOne, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'>> + | PrimitiveFilter; } >; @@ -3119,7 +3119,7 @@ export type QueryMessageHistorySortBase = { export type QueryMessageHistoryOptions = Pager; -export type MessageHistory = { +export type MessageHistoryEntry = { created_at: string; message_id: string; attachments?: Attachment[]; @@ -3128,7 +3128,7 @@ export type MessageHistory = { - message_history: MessageHistory[]; + message_history: MessageHistoryEntry[]; next?: string; prev?: string; }; From 2bd0a233d2c3b048d3d4934959173fe0434d2c72 Mon Sep 17 00:00:00 2001 From: Ali Momen Sani Date: Tue, 14 May 2024 14:47:01 +0200 Subject: [PATCH 5/5] rename fields on message history user_id -> message_updated_by_id created_at -> message_updated_at --- src/types.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/types.ts b/src/types.ts index 3e01666a8..fa039e219 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3101,12 +3101,14 @@ export type QueryMessageHistoryFilters = QueryFilters< | PrimitiveFilter; } & { user_id?: - | RequireOnlyOne, '$eq' | '$in'>> - | PrimitiveFilter; + | RequireOnlyOne, '$eq' | '$in'>> + | PrimitiveFilter; } & { created_at?: - | RequireOnlyOne, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'>> - | PrimitiveFilter; + | RequireOnlyOne< + Pick, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'> + > + | PrimitiveFilter; } >; @@ -3120,11 +3122,11 @@ export type QueryMessageHistorySortBase = { export type QueryMessageHistoryOptions = Pager; export type MessageHistoryEntry = { - created_at: string; message_id: string; + message_updated_at: string; attachments?: Attachment[]; + message_updated_by_id?: string; text?: string; - user_id?: string; }; export type QueryMessageHistoryResponse = {