-
Notifications
You must be signed in to change notification settings - Fork 76
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
[CHAT-1814] Updates to message search #677
Changes from 14 commits
8207d3e
4e984ff
ec4e53f
118f916
fc84437
e8626a3
b70378f
0418a37
f101145
134fe15
a2fa704
ee05ba7
60e91e9
986edfd
d09614e
2b221cb
12277bc
a14d3a1
8960261
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,9 +81,9 @@ import { | |
PermissionAPIResponse, | ||
PermissionsAPIResponse, | ||
ReactionResponse, | ||
SearchAPIResponse, | ||
SearchOptions, | ||
SearchPayload, | ||
SearchAPIResponse, | ||
SendFileAPIResponse, | ||
StreamChatOptions, | ||
TestPushDataInput, | ||
|
@@ -1779,7 +1779,7 @@ export class StreamChat< | |
>, | ||
options: SearchOptions = {}, | ||
) { | ||
// Return a list of channels | ||
const { sort: sort_value, ...options_without_sort } = { ...options }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as in channel but also we can probably avoid the rest spread as well, and pop everything to one line via
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not quite sure what you want to do here. Which lines will be replaced with your suggestion? |
||
const payload: SearchPayload< | ||
AttachmentType, | ||
ChannelType, | ||
|
@@ -1789,7 +1789,7 @@ export class StreamChat< | |
UserType | ||
> = { | ||
filter_conditions: filterConditions, | ||
...options, | ||
...options_without_sort, | ||
}; | ||
if (typeof query === 'string') { | ||
payload.query = query; | ||
|
@@ -1798,6 +1798,9 @@ export class StreamChat< | |
} else { | ||
throw Error(`Invalid type ${typeof query} for query parameter`); | ||
} | ||
if (sort_value) { | ||
payload.sort = normalizeQuerySort(sort_value); | ||
} | ||
|
||
// Make sure we wait for the connect promise if there is a pending one | ||
await this.setUserPromise; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -649,8 +649,17 @@ export type SearchAPIResponse< | |||||||||||||||||||||||||||||||||||||||||||||||||
UserType | ||||||||||||||||||||||||||||||||||||||||||||||||||
>; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
next?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||
previous?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||
results_warning?: SearchWarning; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export type SearchWarning = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
channel_search_cids: string[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
channel_search_count: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||
warning_code: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||
warning_description: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
export type SendFileAPIResponse = APIResponse & { file: string }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export type SendMessageAPIResponse< | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -935,11 +944,19 @@ export type QueryMembersOptions = { | |||||||||||||||||||||||||||||||||||||||||||||||||
user_id_lte?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export type SearchOptions = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
export type SearchOptions = LimitOffsetSearchOptions | NextSearchOptions; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export type LimitOffsetSearchOptions = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
miagilepner marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
limit?: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||
offset?: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export type NextSearchOptions = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
limit?: number; | ||||||||||||||||||||||||||||||||||||||||||||||||||
next?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||
sort?: SearchMessageSort; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defining before using ... makes it a little easier to read!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, do we really need separate
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought it was better to keep them separate - A user should not be allowed to use offset with next or with sort. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah my bad. I thought |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export type StreamChatOptions = AxiosRequestConfig & { | ||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||
* Used to disable warnings that are triggered by using connectUser or connectAnonymousUser server-side. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1407,10 +1424,20 @@ export type UserSort<UserType = UnknownType> = | |||||||||||||||||||||||||||||||||||||||||||||||||
| Sort<UserResponse<UserType>> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Array<Sort<UserResponse<UserType>>>; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export type SearchRelevanceSort = { relevance?: AscDesc }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export type SearchMessageSortBase = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| SearchRelevanceSort | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Sort<Message> | ||||||||||||||||||||||||||||||||||||||||||||||||||
miagilepner marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| { [field: string]: AscDesc }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
miagilepner marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export type SearchMessageSort = SearchMessageSortBase | Array<SearchMessageSortBase>; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export type QuerySort<ChannelType = UnknownType, UserType = UnknownType> = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| BannedUsersSort | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ChannelSort<ChannelType> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| UserSort<UserType>; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| UserSort<UserType> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| SearchMessageSort; | ||||||||||||||||||||||||||||||||||||||||||||||||||
miagilepner marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||
* Base Types | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1898,7 +1925,7 @@ export type SearchPayload< | |||||||||||||||||||||||||||||||||||||||||||||||||
MessageType = UnknownType, | ||||||||||||||||||||||||||||||||||||||||||||||||||
ReactionType = UnknownType, | ||||||||||||||||||||||||||||||||||||||||||||||||||
UserType = UnknownType | ||||||||||||||||||||||||||||||||||||||||||||||||||
> = SearchOptions & { | ||||||||||||||||||||||||||||||||||||||||||||||||||
> = Omit<SearchOptions, 'sort'> & { | ||||||||||||||||||||||||||||||||||||||||||||||||||
client_id?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||
connection_id?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||
filter_conditions?: ChannelFilters<ChannelType, CommandType, UserType>; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1911,6 +1938,10 @@ export type SearchPayload< | |||||||||||||||||||||||||||||||||||||||||||||||||
UserType | ||||||||||||||||||||||||||||||||||||||||||||||||||
>; | ||||||||||||||||||||||||||||||||||||||||||||||||||
query?: string; | ||||||||||||||||||||||||||||||||||||||||||||||||||
sort?: Array<{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
direction: AscDesc; | ||||||||||||||||||||||||||||||||||||||||||||||||||
field: string | number; | ||||||||||||||||||||||||||||||||||||||||||||||||||
miagilepner marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
}>; | ||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
export type TestPushDataInput = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So sort here is throwing a TS error, this is because only one of the 2 search options types has sort on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think you need to spread options here.