@@ -64,6 +64,7 @@ import { createDiscussion } from '../../../discussion/server/methods/createDiscu
6464import { FileUpload } from '../../../file-upload/server' ;
6565import { sendFileMessage } from '../../../file-upload/server/methods/sendFileMessage' ;
6666import { syncRolePrioritiesForRoomIfRequired } from '../../../lib/server/functions/syncRolePrioritiesForRoomIfRequired' ;
67+ import { notifyOnSubscriptionChanged } from '../../../lib/server/lib/notifyListener' ;
6768import { executeArchiveRoom } from '../../../lib/server/methods/archiveRoom' ;
6869import { cleanRoomHistoryMethod } from '../../../lib/server/methods/cleanRoomHistory' ;
6970import { executeGetRoomRoles } from '../../../lib/server/methods/getRoomRoles' ;
@@ -414,6 +415,54 @@ const roomsSaveNotificationEndpoint = API.v1.post(
414415 } ,
415416) ;
416417
418+ const saveDraftBodySchema = ajv . compile < { rid : IRoom [ '_id' ] ; draft : string } > ( {
419+ type : 'object' ,
420+ properties : {
421+ rid : { type : 'string' , minLength : 1 } ,
422+ draft : { type : 'string' } ,
423+ } ,
424+ required : [ 'rid' , 'draft' ] ,
425+ additionalProperties : false ,
426+ } ) ;
427+
428+ const saveDraftResponseSchema = ajv . compile < void > ( {
429+ type : 'object' ,
430+ properties : {
431+ success : { type : 'boolean' , enum : [ true ] } ,
432+ } ,
433+ required : [ 'success' ] ,
434+ additionalProperties : false ,
435+ } ) ;
436+
437+ const roomsSaveDraftEndpoint = API . v1 . post (
438+ 'rooms.saveDraft' ,
439+ {
440+ authRequired : true ,
441+ body : saveDraftBodySchema ,
442+ response : {
443+ 200 : saveDraftResponseSchema ,
444+ 400 : validateBadRequestErrorResponse ,
445+ 401 : validateUnauthorizedErrorResponse ,
446+ } ,
447+ } ,
448+ async function action ( ) {
449+ const { rid, draft } = this . bodyParams ;
450+
451+ if ( draft . length > ( settings . get < number > ( 'Message_MaxAllowedSize' ) ?? 0 ) ) {
452+ return API . v1 . failure ( 'error-message-size-exceeded' ) ;
453+ }
454+
455+ const subscription = await Subscriptions . updateDraftByRoomIdAndUserId ( rid , this . userId , draft || undefined ) ;
456+ if ( ! subscription ) {
457+ throw new Meteor . Error ( 'error-invalid-subscription' , 'Invalid subscription' ) ;
458+ }
459+
460+ void notifyOnSubscriptionChanged ( subscription ) ;
461+
462+ return API . v1 . success ( ) ;
463+ } ,
464+ ) ;
465+
417466API . v1 . post (
418467 'rooms.cleanHistory' ,
419468 {
@@ -1630,7 +1679,8 @@ export const roomEndpoints = API.v1
16301679 ) ;
16311680type RoomEndpoints = ExtractRoutesFromAPI < typeof roomEndpoints > &
16321681 ExtractRoutesFromAPI < typeof roomDeleteEndpoint > &
1633- ExtractRoutesFromAPI < typeof roomsSaveNotificationEndpoint > ;
1682+ ExtractRoutesFromAPI < typeof roomsSaveNotificationEndpoint > &
1683+ ExtractRoutesFromAPI < typeof roomsSaveDraftEndpoint > ;
16341684
16351685declare module '@rocket.chat/rest-typings' {
16361686 // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
0 commit comments