The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/packages/rocketchat-lib/server/functions/sendMessage.coffee

44 lines
1.3 KiB

RocketChat.sendMessage = (user, message, room, upsert = false) ->
if not user or not message or not room._id
11 years ago
return false
unless message.ts?
message.ts = new Date()
11 years ago
message.u = _.pick user, ['_id','username']
message.rid = room._id
if not room.usernames?
room = RocketChat.models.Rooms.findOneById(room._id)
10 years ago
if message.parseUrls isnt false
10 years ago
if urls = message.msg.match /([A-Za-z]{3,9}):\/\/([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((\/[-\+=!:~%\/\.@\,\w]*)?\??([-\+=&!:;%@\/\.\,\w]+)?(?:#([^\s\)]+))?)?/g
message.urls = urls.map (url) -> url: url
11 years ago
message = RocketChat.callbacks.run 'beforeSaveMessage', message
# Avoid saving sandstormSessionId to the database
sandstormSessionId = null
if message.sandstormSessionId
sandstormSessionId = message.sandstormSessionId
delete message.sandstormSessionId
if message._id? and upsert
_id = message._id
delete message._id
RocketChat.models.Messages.upsert {_id: _id, 'u._id': message.u._id}, message
message._id = _id
else
message._id = RocketChat.models.Messages.insert message
###
Defer other updates as their return is not interesting to the user
###
Meteor.defer ->
# Execute all callbacks
message.sandstormSessionId = sandstormSessionId
RocketChat.callbacks.run 'afterSaveMessage', message, room
return message