2014-11-13 23:36:09 +01:00
|
|
|
/* vim: ts=4:sw=4:expandtab
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-09-01 02:58:36 +02:00
|
|
|
var Whisper = Whisper || {};
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
var MessageRecipientInputView = Backbone.View.extend({
|
|
|
|
events: {
|
|
|
|
'change': 'verifyNumber',
|
|
|
|
'focus' : 'removeError'
|
|
|
|
},
|
|
|
|
|
|
|
|
removeError: function() {
|
|
|
|
this.$el.removeClass('error');
|
|
|
|
},
|
|
|
|
|
2014-10-22 20:57:12 +02:00
|
|
|
verifyNumber: function() {
|
2014-09-01 02:58:36 +02:00
|
|
|
try {
|
2014-10-22 20:57:12 +02:00
|
|
|
var val = this.$el.val();
|
|
|
|
if (val[0] === '+') {
|
|
|
|
// assume that the country code is specified
|
|
|
|
var number = libphonenumber.util.verifyNumber(val);
|
|
|
|
} else {
|
|
|
|
// assume that the country code should match our own
|
|
|
|
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
|
|
|
|
var myRegionCode = libphonenumber.util.getRegionCodeForNumber(me);
|
|
|
|
var number = libphonenumber.util.verifyNumber(val, myRegionCode);
|
2014-09-01 02:58:36 +02:00
|
|
|
}
|
2014-10-22 20:57:12 +02:00
|
|
|
this.removeError();
|
2014-10-23 01:07:16 +02:00
|
|
|
return number;
|
2014-10-22 20:57:12 +02:00
|
|
|
} catch(ex) {
|
|
|
|
this.$el.addClass('error');
|
|
|
|
console.log(ex);
|
|
|
|
}
|
2014-09-01 02:58:36 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Whisper.NewConversationView = Backbone.View.extend({
|
|
|
|
className: 'conversation',
|
|
|
|
initialize: function() {
|
|
|
|
this.template = $('#new-message-form').html();
|
|
|
|
Mustache.parse(this.template);
|
|
|
|
this.render();
|
2014-10-23 01:07:16 +02:00
|
|
|
this.input = new MessageRecipientInputView({el: this.$el.find('input.number')});
|
2014-11-04 02:51:49 +01:00
|
|
|
this.fileInput = new Whisper.FileInputView({el: this.$el.find('.attachments')});
|
2014-09-01 02:58:36 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'submit .send': 'send',
|
|
|
|
'close': 'remove'
|
|
|
|
},
|
|
|
|
|
|
|
|
send: function(e) {
|
|
|
|
e.preventDefault();
|
2014-10-22 20:57:12 +02:00
|
|
|
var number = this.input.verifyNumber();
|
|
|
|
if (number) {
|
|
|
|
var thread = Whisper.Threads.findOrCreateForRecipient(number);
|
|
|
|
var message_input = this.$el.find('input.send-message');
|
2014-11-04 02:51:49 +01:00
|
|
|
var message = message_input.val();
|
|
|
|
if (message.length > 0 || this.fileInput.hasFiles()) {
|
|
|
|
this.fileInput.getFiles().then(function(attachments) {
|
|
|
|
thread.sendMessage(message, attachments);
|
|
|
|
});
|
|
|
|
message_input.val("");
|
|
|
|
}
|
2014-10-22 20:57:12 +02:00
|
|
|
this.remove();
|
|
|
|
thread.trigger('render');
|
|
|
|
}
|
2014-09-01 02:58:36 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
this.$el.html(Mustache.render(this.template));
|
|
|
|
Whisper.Layout.setContent(this.$el.show());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
})();
|