Permalink
Browse files

Bug 822055 - [SMS] Messages sent are duplicated in thread and throbbe…

…r is visible on each message r=borja

Remove the pending IndexedDB, refactored how we handle all the events, and
generally made the Sms app more consistent and responsive.

This fixes the duplicated message in thread.

Fixed some other bugs in the process :
- duplicated message when we were resending a failed message
- the received SMS was not displayed when I sent it to myself
- when I was sending the first SMS to a contact, and when I was hiding the Sms
  app (using the home button) and then going back to the Sms app, then the
  thread was empty. This happened only when the phone number was not normalized
  yet in the hash.
- now we try to send the SMS even if we don't have mozSettings
- fix notification was appearing when we were already in the good thread, when
  the num was not normalized yet
- now we store in gecko a SMS that the user tried to send when airplane mode was
  set.
  • Loading branch information...
julienw committed Dec 24, 2012
1 parent acfb004 commit fdc0b4fdea7b56b27b2918d4eed9acf8ed83cb96
Showing with 322 additions and 588 deletions.
  1. +0 −1 apps/sms/index.html
  2. +0 −106 apps/sms/js/pendingDBUtils.js
  3. +322 −481 apps/sms/js/sms.js
View
@@ -40,7 +40,6 @@
<!-- Specific code -->
<script type="text/javascript" src="js/blacklist.js"></script>
<script type="text/javascript" src="js/contacts.js"></script>
- <script type="text/javascript" src="js/pendingDBUtils.js"></script>
<script type="text/javascript" src="js/sms.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript" src="js/searchUtils.js"></script>
@@ -1,106 +0,0 @@
-'use strict';
-
-// Sending failed message management: Add a database for the pending message
-// which didn't send successfully.
-
-var PendingMsgManager = {
- db: null,
- dbReady: false,
- dbName: 'Pending_DB',
- dbVersion: 1,
- dbError: function pm_dbError(errorMsg) {
- console.log('Pending Message Database Error : ' + errorMsg);
- },
-
- init: function pm_init(callback) {
- try {
- var indexedDB = window.indexedDB || window.webkitIndexedDB ||
- window.mozIndexedDB || window.msIndexedDB;
- } catch (e) {
- this.dbError(e);
- return;
- }
-
- if (!indexedDB) {
- this.dbError('Indexed DB is not available!!!');
- return;
- }
-
- try {
- var msgCallback = callback;
- var msgManager = this;
- var request = indexedDB.open(this.dbName, this.dbVersion);
- request.onsuccess = function(event) {
- msgManager.db = event.target.result;
- msgManager.dbReady = true;
- if (msgCallback != undefined) {
- msgCallback();
- }
- };
-
- request.onerror = function(event) {
- msgManager.dbError('Database error: ' + event.target.errorCode);
- };
-
- request.onupgradeneeded = function(event) {
- var db = event.target.result;
- var objStore = db.createObjectStore('msgs', { keyPath: 'timestamp' });
- objStore.createIndex('receiver', 'receiver');
- };
- } catch (ex) {
- msgManager.dbError(ex.message);
- }
- },
-
- getMsgDB: function pm_getMsgDB(num, callback) {
- var store = this.db.transaction('msgs').objectStore('msgs');
- store = store.index('receiver'); // receiver number.
- var boundKeyRange = num ? IDBKeyRange.only(num) : null;
- var cursorRequest = store.openCursor(boundKeyRange, 'next');
- var msg = [];
- cursorRequest.onsuccess = function onsuccess() {
- var cursor = cursorRequest.result;
- if (!cursor) {
- callback(msg);
- return;
- }
- msg.push(cursor.value);
- cursor.continue();
- }
- cursorRequest.onerror = function onerror() {
- callback(null);
- }
- },
-
- saveToMsgDB: function pm_saveToMsgDB(msg, callback) {
- var transaction = this.db.transaction('msgs', 'readwrite');
- var store = transaction.objectStore('msgs');
- var addRequest = store.add(msg);
- var pendingMgr = this;
- addRequest.onsuccess = function onsuccess() {
- callback(addRequest.result);
- }
- addRequest.onerror = function onerror() {
- if (callback)
- callback(null);
- }
- },
-
- deleteFromMsgDB: function pm_deleteFromMsgDB(msg, callback) {
- var transaction = this.db.transaction('msgs', 'readwrite');
- var store = transaction.objectStore('msgs');
- var deleteRequest = store.delete(msg.timestamp);
- var pendingMgr = this;
- deleteRequest.onsuccess = function onsuccess() {
- if (callback) {
- callback(deleteRequest);
- }
-
- }
- deleteRequest.onerror = function onerror() {
- if (callback) {
- callback(null);
- }
- }
- }
-};
Oops, something went wrong.

0 comments on commit fdc0b4f

Please sign in to comment.