Fixes chat messages timestamp according to XEP-0203. Fixes #305.

This commit is contained in:
Zalmoxisus 2015-06-13 00:14:31 +03:00 committed by Damian Minkov
parent 6a492d96c2
commit 7a54537bee
4 changed files with 10 additions and 10 deletions

View File

@ -138,10 +138,10 @@ function setupListeners() {
APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_JOINED, function (from) { APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_JOINED, function (from) {
API.triggerEvent("participantJoined", {jid: 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) if (from != myjid)
API.triggerEvent("incomingMessage", 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) { APP.xmpp.addListener(XMPPEvents.MUC_MEMBER_LEFT, function (jid) {
API.triggerEvent("participantLeft", {jid: jid}); API.triggerEvent("participantLeft", {jid: jid});

View File

@ -408,9 +408,9 @@ function chatSetSubject(text)
return Chat.chatSetSubject(text); return Chat.chatSetSubject(text);
}; };
function updateChatConversation(from, displayName, message) { function updateChatConversation(from, displayName, message, myjid, stamp) {
return Chat.updateChatConversation(from, displayName, message); return Chat.updateChatConversation(from, displayName, message, myjid, stamp);
}; }
function onMucJoined(jid, info) { function onMucJoined(jid, info) {
Toolbar.updateRoomUrl(window.location.href); Toolbar.updateRoomUrl(window.location.href);

View File

@ -85,8 +85,8 @@ function setVisualNotification(show) {
* Returns the current time in the format it is shown to the user * Returns the current time in the format it is shown to the user
* @returns {string} * @returns {string}
*/ */
function getCurrentTime() { function getCurrentTime(stamp) {
var now = new Date(); var now = (stamp? new Date(stamp): new Date());
var hour = now.getHours(); var hour = now.getHours();
var minute = now.getMinutes(); var minute = now.getMinutes();
var second = now.getSeconds(); var second = now.getSeconds();
@ -228,7 +228,7 @@ var Chat = (function (my) {
/** /**
* Appends the given message to the chat conversation. * Appends the given message to the chat conversation.
*/ */
my.updateChatConversation = function (from, displayName, message) { my.updateChatConversation = function (from, displayName, message, myjid, stamp) {
var divClassName = ''; var divClassName = '';
if (APP.xmpp.myJid() === from) { if (APP.xmpp.myJid() === from) {
@ -256,7 +256,7 @@ var Chat = (function (my) {
'<div class="chatmessage">'+ '<div class="chatmessage">'+
'<img src="../images/chatArrow.svg" class="chatArrow">' + '<img src="../images/chatArrow.svg" class="chatArrow">' +
'<div class="username ' + divClassName +'">' + escDisplayName + '<div class="username ' + divClassName +'">' + escDisplayName +
'</div>' + '<div class="timestamp">' + getCurrentTime() + '</div>' + '<div class="timestamp">' + getCurrentTime(stamp) +
'</div>' + '<div class="usermessage">' + message + '</div>' + '</div>' + '<div class="usermessage">' + message + '</div>' +
'</div>'; '</div>';

View File

@ -389,7 +389,7 @@ module.exports = function(XMPP, eventEmitter) {
if (txt) { if (txt) {
console.log('chat', nick, txt); console.log('chat', nick, txt);
eventEmitter.emit(XMPPEvents.MESSAGE_RECEIVED, eventEmitter.emit(XMPPEvents.MESSAGE_RECEIVED,
from, nick, txt, this.myroomjid); from, nick, txt, this.myroomjid, $(msg).find('>delay').attr('stamp'));
} }
return true; return true;
}, },