Skip to content

Commit d824760

Browse files
committed
fix(chat): address review feedback for chat.getThreadsList schema and validation
1 parent 257ef25 commit d824760

File tree

2 files changed

+57
-105
lines changed
  • apps/meteor/app/api/server/v1
  • packages/rest-typings/src/v1

2 files changed

+57
-105
lines changed

apps/meteor/app/api/server/v1/chat.ts

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Message } from '@rocket.chat/core-services';
2-
import type { IMessage, IThreadMainMessage } from '@rocket.chat/core-typings';
2+
import type { IMessage, IThreadMainMessage, IRoom } from '@rocket.chat/core-typings';
33
import { MessageTypes } from '@rocket.chat/message-types';
44
import { Messages, Users, Rooms, Subscriptions } from '@rocket.chat/models';
5+
import type { PaginatedRequest } from '@rocket.chat/rest-typings';
56
import {
67
ajv,
78
isChatReportMessageProps,
89
isChatGetURLPreviewProps,
910
isChatUpdateProps,
10-
isChatGetThreadsListProps,
1111
isChatDeleteProps,
1212
isChatSyncMessagesProps,
1313
isChatGetMessageProps,
@@ -275,6 +275,55 @@ const isChatPinMessageProps = ajv.compile<ChatPinMessage>(ChatPinMessageSchema);
275275

276276
const isChatUnpinMessageProps = ajv.compile<ChatUnpinMessage>(ChatUnpinMessageSchema);
277277

278+
type ChatGetThreadsList = PaginatedRequest<{
279+
rid: IRoom['_id'];
280+
type?: 'unread' | 'following';
281+
text?: string;
282+
fields?: string;
283+
}>;
284+
285+
const ChatGetThreadsListSchema = {
286+
type: 'object',
287+
properties: {
288+
rid: {
289+
type: 'string',
290+
},
291+
type: {
292+
type: 'string',
293+
enum: ['following', 'unread'],
294+
nullable: true,
295+
},
296+
text: {
297+
type: 'string',
298+
nullable: true,
299+
},
300+
offset: {
301+
type: 'number',
302+
nullable: true,
303+
},
304+
count: {
305+
type: 'number',
306+
nullable: true,
307+
},
308+
sort: {
309+
type: 'string',
310+
nullable: true,
311+
},
312+
query: {
313+
type: 'string',
314+
nullable: true,
315+
},
316+
fields: {
317+
type: 'string',
318+
nullable: true,
319+
},
320+
},
321+
required: ['rid'],
322+
additionalProperties: false,
323+
};
324+
325+
const isChatGetThreadsListLocalProps = ajv.compile<ChatGetThreadsList>(ChatGetThreadsListSchema);
326+
278327
const isChatGetThreadsListResponse = ajv.compile<{
279328
threads: IMessage[];
280329
count: number;
@@ -302,7 +351,7 @@ const isChatGetThreadsListResponse = ajv.compile<{
302351
success: {
303352
type: 'boolean',
304353
enum: [true],
305-
}
354+
},
306355
},
307356
required: ['threads', 'count', 'offset', 'total', 'success'],
308357
additionalProperties: false,
@@ -596,7 +645,7 @@ const chatEndpoints = API.v1
596645
'chat.getThreadsList',
597646
{
598647
authRequired: true,
599-
query: isChatGetThreadsListProps,
648+
query: isChatGetThreadsListLocalProps,
600649
response: {
601650
400: validateBadRequestErrorResponse,
602651
401: validateUnauthorizedErrorResponse,
@@ -867,7 +916,6 @@ API.v1.addRoute(
867916
},
868917
);
869918

870-
871919
API.v1.addRoute(
872920
'chat.syncThreadsList',
873921
{ authRequired: true, validateParams: isChatSyncThreadsListProps },
@@ -1089,9 +1137,9 @@ API.v1.addRoute(
10891137
},
10901138
);
10911139

1140+
10921141
export type ChatEndpoints = ExtractRoutesFromAPI<typeof chatEndpoints>;
10931142

10941143
declare module '@rocket.chat/rest-typings' {
1095-
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
1096-
interface Endpoints extends ChatEndpoints {}
1097-
}
1144+
interface Endpoints extends ChatEndpoints {}
1145+
}

packages/rest-typings/src/v1/chat.ts

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { IMessage, IRoom, MessageAttachment, IReadReceiptWithUser, MessageUrl, IThreadMainMessage } from '@rocket.chat/core-typings';
1+
import type { IMessage, IRoom, MessageAttachment, IReadReceiptWithUser, MessageUrl} from '@rocket.chat/core-typings';
22

33
import { ajv } from './Ajv';
44
import type { PaginatedRequest } from '../helpers/PaginatedRequest';
@@ -146,54 +146,6 @@ const ChatReportMessageSchema = {
146146

147147
export const isChatReportMessageProps = ajv.compile<ChatReportMessage>(ChatReportMessageSchema);
148148

149-
type ChatGetThreadsList = PaginatedRequest<{
150-
rid: IRoom['_id'];
151-
type?: 'unread' | 'following';
152-
text?: string;
153-
fields?: string;
154-
}>;
155-
156-
const ChatGetThreadsListSchema = {
157-
type: 'object',
158-
properties: {
159-
rid: {
160-
type: 'string',
161-
},
162-
type: {
163-
type: 'string',
164-
enum: ['following', 'unread'],
165-
nullable: true,
166-
},
167-
text: {
168-
type: 'string',
169-
nullable: true,
170-
},
171-
offset: {
172-
type: 'number',
173-
nullable: true,
174-
},
175-
count: {
176-
type: 'number',
177-
nullable: true,
178-
},
179-
sort: {
180-
type: 'string',
181-
nullable: true,
182-
},
183-
query: {
184-
type: 'string',
185-
nullable: true,
186-
},
187-
fields: {
188-
type: 'string',
189-
nullable: true,
190-
},
191-
},
192-
required: ['rid'],
193-
additionalProperties: false,
194-
};
195-
196-
export const isChatGetThreadsListProps = ajv.compile<ChatGetThreadsList>(ChatGetThreadsListSchema);
197149

198150
type ChatSyncThreadsList = {
199151
rid: IRoom['_id'];
@@ -638,40 +590,6 @@ const ChatSyncMessagesSchema = {
638590

639591
export const isChatSyncMessagesProps = ajv.compile<ChatSyncMessages>(ChatSyncMessagesSchema);
640592

641-
type ChatSyncThreadMessages = PaginatedRequest<{
642-
tmid: string;
643-
updatedSince: string;
644-
}>;
645-
646-
const ChatSyncThreadMessagesSchema = {
647-
type: 'object',
648-
properties: {
649-
tmid: {
650-
type: 'string',
651-
minLength: 1,
652-
},
653-
updatedSince: {
654-
type: 'string',
655-
format: 'iso-date-time',
656-
},
657-
count: {
658-
type: 'number',
659-
nullable: true,
660-
},
661-
offset: {
662-
type: 'number',
663-
nullable: true,
664-
},
665-
sort: {
666-
type: 'string',
667-
nullable: true,
668-
},
669-
},
670-
required: ['tmid', 'updatedSince'],
671-
additionalProperties: false,
672-
};
673-
674-
export const isChatSyncThreadMessagesProps = ajv.compile<ChatSyncThreadMessages>(ChatSyncThreadMessagesSchema);
675593

676594
type ChatGetThreadMessages = PaginatedRequest<{
677595
tmid: string;
@@ -906,12 +824,6 @@ export type ChatEndpoints = {
906824
total: number;
907825
};
908826
};
909-
'/v1/chat.getThreadsList': {
910-
GET: (params: ChatGetThreadsList) => {
911-
threads: IThreadMainMessage[];
912-
total: number;
913-
};
914-
};
915827
'/v1/chat.syncThreadsList': {
916828
GET: (params: ChatSyncThreadsList) => {
917829
threads: {
@@ -989,14 +901,6 @@ export type ChatEndpoints = {
989901
message: IMessage;
990902
};
991903
};
992-
'/v1/chat.syncThreadMessages': {
993-
GET: (params: ChatSyncThreadMessages) => {
994-
messages: {
995-
update: IMessage[];
996-
remove: IMessage[];
997-
};
998-
};
999-
};
1000904
'/v1/chat.getThreadMessages': {
1001905
GET: (params: ChatGetThreadMessages) => {
1002906
messages: IMessage[];

0 commit comments

Comments
 (0)