Skip to content

Commit 0b774cf

Browse files
committed
Avoid initial callback dispatch
Only execute callback if message timestamp is newer than lastMessage timestamp. This shall fix #17
1 parent e0d26f7 commit 0b774cf

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

demo/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ <h1>User side support</h1>
6464
defaultSupportPic: 'http://lorempixel.com/100/100/people',
6565
onMessage: myFunction,
6666
onSend: function(msg, key) {
67-
console.log('Sent message. Id stored: ' + key);
67+
console.log('#################');
68+
console.log('- Message sent! Key: ' + key);
6869
console.log(msg)
70+
console.log('#################');
6971
}
7072
});
7173

7274
function myFunction(message, key) {
7375
console.log('--------------------');
74-
console.log('- We got a message!');
76+
console.log('- We got a message! key: ' + key);
7577
console.log(message);
76-
console.log('- key:');
77-
console.log(key);
7878
console.log('--------------------');
7979
}
8080
};

dist/chat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ function IASChat(config) {
333333

334334
if(message.uid == uid) {
335335
printMessage(text);
336-
if(typeof onSend === 'function') {
336+
if(typeof onSend === 'function' && message.timestamp > lastMessage.timestamp) {
337337
onSend(message, key);
338338
}
339339
} else {
@@ -344,7 +344,7 @@ function IASChat(config) {
344344
readLastMessage();
345345
}
346346

347-
if(typeof onMessage === 'function') {
347+
if(typeof onMessage === 'function' && message.timestamp > lastMessage.timestamp) {
348348
onMessage(message, key);
349349
}
350350
}

js/chat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ function IASChat(config) {
333333

334334
if(message.uid == uid) {
335335
printMessage(text);
336-
if(typeof onSend === 'function') {
336+
if(typeof onSend === 'function' && message.timestamp > lastMessage.timestamp) {
337337
onSend(message, key);
338338
}
339339
} else {
@@ -344,7 +344,7 @@ function IASChat(config) {
344344
readLastMessage();
345345
}
346346

347-
if(typeof onMessage === 'function') {
347+
if(typeof onMessage === 'function' && message.timestamp > lastMessage.timestamp) {
348348
onMessage(message, key);
349349
}
350350
}

0 commit comments

Comments
 (0)