Skip to content

Commit

Permalink
Bug 815236 - SMS sent multiple times r=borjasalguero
Browse files Browse the repository at this point in the history
  • Loading branch information
ochameau committed Dec 6, 2012
1 parent 7baaf75 commit 3d63e91
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
8 changes: 2 additions & 6 deletions apps/sms/js/pendingDBUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ var PendingMsgManager = {
callback(addRequest.result);
}
addRequest.onerror = function onerror() {
// Execute save operation again if failed.
window.setTimeout(
pendingMgr.saveToMsgDB(msg, callback).bind(pendingMgr), 500);
if (callback)
callback(null);
}
},

Expand All @@ -102,9 +101,6 @@ var PendingMsgManager = {
if (callback) {
callback(null);
}
// Execute save operation again if failed.
window.setTimeout(
pendingMgr.deleteFromMsgDB(msg, callback).bind(pendingMgr), 500);
}
}
};
31 changes: 30 additions & 1 deletion apps/sms/js/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,9 @@ var ThreadUI = {
this.selectedInputList = [];
this.pageHeader.innerHTML = _('editMode');
this.checkInputs();

// Unlock sendMessage function.
ThreadUI.sendingMessage = false;
},

clearContact: function thui_clearContact() {
Expand Down Expand Up @@ -1132,7 +1135,16 @@ var ThreadUI = {
var settings = window.navigator.mozSettings,
throwGeneralError;

// Lock sendMessage in order to ensure sending the message only once
if (this.sendingMessage)
return;
this.sendingMessage = true;
function unlock() {
ThreadUI.sendingMessage = false;
}

throwGeneralError = function() {
unlock();
CustomDialog.show(
_('sendGeneralErrorTitle'),
_('sendGeneralErrorBody'),
Expand All @@ -1145,6 +1157,8 @@ var ThreadUI = {
);
};

var sent = false;

if (settings) {

var req = settings.createLock().get('ril.radio.disabled');
Expand All @@ -1162,7 +1176,11 @@ var ThreadUI = {
var numNormalized =
PhoneNumberManager.getNormalizedInternationalNumber(num);
// Retrieve text
var text = this.input.value || resendText;
var text = this.input.value;
// Ensure that resendText isn't a MouseEvent
if (typeof(resendText) == 'string')
text = resendText;

// If we have something to send
if (numNormalized != '' && text != '') {
// Create 'PendingMessage'
Expand All @@ -1181,6 +1199,7 @@ var ThreadUI = {
// Save the message into pendind DB before send.
PendingMsgManager.saveToMsgDB(message, function onsave(msg) {
ThreadUI.cleanFields();
unlock();
if (window.location.hash == '#new') {
window.location.hash = '#num=' + num;
} else {
Expand All @@ -1192,6 +1211,13 @@ var ThreadUI = {
});
}
MessageManager.getMessages(ThreadListUI.renderThreads);

// Safety check in order to ensure that we try to send the
// message only once
if (sent)
return;
sent = true;

// XXX Once we have PhoneNumberJS in Gecko we will
// use num directly:
// https://bugzilla.mozilla.org/show_bug.cgi?id=809213
Expand Down Expand Up @@ -1238,6 +1264,7 @@ var ThreadUI = {
// Save the message into pendind DB before send.
PendingMsgManager.saveToMsgDB(message, function onsave(msg) {
ThreadUI.cleanFields();
unlock();
if (window.location.hash == '#new') {
window.location.hash = '#num=' + num;
} else {
Expand All @@ -1260,6 +1287,8 @@ var ThreadUI = {
MessageManager.getMessages(ThreadListUI.renderThreads);
});
}
} else {
unlock();
}
}).bind(this));

Expand Down

0 comments on commit 3d63e91

Please sign in to comment.