Skip to content

Commit 2f60a09

Browse files
committed
chore: migrate chat.followMessage and chat.unfollowMessage to OpenAPI
1 parent 3c30636 commit 2f60a09

File tree

3 files changed

+108
-80
lines changed

3 files changed

+108
-80
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@rocket.chat/meteor": minor
3+
"@rocket.chat/rest-typings": minor
4+
---
5+
6+
Add OpenAPI support for the chat.followMessage and chat.unfollowMessage API endpoints by migrating to a modern chained route definition syntax and utilizing AJV schemas for body and response validation.

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

Lines changed: 102 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import {
1818
isChatUnstarMessageProps,
1919
isChatIgnoreUserProps,
2020
isChatGetPinnedMessagesProps,
21-
isChatFollowMessageProps,
22-
isChatUnfollowMessageProps,
2321
isChatGetMentionedMessagesProps,
2422
isChatReactProps,
2523
isChatGetDeletedMessagesProps,
@@ -59,6 +57,42 @@ import { API } from '../api';
5957
import { getPaginationItems } from '../helpers/getPaginationItems';
6058
import { findDiscussionsFromRoom, findMentionedMessages, findStarredMessages } from '../lib/messages';
6159

60+
type ChatFollowMessageLocal = {
61+
mid: string;
62+
};
63+
64+
const ChatFollowMessageLocalSchema = {
65+
type: 'object',
66+
properties: {
67+
mid: {
68+
type: 'string',
69+
minLength: 1,
70+
},
71+
},
72+
required: ['mid'],
73+
additionalProperties: false,
74+
};
75+
76+
const isChatFollowMessageLocalProps = ajv.compile<ChatFollowMessageLocal>(ChatFollowMessageLocalSchema);
77+
78+
type ChatUnfollowMessageLocal = {
79+
mid: string;
80+
};
81+
82+
const ChatUnfollowMessageLocalSchema = {
83+
type: 'object',
84+
properties: {
85+
mid: {
86+
type: 'string',
87+
minLength: 1,
88+
},
89+
},
90+
required: ['mid'],
91+
additionalProperties: false,
92+
};
93+
94+
const isChatUnfollowMessageLocalProps = ajv.compile<ChatUnfollowMessageLocal>(ChatUnfollowMessageLocalSchema);
95+
6296
API.v1.addRoute(
6397
'chat.delete',
6498
{ authRequired: true, validateParams: isChatDeleteProps },
@@ -350,6 +384,72 @@ const chatEndpoints = API.v1
350384
message,
351385
});
352386
},
387+
)
388+
.post(
389+
'chat.followMessage',
390+
{
391+
authRequired: true,
392+
body: isChatFollowMessageLocalProps,
393+
response: {
394+
400: validateBadRequestErrorResponse,
395+
401: validateUnauthorizedErrorResponse,
396+
200: ajv.compile<void>({
397+
type: 'object',
398+
properties: {
399+
success: {
400+
type: 'boolean',
401+
enum: [true],
402+
},
403+
},
404+
required: ['success'],
405+
additionalProperties: false,
406+
}),
407+
},
408+
},
409+
async function action() {
410+
const { mid } = this.bodyParams;
411+
412+
if (!mid) {
413+
throw new Meteor.Error('The required "mid" body param is missing.');
414+
}
415+
416+
await followMessage(this.user, { mid });
417+
418+
return API.v1.success();
419+
},
420+
)
421+
.post(
422+
'chat.unfollowMessage',
423+
{
424+
authRequired: true,
425+
body: isChatUnfollowMessageLocalProps,
426+
response: {
427+
400: validateBadRequestErrorResponse,
428+
401: validateUnauthorizedErrorResponse,
429+
200: ajv.compile<void>({
430+
type: 'object',
431+
properties: {
432+
success: {
433+
type: 'boolean',
434+
enum: [true],
435+
},
436+
},
437+
required: ['success'],
438+
additionalProperties: false,
439+
}),
440+
},
441+
},
442+
async function action() {
443+
const { mid } = this.bodyParams;
444+
445+
if (!mid) {
446+
throw new Meteor.Error('The required "mid" body param is missing.');
447+
}
448+
449+
await unfollowMessage(this.user, { mid });
450+
451+
return API.v1.success();
452+
},
353453
);
354454

355455
API.v1.addRoute(
@@ -793,42 +893,6 @@ API.v1.addRoute(
793893
},
794894
);
795895

796-
API.v1.addRoute(
797-
'chat.followMessage',
798-
{ authRequired: true, validateParams: isChatFollowMessageProps },
799-
{
800-
async post() {
801-
const { mid } = this.bodyParams;
802-
803-
if (!mid) {
804-
throw new Meteor.Error('The required "mid" body param is missing.');
805-
}
806-
807-
await followMessage(this.user, { mid });
808-
809-
return API.v1.success();
810-
},
811-
},
812-
);
813-
814-
API.v1.addRoute(
815-
'chat.unfollowMessage',
816-
{ authRequired: true, validateParams: isChatUnfollowMessageProps },
817-
{
818-
async post() {
819-
const { mid } = this.bodyParams;
820-
821-
if (!mid) {
822-
throw new Meteor.Error('The required "mid" body param is missing.');
823-
}
824-
825-
await unfollowMessage(this.user, { mid });
826-
827-
return API.v1.success();
828-
},
829-
},
830-
);
831-
832896
API.v1.addRoute(
833897
'chat.getMentionedMessages',
834898
{ authRequired: true, validateParams: isChatGetMentionedMessagesProps },

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

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -79,42 +79,6 @@ const chatSendMessageSchema = {
7979

8080
export const isChatSendMessageProps = ajv.compile<ChatSendMessage>(chatSendMessageSchema);
8181

82-
type ChatFollowMessage = {
83-
mid: IMessage['_id'];
84-
};
85-
86-
const chatFollowMessageSchema = {
87-
type: 'object',
88-
properties: {
89-
mid: {
90-
type: 'string',
91-
minLength: 1,
92-
},
93-
},
94-
required: ['mid'],
95-
additionalProperties: false,
96-
};
97-
98-
export const isChatFollowMessageProps = ajv.compile<ChatFollowMessage>(chatFollowMessageSchema);
99-
100-
type ChatUnfollowMessage = {
101-
mid: IMessage['_id'];
102-
};
103-
104-
const chatUnfollowMessageSchema = {
105-
type: 'object',
106-
properties: {
107-
mid: {
108-
type: 'string',
109-
minLength: 1,
110-
},
111-
},
112-
required: ['mid'],
113-
additionalProperties: false,
114-
};
115-
116-
export const isChatUnfollowMessageProps = ajv.compile<ChatUnfollowMessage>(chatUnfollowMessageSchema);
117-
11882
type ChatGetMessage = {
11983
msgId: IMessage['_id'];
12084
};
@@ -967,12 +931,6 @@ export type ChatEndpoints = {
967931
message: IMessage;
968932
};
969933
};
970-
'/v1/chat.followMessage': {
971-
POST: (params: ChatFollowMessage) => void;
972-
};
973-
'/v1/chat.unfollowMessage': {
974-
POST: (params: ChatUnfollowMessage) => void;
975-
};
976934
'/v1/chat.starMessage': {
977935
POST: (params: ChatStarMessage) => void;
978936
};

0 commit comments

Comments
 (0)