mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-21 04:25:27 -04:00
Add utility features for searching.
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "revolt.js",
|
||||
"version": "4.3.3-alpha.12",
|
||||
"version": "4.3.3-alpha.13",
|
||||
"main": "dist/index.js",
|
||||
"repository": "https://gitlab.insrt.uk/revolt/revolt.js",
|
||||
"author": "Paul Makles <insrt.uk>",
|
||||
|
||||
+1
-1
@@ -410,7 +410,7 @@ type Routes =
|
||||
}
|
||||
| {
|
||||
// Search messages in a channel (optionally include users as well).
|
||||
method: 'GET',
|
||||
method: 'POST',
|
||||
route: `/channels/${Id}/search`,
|
||||
data: {
|
||||
query: string,
|
||||
|
||||
@@ -232,6 +232,40 @@ export default class Channels extends Collection<Channel> {
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for messages
|
||||
* @param id ID of the target channel
|
||||
* @param params Message searching route data
|
||||
* @returns The messages
|
||||
*/
|
||||
async search(id: string, params?: Omit<Route<'POST', '/channels/id/search'>["data"], 'include_users'>) {
|
||||
return await this.client.request('POST', `/channels/${id}/search` as '/channels/id/search', { params }) as Message[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for messages including the users that sent them
|
||||
* @param id ID of the target channel
|
||||
* @param params Message searching route data
|
||||
* @returns The messages
|
||||
*/
|
||||
async searchWithUsers(id: string, params?: Omit<Route<'POST', '/channels/id/search'>["data"], 'include_users'>, processUsers?: boolean) {
|
||||
let res = await this.client.request('GET', `/channels/${id}/search` as '/channels/id/search', { params: { ...params, include_users: true } }) as { messages: Message[], users: User[], members: Servers.Member[] };
|
||||
|
||||
if (processUsers) {
|
||||
for (let user of res.users) {
|
||||
this.client.users.set(user);
|
||||
}
|
||||
|
||||
if (res.members) {
|
||||
for (let member of res.members) {
|
||||
this.client.servers.members.set(flattenMember(member));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch stale messages
|
||||
* @param id ID of the target channel
|
||||
|
||||
Reference in New Issue
Block a user