@ -1,7 +1,6 @@
import { Meteor } from 'meteor/meteor' ;
import _ from 'underscore' ;
import s from 'underscore.string' ;
import mem from 'mem' ;
import { getRoomByNameOrIdWithOptionToJoin } from './getRoomByNameOrIdWithOptionToJoin' ;
import { sendMessage } from './sendMessage' ;
@ -9,14 +8,7 @@ import { validateRoomMessagePermissions } from '../../../authorization/server/fu
import { SystemLogger } from '../../../../server/lib/logger/system' ;
import { getDirectMessageByIdWithOptionToJoin , getDirectMessageByNameOrIdWithOptionToJoin } from './getDirectMessageByNameOrIdWithOptionToJoin' ;
// show deprecation warning only once per hour for each integration
const showDeprecation = mem ( ( { integration , channels , username } , error ) => {
console . warn ( ` Warning: The integration " ${ integration } " failed to send a message to " ${ [ ] . concat ( channels ) . join ( ',' ) } " because user " ${ username } " doesn't have permission or is not a member of the channel. ` ) ;
console . warn ( 'This behavior is deprecated and starting from version v4.0.0 the following error will be thrown and the message will not be sent.' ) ;
SystemLogger . error ( error ) ;
} , { maxAge : 360000 , cacheKey : ( integration ) => JSON . stringify ( integration ) } ) ;
export const processWebhookMessage = function ( messageObj , user , defaultValues = { channel : '' , alias : '' , avatar : '' , emoji : '' } , integration = null ) {
export const processWebhookMessage = function ( messageObj , user , defaultValues = { channel : '' , alias : '' , avatar : '' , emoji : '' } ) {
const sentData = [ ] ;
const channels = [ ] . concat ( messageObj . channel || messageObj . roomId || defaultValues . channel ) ;
@ -87,18 +79,7 @@ export const processWebhookMessage = function(messageObj, user, defaultValues =
}
}
try {
validateRoomMessagePermissions ( room , { uid : user . _id , ... user } ) ;
} catch ( error ) {
if ( ! integration ) {
throw error ;
}
showDeprecation ( {
integration : integration . name ,
channels : integration . channel ,
username : integration . username ,
} , error ) ;
}
validateRoomMessagePermissions ( room , { uid : user . _id , ... user } ) ;
const messageReturn = sendMessage ( user , message , room ) ;
sentData . push ( { channel , message : messageReturn } ) ;