Skip to content

Commit

Permalink
Avoid initial callback dispatch
Browse files Browse the repository at this point in the history
Only execute callback if message timestamp is newer than lastMessage
timestamp. This shall fix #17
  • Loading branch information
CodingCarlos committed Mar 11, 2017
1 parent e0d26f7 commit 0b774cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ <h1>User side support</h1>
defaultSupportPic: 'http://lorempixel.com/100/100/people',
onMessage: myFunction,
onSend: function(msg, key) {
console.log('Sent message. Id stored: ' + key);
console.log('#################');
console.log('- Message sent! Key: ' + key);
console.log(msg)
console.log('#################');
}
});

function myFunction(message, key) {
console.log('--------------------');
console.log('- We got a message!');
console.log('- We got a message! key: ' + key);
console.log(message);
console.log('- key:');
console.log(key);
console.log('--------------------');
}
};
Expand Down
4 changes: 2 additions & 2 deletions dist/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ function IASChat(config) {

if(message.uid == uid) {
printMessage(text);
if(typeof onSend === 'function') {
if(typeof onSend === 'function' && message.timestamp > lastMessage.timestamp) {
onSend(message, key);
}
} else {
Expand All @@ -344,7 +344,7 @@ function IASChat(config) {
readLastMessage();
}

if(typeof onMessage === 'function') {
if(typeof onMessage === 'function' && message.timestamp > lastMessage.timestamp) {
onMessage(message, key);
}
}
Expand Down
4 changes: 2 additions & 2 deletions js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ function IASChat(config) {

if(message.uid == uid) {
printMessage(text);
if(typeof onSend === 'function') {
if(typeof onSend === 'function' && message.timestamp > lastMessage.timestamp) {
onSend(message, key);
}
} else {
Expand All @@ -344,7 +344,7 @@ function IASChat(config) {
readLastMessage();
}

if(typeof onMessage === 'function') {
if(typeof onMessage === 'function' && message.timestamp > lastMessage.timestamp) {
onMessage(message, key);
}
}
Expand Down

0 comments on commit 0b774cf

Please sign in to comment.