Commit e2001896 authored by Christoph's avatar Christoph

Fix outgoing chat messages not having a msgid when being put into sessionStorage, fixes #467

parent 57a30917
...@@ -932,7 +932,14 @@ ...@@ -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({ this.Messages = Backbone.Collection.extend({
model: converse.Message, model: converse.Message,
comparator: 'time' comparator: 'time'
...@@ -1087,7 +1094,7 @@ ...@@ -1087,7 +1094,7 @@
this.trigger('showReceivedOTRMessage', msg); this.trigger('showReceivedOTRMessage', msg);
}.bind(this)); }.bind(this));
this.otr.on('io', function (msg) { this.otr.on('io', function (msg) {
this.trigger('sendMessage', msg); this.trigger('sendMessage', new converse.Message({ message: msg }));
}.bind(this)); }.bind(this));
this.otr.on('error', function (msg) { this.otr.on('error', function (msg) {
this.trigger('showOTRError', msg); this.trigger('showOTRError', msg);
...@@ -1498,6 +1505,7 @@ ...@@ -1498,6 +1505,7 @@
extra_classes += ' mentioned'; extra_classes += ' mentioned';
} }
return $(template({ return $(template({
msgid: attrs.msgid,
'sender': attrs.sender, 'sender': attrs.sender,
'time': msg_time.format('hh:mm'), 'time': msg_time.format('hh:mm'),
'isodate': msg_time.format(), 'isodate': msg_time.format(),
...@@ -1553,30 +1561,29 @@ ...@@ -1553,30 +1561,29 @@
} }
}, },
sendMessage: function (text) { sendMessage: function (message) {
/* Responsible for sending off a text message. /* Responsible for sending off a text message.
* *
* Parameters: * 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. // 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 bare_jid = this.model.get('jid');
var message = $msg({from: converse.connection.jid, to: bare_jid, type: 'chat', id: timestamp}) var messageStanza = $msg({from: converse.connection.jid, to: bare_jid, type: 'chat', id: message.get('msgid')})
.c('body').t(text).up() .c('body').t(message.get('message')).up()
.c(ACTIVE, {'xmlns': Strophe.NS.CHATSTATES}).up(); .c(ACTIVE, {'xmlns': Strophe.NS.CHATSTATES}).up();
if (this.model.get('otr_status') != UNENCRYPTED) { if (this.model.get('otr_status') != UNENCRYPTED) {
// OTR messages aren't carbon copied // 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) { if (converse.forward_messages) {
// Forward the message, so that other connected resources are also aware of it. // 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('forwarded', {xmlns:'urn:xmpp:forward:0'})
.c('delay', {xmns:'urn:xmpp:delay',stamp:timestamp}).up() .c('delay', {xmns:'urn:xmpp:delay',stamp:timestamp}).up()
.cnode(message.tree()); .cnode(messageStanza.tree());
converse.connection.send(forwarded); converse.connection.send(forwarded);
} }
}, },
...@@ -1618,13 +1625,13 @@ ...@@ -1618,13 +1625,13 @@
// We only save unencrypted messages. // We only save unencrypted messages.
var fullname = converse.xmppstatus.get('fullname'); var fullname = converse.xmppstatus.get('fullname');
fullname = _.isEmpty(fullname)? converse.bare_jid: fullname; fullname = _.isEmpty(fullname)? converse.bare_jid: fullname;
this.model.messages.create({ var message = this.model.messages.create({
fullname: fullname, fullname: fullname,
sender: 'me', sender: 'me',
time: moment().format(), time: moment().format(),
message: text message: text
}); });
this.sendMessage(text); this.sendMessage(message);
} }
}, },
......
...@@ -8,6 +8,7 @@ Changelog ...@@ -8,6 +8,7 @@ Changelog
* #468 Fix [object Object] being sometimes shown as status [1st8] * #468 Fix [object Object] being sometimes shown as status [1st8]
* #493 Roster wasn't being updated after a Roster push update [teseo, jcbrand] * #493 Roster wasn't being updated after a Roster push update [teseo, jcbrand]
* #496 Bugfix. Pings weren't being sent out. [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) 0.9.5 (2015-08-24)
------------------ ------------------
......
...@@ -779,7 +779,7 @@ ...@@ -779,7 +779,7 @@
var chatbox = converse.chatboxes.get(sender_jid); var chatbox = converse.chatboxes.get(sender_jid);
spyOn(converse.connection, 'send'); spyOn(converse.connection, 'send');
chatbox.set('otr_status', 1); // Set OTR status to UNVERIFIED, to mock an encrypted session 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()); var $sent = $(converse.connection.send.argsForCall[0][0].tree());
expect($sent.find('body').siblings('private').length).toBe(1); expect($sent.find('body').siblings('private').length).toBe(1);
expect($sent.find('private').length).toBe(1); expect($sent.find('private').length).toBe(1);
......
<div class="chat-message {{extra_classes}}" data-isodate="{{isodate}}"> <div class="chat-message {{extra_classes}}" data-isodate="{{isodate}}" data-msgid="{{msgid}}">
<span class="chat-message-{{sender}}">{{time}} {{username}}:&nbsp;</span> <span class="chat-message-{{sender}}">{{time}} {{username}}:&nbsp;</span>
<span class="chat-message-content">{{message}}</span> <span class="chat-message-content">{{message}}</span>
</div> </div>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment