Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [PBE-1666] add query message histories #1298

Merged
merged 6 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
Loading