@ -12,7 +12,7 @@ function findDirectMessageRoomById(roomId, userId) {
return roomSub ;
}
RocketChat . API . v1 . addRoute ( 'im.close', { authRequired : true } , {
RocketChat . API . v1 . addRoute ( [ 'dm.close' , 'im.close'] , { authRequired : true } , {
post : function ( ) {
const findResult = findDirectMessageRoomById ( this . bodyParams . roomId , this . userId ) ;
@ -33,7 +33,7 @@ RocketChat.API.v1.addRoute('im.close', { authRequired: true }, {
}
} ) ;
RocketChat . API . v1 . addRoute ( 'im.history', { authRequired : true } , {
RocketChat . API . v1 . addRoute ( [ 'dm.history' , 'im.history'] , { authRequired : true } , {
get : function ( ) {
const findResult = findDirectMessageRoomById ( this . queryParams . roomId , this . userId ) ;
@ -78,8 +78,47 @@ RocketChat.API.v1.addRoute('im.history', { authRequired: true }, {
}
} ) ;
RocketChat . API . v1 . addRoute ( [ 'dm.messages.others' , 'im.messages.others' ] , { authRequired : true } , {
get : function ( ) {
if ( RocketChat . settings . get ( 'API_Enable_Direct_Message_History_EndPoint' ) !== true ) {
throw new Meteor . Error ( 'error-endpoint-disabled' , 'This endpoint is disabled' , { route : '/api/v1/im.messages.others' } ) ;
}
if ( ! RocketChat . authz . hasPermission ( this . userId , 'view-room-administration' ) ) {
return RocketChat . API . v1 . unauthorized ( ) ;
}
const roomId = this . queryParams . roomId ;
if ( ! roomId || ! roomId . trim ( ) ) {
throw new Meteor . Error ( 'error-roomid-param-not-provided' , 'The parameter "roomId" is required' ) ;
}
const room = RocketChat . models . Rooms . findOneById ( roomId ) ;
if ( ! room || room . t !== 'd' ) {
throw new Meteor . Error ( 'error-room-not-found' , ` No direct message room found by the id of: ${ roomId } ` ) ;
}
const { offset , count } = this . getPaginationItems ( ) ;
const { sort , fields , query } = this . parseJsonQuery ( ) ;
const ourQuery = Object . assign ( { } , query , { rid : room . _id } ) ;
const msgs = RocketChat . models . Messages . find ( ourQuery , {
sort : sort ? sort : { ts : - 1 } ,
skip : offset ,
limit : count ,
fields : Object . assign ( { } , fields , RocketChat . API . v1 . defaultFieldsToExclude )
} ) . fetch ( ) ;
return RocketChat . API . v1 . success ( {
messages : msgs ,
offset ,
count : msgs . length ,
total : RocketChat . models . Messages . find ( ourQuery ) . count ( )
} ) ;
}
} ) ;
RocketChat . API . v1 . addRoute ( 'im.list' , { authRequired : true } , {
RocketChat . API . v1 . addRoute ( [ 'dm.list' , 'im.list'] , { authRequired : true } , {
get : function ( ) {
const { offset , count } = this . getPaginationItems ( ) ;
const { sort , fields } = this . parseJsonQuery ( ) ;
@ -102,7 +141,7 @@ RocketChat.API.v1.addRoute('im.list', { authRequired: true }, {
}
} ) ;
RocketChat . API . v1 . addRoute ( 'im.list.everyone', { authRequired : true } , {
RocketChat . API . v1 . addRoute ( [ 'dm.list.everyone' , 'im.list.everyone'] , { authRequired : true } , {
get : function ( ) {
if ( ! RocketChat . authz . hasPermission ( this . userId , 'view-room-administration' ) ) {
return RocketChat . API . v1 . unauthorized ( ) ;
@ -129,7 +168,7 @@ RocketChat.API.v1.addRoute('im.list.everyone', { authRequired: true }, {
}
} ) ;
RocketChat . API . v1 . addRoute ( 'im.open', { authRequired : true } , {
RocketChat . API . v1 . addRoute ( [ 'dm.open' , 'im.open'] , { authRequired : true } , {
post : function ( ) {
const findResult = findDirectMessageRoomById ( this . bodyParams . roomId , this . userId ) ;
@ -150,7 +189,7 @@ RocketChat.API.v1.addRoute('im.open', { authRequired: true }, {
}
} ) ;
RocketChat . API . v1 . addRoute ( 'im.setTopic', { authRequired : true } , {
RocketChat . API . v1 . addRoute ( [ 'dm.setTopic' , 'im.setTopic'] , { authRequired : true } , {
post : function ( ) {
if ( ! this . bodyParams . topic || ! this . bodyParams . topic . trim ( ) ) {
return RocketChat . API . v1 . failure ( 'The bodyParam "topic" is required' ) ;