Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions .changeset/migrate-chat-search-to-AJV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/rest-typings': major
'@rocket.chat/meteor': major
---

Migrate chat.search endpoint to the one openAPI compatible AJV format
86 changes: 54 additions & 32 deletions apps/meteor/app/api/server/v1/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,60 @@ const chatEndpoints = API.v1

return API.v1.success();
},
)
.get(
'chat.search',
{
authRequired: true,
query: isChatSearchProps,
response: {
400: validateBadRequestErrorResponse,
401: validateUnauthorizedErrorResponse,
200: ajv.compile({
type: 'object',
properties: {
messages: {
type: 'array',
items: { $ref: '#/components/schemas/IMessage' },
},
success: {
type: 'boolean',
enum: [true],
},
},
required: ['messages', 'success'],
additionalProperties: false,
}),
},
},
async function action() {
const { roomId, searchText } = this.queryParams;
const { offset, count } = await getPaginationItems(this.queryParams);

if (!roomId) {
throw new Meteor.Error('error-roomId-param-not-provided', 'The required "roomId" query param is missing.');
}

if (!searchText) {
throw new Meteor.Error('error-searchText-param-not-provided', 'The required "searchText" query param is missing.');
}

const searchResult = await messageSearch(this.userId, searchText, roomId, count, offset);

if (searchResult === false) {
return API.v1.failure();
}

if (!searchResult.message) {
return API.v1.failure();
}

const result = searchResult.message.docs;

return API.v1.success({
messages: await normalizeMessagesForUser(result, this.userId),
});
},
);

API.v1.addRoute(
Expand Down Expand Up @@ -597,38 +651,6 @@ API.v1.addRoute(
},
);

API.v1.addRoute(
'chat.search',
{ authRequired: true, validateParams: isChatSearchProps },
{
async get() {
const { roomId, searchText } = this.queryParams;
const { offset, count } = await getPaginationItems(this.queryParams);

if (!roomId) {
throw new Meteor.Error('error-roomId-param-not-provided', 'The required "roomId" query param is missing.');
}

if (!searchText) {
throw new Meteor.Error('error-searchText-param-not-provided', 'The required "searchText" query param is missing.');
}

const searchResult = await messageSearch(this.userId, searchText, roomId, count, offset);
if (searchResult === false) {
return API.v1.failure();
}
if (!searchResult.message) {
return API.v1.failure();
}
const result = searchResult.message.docs;

return API.v1.success({
messages: await normalizeMessagesForUser(result, this.userId),
});
},
},
);

// The difference between `chat.postMessage` and `chat.sendMessage` is that `chat.sendMessage` allows
// for passing a value for `_id` and the other one doesn't. Also, `chat.sendMessage` only sends it to
// one channel whereas the other one allows for sending to more than one channel at a time.
Expand Down
1 change: 1 addition & 0 deletions packages/core-typings/src/Ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const schemas = typia.json.schemas<
| IBanner
),
CallHistoryItem,
ICalendarEvent,
ICustomUserStatus,
SlashCommand,
],
Expand Down