Skip to content
Snippets Groups Projects
Unverified Commit 3364c092 authored by Gabriel Engel's avatar Gabriel Engel
Browse files

improved ts diff function

parent 5dbf4eb4
No related branches found
No related tags found
No related merge requests found
......@@ -18,9 +18,9 @@ RocketChat.sendMessage = (user, message, room, upsert = false) ->
message = RocketChat.callbacks.run 'beforeSaveMessage', message
# Avoid saving sandstormSessionId to the database
sandstormSessionId = null
if message.sandstormSessionId
# Persisting sessionId to the database is a bad idea.
sandstormSessionId = message.sandstormSessionId
delete message.sandstormSessionId
......
......@@ -4,7 +4,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
return message;
}
if (message.ts && (moment(message.ts).subtract(5, 'seconds').isBefore(new Date) || moment(message.ts).isAfter(moment().add(5, 'seconds')))) {
if (message.ts && Math.abs(moment(message.ts).diff()) > 60000) {
return message;
}
......
......@@ -4,7 +4,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
return message;
}
if (message.ts && (moment(message.ts).subtract(5, 'seconds').isBefore(new Date) || moment(message.ts).isAfter(moment().add(5, 'seconds')))) {
if (message.ts && Math.abs(moment(message.ts).diff()) > 60000) {
return message;
}
......
Meteor.methods
sendMessage: (message) ->
if message.ts and (moment(message.ts).subtract(5, 'seconds').isBefore(new Date) or moment(message.ts).isAfter(moment().add(5, 'seconds')))
throw new Meteor.Error('error-message-ts-out-of-sync', 'Message timestamp is out of sync', { method: 'sendMessage', message_ts: message.ts, server_ts: new Date().getTime() })
if message.ts
tsDiff = Math.abs(moment(message.ts).diff())
if tsDiff > 60000
throw new Meteor.Error('error-message-ts-out-of-sync', 'Message timestamp is out of sync', { method: 'sendMessage', message_ts: message.ts, server_ts: new Date().getTime() })
else if tsDiff > 10000
message.ts = new Date()
if message.msg?.length > RocketChat.settings.get('Message_MaxAllowedSize')
throw new Meteor.Error('error-message-size-exceeded', 'Message size exceeds Message_MaxAllowedSize', { method: 'sendMessage' })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment