Permalink
Browse files

Merge pull request #6853 from ochameau/sms2

Bug 815236 - SMS sent multiple times
  • Loading branch information...
2 parents e8b40b2 + 3d63e91 commit e852c4c1b8cf6f08a9599e1673d2fe6afbd57e6d @vingtetun vingtetun committed Dec 6, 2012
Showing with 32 additions and 7 deletions.
  1. +2 −6 apps/sms/js/pendingDBUtils.js
  2. +30 −1 apps/sms/js/sms.js
@@ -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);
}
},
@@ -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);
}
}
};
View
@@ -953,6 +953,9 @@ var ThreadUI = {
this.selectedInputList = [];
this.pageHeader.innerHTML = _('editMode');
this.checkInputs();
+
+ // Unlock sendMessage function.
+ ThreadUI.sendingMessage = false;
},
clearContact: function thui_clearContact() {
@@ -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'),
@@ -1145,6 +1157,8 @@ var ThreadUI = {
);
};
+ var sent = false;
+
if (settings) {
var req = settings.createLock().get('ril.radio.disabled');
@@ -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'
@@ -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 {
@@ -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
@@ -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 {
@@ -1260,6 +1287,8 @@ var ThreadUI = {
MessageManager.getMessages(ThreadListUI.renderThreads);
});
}
+ } else {
+ unlock();
}
}).bind(this));

0 comments on commit e852c4c

Please sign in to comment.