Skip to content

Commit

Permalink
feat: [PBE-1666] add query message histories (#1298)
Browse files Browse the repository at this point in the history
Co-authored-by: Lennart <[email protected]>
  • Loading branch information
shaljam and totalimmersion authored May 17, 2024
1 parent 5dfade6 commit c3c030c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ import {
ReactionSort,
QueryReactionsAPIResponse,
QueryReactionsOptions,
QueryMessageHistoryFilters,
QueryMessageHistorySort,
QueryMessageHistoryOptions,
QueryMessageHistoryResponse,
} from './types';
import { InsightMetrics, postInsights } from './insights';
import { Thread } from './thread';
Expand Down Expand Up @@ -3647,4 +3651,23 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
...options,
});
}

/**
* Queries message histories
* @param filter
* @param sort
* @param options Option object, {limit: 10}
* @returns {APIResponse & QueryMessageHistoryResponse} The message histories
*/
async queryMessageHistory(
filter: QueryMessageHistoryFilters = {},
sort: QueryMessageHistorySort = [],
options: QueryMessageHistoryOptions = {},
): Promise<APIResponse & QueryMessageHistoryResponse> {
return await this.post<APIResponse & QueryMessageHistoryResponse>(this.baseURL + '/messages/history', {
filter,
sort: normalizeQuerySort(sort),
...options,
});
}
}
41 changes: 41 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3089,3 +3089,44 @@ export type PollVotesAPIResponse<StreamChatGenerics extends ExtendableGenerics =
export type CastVoteAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
vote: PollVote<StreamChatGenerics>;
};

export type QueryMessageHistoryFilters = QueryFilters<
{
message_id?:
| RequireOnlyOne<Pick<QueryFilter<MessageHistoryEntry['message_id']>, '$eq' | '$in'>>
| PrimitiveFilter<MessageHistoryEntry['message_id']>;
} & {
user_id?:
| RequireOnlyOne<Pick<QueryFilter<MessageHistoryEntry['message_updated_by_id']>, '$eq' | '$in'>>
| PrimitiveFilter<MessageHistoryEntry['message_updated_by_id']>;
} & {
created_at?:
| RequireOnlyOne<
Pick<QueryFilter<MessageHistoryEntry['message_updated_at']>, '$eq' | '$gt' | '$lt' | '$gte' | '$lte'>
>
| PrimitiveFilter<MessageHistoryEntry['message_updated_at']>;
}
>;

export type QueryMessageHistorySort = QueryMessageHistorySortBase | Array<QueryMessageHistorySortBase>;

export type QueryMessageHistorySortBase = {
created_at?: AscDesc;
user_id?: AscDesc;
};

export type QueryMessageHistoryOptions = Pager;

export type MessageHistoryEntry<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
message_id: string;
message_updated_at: string;
attachments?: Attachment<StreamChatGenerics>[];
message_updated_by_id?: string;
text?: string;
};

export type QueryMessageHistoryResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
message_history: MessageHistoryEntry<StreamChatGenerics>[];
next?: string;
prev?: string;
};

0 comments on commit c3c030c

Please sign in to comment.