diff --git a/converse.js b/converse.js index 74a22005c..a98eba108 100644 --- a/converse.js +++ b/converse.js @@ -932,7 +932,14 @@ } }); - this.Message = Backbone.Model; + this.Message = Backbone.Model.extend({ + idAttribute: 'msgid', + defaults: function(){ + return { + msgid: converse.connection.getUniqueId() + }; + } + }); this.Messages = Backbone.Collection.extend({ model: converse.Message, comparator: 'time' @@ -1087,7 +1094,7 @@ this.trigger('showReceivedOTRMessage', msg); }.bind(this)); this.otr.on('io', function (msg) { - this.trigger('sendMessage', msg); + this.trigger('sendMessage', new converse.Message({ message: msg })); }.bind(this)); this.otr.on('error', function (msg) { this.trigger('showOTRError', msg); @@ -1498,6 +1505,7 @@ extra_classes += ' mentioned'; } return $(template({ + msgid: attrs.msgid, 'sender': attrs.sender, 'time': msg_time.format('hh:mm'), 'isodate': msg_time.format(), @@ -1553,30 +1561,29 @@ } }, - sendMessage: function (text) { + sendMessage: function (message) { /* Responsible for sending off a text message. * * Parameters: - * (string) text - The chat message text. + * (Message) message - The chat message */ // TODO: We might want to send to specfic resources. Especially in the OTR case. - var timestamp = (new Date()).getTime(); var bare_jid = this.model.get('jid'); - var message = $msg({from: converse.connection.jid, to: bare_jid, type: 'chat', id: timestamp}) - .c('body').t(text).up() + var messageStanza = $msg({from: converse.connection.jid, to: bare_jid, type: 'chat', id: message.get('msgid')}) + .c('body').t(message.get('message')).up() .c(ACTIVE, {'xmlns': Strophe.NS.CHATSTATES}).up(); if (this.model.get('otr_status') != UNENCRYPTED) { // OTR messages aren't carbon copied - message.c('private', {'xmlns': Strophe.NS.CARBONS}); + messageStanza.c('private', {'xmlns': Strophe.NS.CARBONS}); } - converse.connection.send(message); + converse.connection.send(messageStanza); if (converse.forward_messages) { // Forward the message, so that other connected resources are also aware of it. - var forwarded = $msg({to:converse.bare_jid, type:'chat', id:timestamp}) + var forwarded = $msg({ to: converse.bare_jid, type: 'chat', id: message.get('msgid') }) .c('forwarded', {xmlns:'urn:xmpp:forward:0'}) .c('delay', {xmns:'urn:xmpp:delay',stamp:timestamp}).up() - .cnode(message.tree()); + .cnode(messageStanza.tree()); converse.connection.send(forwarded); } }, @@ -1618,13 +1625,13 @@ // We only save unencrypted messages. var fullname = converse.xmppstatus.get('fullname'); fullname = _.isEmpty(fullname)? converse.bare_jid: fullname; - this.model.messages.create({ + var message = this.model.messages.create({ fullname: fullname, sender: 'me', time: moment().format(), message: text }); - this.sendMessage(text); + this.sendMessage(message); } }, diff --git a/docs/CHANGES.rst b/docs/CHANGES.rst index b1cd3a989..ab55d2027 100644 --- a/docs/CHANGES.rst +++ b/docs/CHANGES.rst @@ -8,6 +8,7 @@ Changelog * #468 Fix [object Object] being sometimes shown as status [1st8] * #493 Roster wasn't being updated after a Roster push update [teseo, jcbrand] * #496 Bugfix. Pings weren't being sent out. [teseo, jcbrand] +* #467 Fix outgoing chat messages not having a msgid when being put into sessionStorage [1st8] 0.9.5 (2015-08-24) ------------------ diff --git a/spec/chatbox.js b/spec/chatbox.js index d70b32465..d031fc0f2 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -779,7 +779,7 @@ var chatbox = converse.chatboxes.get(sender_jid); spyOn(converse.connection, 'send'); chatbox.set('otr_status', 1); // Set OTR status to UNVERIFIED, to mock an encrypted session - chatbox.trigger('sendMessage', msgtext); + chatbox.trigger('sendMessage', new converse.Message({ message: msgtext })); var $sent = $(converse.connection.send.argsForCall[0][0].tree()); expect($sent.find('body').siblings('private').length).toBe(1); expect($sent.find('private').length).toBe(1); diff --git a/src/templates/message.html b/src/templates/message.html index b36e6e5bf..d87f08c82 100644 --- a/src/templates/message.html +++ b/src/templates/message.html @@ -1,4 +1,4 @@ -
+
{{time}} {{username}}:  {{message}}