From 7a54537beebcc208b77bc8caac7f0ce5b6b36b9d Mon Sep 17 00:00:00 2001 From: Zalmoxisus Date: Sat, 13 Jun 2015 00:14:31 +0300 Subject: [PATCH] Fixes chat messages timestamp according to XEP-0203. Fixes #305. --- modules/API/API.js | 4 ++-- modules/UI/UI.js | 6 +++--- modules/UI/side_pannels/chat/Chat.js | 8 ++++---- modules/xmpp/strophe.emuc.js | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/API/API.js b/modules/API/API.js index 44256ff7b..ac9f7e6b2 100644 --- a/modules/API/API.js +++ b/modules/API/API.js @@ -138,10 +138,10 @@ function setupListeners() { APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_JOINED, function (from) { API.triggerEvent("participantJoined", {jid: from}); }); - APP.xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, function (from, nick, txt, myjid) { + APP.xmpp.addListener(XMPPEvents.MESSAGE_RECEIVED, function (from, nick, txt, myjid, stamp) { if (from != myjid) API.triggerEvent("incomingMessage", - {"from": from, "nick": nick, "message": txt}); + {"from": from, "nick": nick, "message": txt, "stamp": stamp}); }); APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_LEFT, function (jid) { API.triggerEvent("participantLeft", {jid: jid}); diff --git a/modules/UI/UI.js b/modules/UI/UI.js index 0e68d1831..6c3a243ba 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -408,9 +408,9 @@ function chatSetSubject(text) return Chat.chatSetSubject(text); }; -function updateChatConversation(from, displayName, message) { - return Chat.updateChatConversation(from, displayName, message); -}; +function updateChatConversation(from, displayName, message, myjid, stamp) { + return Chat.updateChatConversation(from, displayName, message, myjid, stamp); +} function onMucJoined(jid, info) { Toolbar.updateRoomUrl(window.location.href); diff --git a/modules/UI/side_pannels/chat/Chat.js b/modules/UI/side_pannels/chat/Chat.js index 5f9fb7e9c..e5965bea7 100644 --- a/modules/UI/side_pannels/chat/Chat.js +++ b/modules/UI/side_pannels/chat/Chat.js @@ -85,8 +85,8 @@ function setVisualNotification(show) { * Returns the current time in the format it is shown to the user * @returns {string} */ -function getCurrentTime() { - var now = new Date(); +function getCurrentTime(stamp) { + var now = (stamp? new Date(stamp): new Date()); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); @@ -228,7 +228,7 @@ var Chat = (function (my) { /** * Appends the given message to the chat conversation. */ - my.updateChatConversation = function (from, displayName, message) { + my.updateChatConversation = function (from, displayName, message, myjid, stamp) { var divClassName = ''; if (APP.xmpp.myJid() === from) { @@ -256,7 +256,7 @@ var Chat = (function (my) { '
'+ '' + '
' + escDisplayName + - '
' + '
' + getCurrentTime() + + '
' + '
' + getCurrentTime(stamp) + '
' + '
' + message + '
' + '
'; diff --git a/modules/xmpp/strophe.emuc.js b/modules/xmpp/strophe.emuc.js index 1a7d68fbf..68a67d1ac 100644 --- a/modules/xmpp/strophe.emuc.js +++ b/modules/xmpp/strophe.emuc.js @@ -389,7 +389,7 @@ module.exports = function(XMPP, eventEmitter) { if (txt) { console.log('chat', nick, txt); eventEmitter.emit(XMPPEvents.MESSAGE_RECEIVED, - from, nick, txt, this.myroomjid); + from, nick, txt, this.myroomjid, $(msg).find('>delay').attr('stamp')); } return true; },