B2G/gaia/apps/communications/dialer/js/call_log_db.js
// Populate quick group view with already existing calls information.
Populate quick group view with already existing calls information.
Populate quick group view with already existing calls information .
function populateGroups() {
      var percent = parseInt(recentsCount * 0.15);
      var countToProgressEvent = percent;
      var percent2 = parseInt(recentsCount * 0.25);
      var countToProgressEvent2 = percent2;
      var progress = 0;
      recentsStore.openCursor().onsuccess = function onsuccess(event) {
        if (countToProgressEvent === 0) {
          countToProgressEvent = percent;
          progress += 10;
          self._notifyObservers('upgradeprogress', progress);
        } else {
          countToProgressEvent--;
        }
        var cursor = event.target.result;
        if (!cursor) {
          cursorDone = true;
          onGroupsDone();
          return;
        }
        var record = cursor.value;
        var type = '';
        var status;
        switch (record.type) {
          case 'incoming-connected':
            type = 'incoming';
            status = 'connected';
            break;
          case 'incoming-refused':
            type = 'incoming';
            break;
          default:
            if (record.type && record.type.indexOf('dialing') != -1) {
              type = 'dialing';
            }
            break;
        }
        var id = self._getGroupId({
          date: record.date,
          number: record.number,
          type: type,
          status: status
        });
        var date = new Date(record.date);
        var key = date.getDay() + date.getMonth() + date.getFullYear() +
                  record.number + type;
        if (status) {
          key += status;
        }
        waitForAsyncCall++;
        Contacts.findByNumber(record.number,
                              function(contact, matchingTel) {
          if (countToProgressEvent2 === 0) {
            countToProgressEvent2 = percent2;
            progress += 10;
            self._notifyObservers('upgradeprogress', progress);
          } else {
            countToProgressEvent2--;
          }
          if (key in groups) {
            if (groups[key].lastEntryDate <= record.date) {
              groups[key].lastEntryDate = record.date;
            }
            groups[key].retryCount++;
          } else {
            var group = {
              id: id,
              number: record.number,
              lastEntryDate: record.date,
              retryCount: 1
            };
            if (contact && contact !== null) {
              group.contactId = contact.id;
              if (Array.isArray(contact.photo) && contact.photo[0]) {
                group.contactPhoto = contact.photo[0];
              }
              if (matchingTel) {
                var primaryInfo = Utils.getPhoneNumberPrimaryInfo(matchingTel,
                                                                  contact);
                if (Array.isArray(primaryInfo)) {
                  primaryInfo = primaryInfo[0];
                }
                group.contactPrimaryInfo = String(primaryInfo);
                if (Array.isArray(matchingTel.type) && matchingTel.type[0]) {
                  group.contactMatchingTelType = String(matchingTel.type[0]);
                }
                if (matchingTel.carrier) {
                  group.contactMatchingTelCarrier = String(matchingTel.carrier);
                }
              }
            }
            groups[key] = group;
            groupCount++;
          }
          waitForAsyncCall--;
          onGroupsDone();
        });
        cursor.continue();
      };
    }
function populateGroups ( ) { var percent = parseInt ( recentsCount * 0.15 ) ; var countToProgressEvent = percent ; var percent2 = parseInt ( recentsCount * 0.25 ) ; var countToProgressEvent2 = percent2 ; var progress = 0 ; recentsStore . openCursor ( ) . onsuccess = function onsuccess ( event ) { if ( countToProgressEvent === 0 ) { countToProgressEvent = percent ; progress += 10 ; self . _notifyObservers ( 'upgradeprogress' , progress ) ; } else { countToProgressEvent -- ; } var cursor = event . target . result ; if ( ! cursor ) { cursorDone = true ; onGroupsDone ( ) ; return ; } var record = cursor . value ; var type = '' ; var status ; switch ( record . type ) { case 'incoming-connected' : type = 'incoming' ; status = 'connected' ; break ; case 'incoming-refused' : type = 'incoming' ; break ; default : if ( record . type && record . type . indexOf ( 'dialing' ) != - 1 ) { type = 'dialing' ; } break ; } var id = self . _getGroupId ( { date : record . date , number : record . number , type : type , status : status } ) ; var date = new Date ( record . date ) ; var key = date . getDay ( ) + date . getMonth ( ) + date . getFullYear ( ) + record . number + type ; if ( status ) { key += status ; } waitForAsyncCall ++ ; Contacts . findByNumber ( record . number , function ( contact , matchingTel ) { if ( countToProgressEvent2 === 0 ) { countToProgressEvent2 = percent2 ; progress += 10 ; self . _notifyObservers ( 'upgradeprogress' , progress ) ; } else { countToProgressEvent2 -- ; } if ( key in groups ) { if ( groups [ key ] . lastEntryDate <= record . date ) { groups [ key ] . lastEntryDate = record . date ; } groups [ key ] . retryCount ++ ; } else { var group = { id : id , number : record . number , lastEntryDate : record . date , retryCount : 1 } ; if ( contact && contact !== null ) { group . contactId = contact . id ; if ( Array . isArray ( contact . photo ) && contact . photo [ 0 ] ) { group . contactPhoto = contact . photo [ 0 ] ; } if ( matchingTel ) { var primaryInfo = Utils . getPhoneNumberPrimaryInfo ( matchingTel , contact ) ; if ( Array . isArray ( primaryInfo ) ) { primaryInfo = primaryInfo [ 0 ] ; } group . contactPrimaryInfo = String ( primaryInfo ) ; if ( Array . isArray ( matchingTel . type ) && matchingTel . type [ 0 ] ) { group . contactMatchingTelType = String ( matchingTel . type [ 0 ] ) ; } if ( matchingTel . carrier ) { group . contactMatchingTelCarrier = String ( matchingTel . carrier ) ; } } } groups [ key ] = group ; groupCount ++ ; } waitForAsyncCall -- ; onGroupsDone ( ) ; } ) ; cursor . continue ( ) ; } ; }
Populate quick group view with already existing calls information.
Populate quick group view with already existing calls information .
// We send 'upgradeprogress' events from two different places: // 1- For each 15% of the recentsStore cursor requests completed. //    We increment the progress by 10%, leaving the total amount //    in 60%. // 2- For each 25% of the Contacts API requests completed. We //    also increment the progress by 10%, leaving the total //    amount in 90%. // The final progress 100% event is avoided as we send a 'upgradedone' // event instead. // As soon as the cursor is done, we bail out. We still need to wait // for all the async calls to retrieve the contacts information to // finish before pushing the data to the groups object store. We will // notify the UI about that so it can request the data again. // Get group type and status. // Create the id and a temporary unique key for the group. // Get the contact information associated with the number. // Store the group or increment the 'retryCount' field if we already // created a group for this call. // Groups should have the date of the newest call.