Skip to content

Commit

Permalink
Fix issue when bot is connected twice
Browse files Browse the repository at this point in the history
  • Loading branch information
oanguenot committed Mar 9, 2018
1 parent 7439ac4 commit 8253e8c
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions modules/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,26 @@ class SDK {

listenToIncomingMessage() {
this._nodeSDK.events.on("rainbow_onmessagereceived", (message) => {
this._nodeSDK.im.markMessageAsRead(message);

this.getContact(message.fromJid).then(contact => {
let msg = new Message({
type: Message.MESSAGE_TYPE.MESSAGE,
jid: message.fromJid,
from: contact,
value: message.content,
lang: message.lang,
date: new Date()

// Do not deal with messages sent by the bot or the bot identity connected in web, mobile...
if(!message.cc) {
this._nodeSDK.im.markMessageAsRead(message);

this.getContact(message.fromJid).then(contact => {
let msg = new Message({
type: Message.MESSAGE_TYPE.MESSAGE,
jid: message.fromJid,
from: contact,
value: message.content,
lang: message.lang,
date: new Date()
});

this._logger.log("debug", LOG_ID + "listenToIncomingMessage() - Received " + msg.type);

this._event.emit("onmessagereceived", msg);
});

this._logger.log("debug", LOG_ID + "listenToIncomingMessage() - Received " + msg.type);

this._event.emit("onmessagereceived", msg);
});
}
});

this._nodeSDK.events.on("rainbow_onmessagereceiptreceived", (receipt) => {
Expand Down

0 comments on commit 8253e8c

Please sign in to comment.