@@ -14,8 +14,6 @@ import {
1414 isChatPostMessageProps ,
1515 isChatSearchProps ,
1616 isChatSendMessageProps ,
17- isChatStarMessageProps ,
18- isChatUnstarMessageProps ,
1917 isChatIgnoreUserProps ,
2018 isChatGetPinnedMessagesProps ,
2119 isChatFollowMessageProps ,
@@ -59,6 +57,42 @@ import { API } from '../api';
5957import { getPaginationItems } from '../helpers/getPaginationItems' ;
6058import { findDiscussionsFromRoom , findMentionedMessages , findStarredMessages } from '../lib/messages' ;
6159
60+ type ChatStarMessageLocal = {
61+ messageId : IMessage [ '_id' ] ;
62+ } ;
63+
64+ type ChatUnstarMessageLocal = {
65+ messageId : IMessage [ '_id' ] ;
66+ } ;
67+
68+ const ChatStarMessageLocalSchema = {
69+ type : 'object' ,
70+ properties : {
71+ messageId : {
72+ type : 'string' ,
73+ minLength : 1 ,
74+ } ,
75+ } ,
76+ required : [ 'messageId' ] ,
77+ additionalProperties : false ,
78+ } ;
79+
80+ const ChatUnstarMessageLocalSchema = {
81+ type : 'object' ,
82+ properties : {
83+ messageId : {
84+ type : 'string' ,
85+ minLength : 1 ,
86+ } ,
87+ } ,
88+ required : [ 'messageId' ] ,
89+ additionalProperties : false ,
90+ } ;
91+
92+ const isChatStarMessageLocalProps = ajv . compile < ChatStarMessageLocal > ( ChatStarMessageLocalSchema ) ;
93+
94+ const isChatUnstarMessageLocalProps = ajv . compile < ChatUnstarMessageLocal > ( ChatUnstarMessageLocalSchema ) ;
95+
6296API . v1 . addRoute (
6397 'chat.delete' ,
6498 { authRequired : true , validateParams : isChatDeleteProps } ,
@@ -350,6 +384,80 @@ const chatEndpoints = API.v1
350384 message,
351385 } ) ;
352386 } ,
387+ )
388+ . post (
389+ 'chat.starMessage' ,
390+ {
391+ authRequired : true ,
392+ body : isChatStarMessageLocalProps ,
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 msg = await Messages . findOneById ( this . bodyParams . messageId ) ;
411+
412+ if ( ! msg ) {
413+ throw new Meteor . Error ( 'error-message-not-found' , 'The provided "messageId" does not match any existing message.' ) ;
414+ }
415+
416+ await starMessage ( this . user , {
417+ _id : msg . _id ,
418+ rid : msg . rid ,
419+ starred : true ,
420+ } ) ;
421+
422+ return API . v1 . success ( ) ;
423+ } ,
424+ )
425+ . post (
426+ 'chat.unStarMessage' ,
427+ {
428+ authRequired : true ,
429+ body : isChatUnstarMessageLocalProps ,
430+ response : {
431+ 400 : validateBadRequestErrorResponse ,
432+ 401 : validateUnauthorizedErrorResponse ,
433+ 200 : ajv . compile < void > ( {
434+ type : 'object' ,
435+ properties : {
436+ success : {
437+ type : 'boolean' ,
438+ enum : [ true ] ,
439+ } ,
440+ } ,
441+ required : [ 'success' ] ,
442+ additionalProperties : false ,
443+ } ) ,
444+ } ,
445+ } ,
446+ async function action ( ) {
447+ const msg = await Messages . findOneById ( this . bodyParams . messageId ) ;
448+
449+ if ( ! msg ) {
450+ throw new Meteor . Error ( 'error-message-not-found' , 'The provided "messageId" does not match any existing message.' ) ;
451+ }
452+
453+ await starMessage ( this . user , {
454+ _id : msg . _id ,
455+ rid : msg . rid ,
456+ starred : false ,
457+ } ) ;
458+
459+ return API . v1 . success ( ) ;
460+ } ,
353461 ) ;
354462
355463API . v1 . addRoute (
@@ -445,50 +553,6 @@ API.v1.addRoute(
445553 } ,
446554) ;
447555
448- API . v1 . addRoute (
449- 'chat.starMessage' ,
450- { authRequired : true , validateParams : isChatStarMessageProps } ,
451- {
452- async post ( ) {
453- const msg = await Messages . findOneById ( this . bodyParams . messageId ) ;
454-
455- if ( ! msg ) {
456- throw new Meteor . Error ( 'error-message-not-found' , 'The provided "messageId" does not match any existing message.' ) ;
457- }
458-
459- await starMessage ( this . user , {
460- _id : msg . _id ,
461- rid : msg . rid ,
462- starred : true ,
463- } ) ;
464-
465- return API . v1 . success ( ) ;
466- } ,
467- } ,
468- ) ;
469-
470- API . v1 . addRoute (
471- 'chat.unStarMessage' ,
472- { authRequired : true , validateParams : isChatUnstarMessageProps } ,
473- {
474- async post ( ) {
475- const msg = await Messages . findOneById ( this . bodyParams . messageId ) ;
476-
477- if ( ! msg ) {
478- throw new Meteor . Error ( 'error-message-not-found' , 'The provided "messageId" does not match any existing message.' ) ;
479- }
480-
481- await starMessage ( this . user , {
482- _id : msg . _id ,
483- rid : msg . rid ,
484- starred : false ,
485- } ) ;
486-
487- return API . v1 . success ( ) ;
488- } ,
489- } ,
490- ) ;
491-
492556API . v1 . addRoute (
493557 'chat.react' ,
494558 { authRequired : true , validateParams : isChatReactProps } ,
0 commit comments