Refactored sendMessage
Let the message only be sent when an event has been triggered. This allows us to first (if necessary) let OTR process the image.
This commit is contained in:
parent
a2aeec8449
commit
cf4cec1e29
67
converse.js
67
converse.js
@ -227,17 +227,17 @@
|
|||||||
priv: myKey,
|
priv: myKey,
|
||||||
debug: true
|
debug: true
|
||||||
};
|
};
|
||||||
var contact = new otr.OTR(options);
|
this.otr = new otr.OTR(options);
|
||||||
|
this.otr.on('ui', $.proxy(function (msg) {
|
||||||
contact.on('ui', function (msg) {
|
|
||||||
console.log("message to display to the user:"+msg);
|
console.log("message to display to the user:"+msg);
|
||||||
});
|
}, this));
|
||||||
contact.on('io', function (msg) {
|
this.otr.on('io', $.proxy(function (msg) {
|
||||||
console.log("message to display to the user:"+msg);
|
console.log("message to display to the user:"+msg);
|
||||||
});
|
this.trigger('sendMessage', msg);
|
||||||
contact.on('error', function (msg) {
|
}, this));
|
||||||
|
this.otr.on('error', $.proxy(function (msg) {
|
||||||
console.log("message to display to the user:"+msg);
|
console.log("message to display to the user:"+msg);
|
||||||
});
|
}, this));
|
||||||
},
|
},
|
||||||
|
|
||||||
messageReceived: function (message) {
|
messageReceived: function (message) {
|
||||||
@ -308,6 +308,20 @@
|
|||||||
'<time class="chat-date" datetime="{{isodate}}">{{datestring}}</time>'
|
'<time class="chat-date" datetime="{{isodate}}">{{datestring}}</time>'
|
||||||
),
|
),
|
||||||
|
|
||||||
|
initialize: function (){
|
||||||
|
this.model.messages.on('add', this.showMessage, this);
|
||||||
|
this.model.on('show', this.show, this);
|
||||||
|
this.model.on('destroy', this.hide, this);
|
||||||
|
this.model.on('change', this.onChange, this);
|
||||||
|
this.model.on('sendMessage', this.onMessageSend, this);
|
||||||
|
this.updateVCard();
|
||||||
|
this.$el.appendTo(converse.chatboxesview.$el);
|
||||||
|
this.render().show().model.messages.fetch({add: true});
|
||||||
|
if (this.model.get('status')) {
|
||||||
|
this.showStatusMessage(this.model.get('status'));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
appendMessage: function ($el, msg_dict) {
|
appendMessage: function ($el, msg_dict) {
|
||||||
var this_date = converse.parseISO8601(msg_dict.time),
|
var this_date = converse.parseISO8601(msg_dict.time),
|
||||||
text = msg_dict.message,
|
text = msg_dict.message,
|
||||||
@ -393,14 +407,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
sendMessage: function (text) {
|
sendMessage: function (text) {
|
||||||
// TODO: Look in ChatPartners to see what resources we have for the recipient.
|
var match = text.replace(/^\s*/, "").match(/^\/(.*)\s*$/), msgs;
|
||||||
// if we have one resource, we sent to only that resources, if we have multiple
|
|
||||||
// we send to the bare jid.
|
|
||||||
var timestamp = (new Date()).getTime(),
|
|
||||||
bare_jid = this.model.get('jid'),
|
|
||||||
match = text.replace(/^\s*/, "").match(/^\/(.*)\s*$/),
|
|
||||||
msgs;
|
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
if (match[1] === "clear") {
|
if (match[1] === "clear") {
|
||||||
this.$el.find('.chat-content').empty();
|
this.$el.find('.chat-content').empty();
|
||||||
@ -432,6 +439,20 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.model.otr) {
|
||||||
|
this.model.otr.sendMsg(text);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.model.trigger('sendMessage', text);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onMessageSend: function (text) {
|
||||||
|
// TODO: Look in ChatPartners to see what resources we have for the recipient.
|
||||||
|
// if we have one resource, we sent to only that resources, if we have multiple
|
||||||
|
// we send to the bare jid.
|
||||||
|
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})
|
var message = $msg({from: converse.connection.jid, to: bare_jid, type: 'chat', id: timestamp})
|
||||||
.c('body').t(text).up()
|
.c('body').t(text).up()
|
||||||
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'});
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'});
|
||||||
@ -441,6 +462,7 @@
|
|||||||
.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(message.tree());
|
||||||
|
|
||||||
converse.connection.send(message);
|
converse.connection.send(message);
|
||||||
converse.connection.send(forwarded);
|
converse.connection.send(forwarded);
|
||||||
// Add the new message
|
// Add the new message
|
||||||
@ -540,19 +562,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function (){
|
|
||||||
this.model.messages.on('add', this.showMessage, this);
|
|
||||||
this.model.on('show', this.show, this);
|
|
||||||
this.model.on('destroy', this.hide, this);
|
|
||||||
this.model.on('change', this.onChange, this);
|
|
||||||
this.updateVCard();
|
|
||||||
this.$el.appendTo(converse.chatboxesview.$el);
|
|
||||||
this.render().show().model.messages.fetch({add: true});
|
|
||||||
if (this.model.get('status')) {
|
|
||||||
this.showStatusMessage(this.model.get('status'));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
template: _.template(
|
template: _.template(
|
||||||
'<div class="chat-head chat-head-chatbox">' +
|
'<div class="chat-head chat-head-chatbox">' +
|
||||||
'<a class="close-chatbox-button">X</a>' +
|
'<a class="close-chatbox-button">X</a>' +
|
||||||
|
Loading…
Reference in New Issue
Block a user