Cordova contacts plugin multiple promise never resolved


#1

I have a ionic 3 application where i use cordova-plugin-contacts.

What I have i a simple function that from a phone number return a name based on contacts:

public getContactNameNumber = function(number) {
    return this.contacts.find(['phoneNumbers'], {filter: number, multiple: false})
    .then(data => {
      console.log('resolved');
      if (data && data[0].displayName) {
        return {'name': data[0].displayName, 'number': number};
      }

      return {'name': number, 'number': number};
    })
    .catch(e => console.log('error', JSON.stringify(e)));
  }

Now i call my function multiple times (for every phone numbers i have):


const uniqueContacts = Promise.all(
        rows
        .map(item=>item.to)
        .filter(
          (item,index,all)=>all.indexOf(item)===index
        )
        .map(this.getContactNameNumber.bind(this))
      );
uniqueContacts.then(
        uniqueContacts =>
          console.log(
            "unique contacts length:",
            uniqueContacts.length,
            "first item:",
            JSON.stringify(uniqueContacts[0],undefined,2)
          ) ||
          uniqueContacts.reduce(
            (messages,contact)=>
              replaceToWithName(contact)
            ,this.messages
        )
      )
      .catch(e => console.log('my error', JSON.stringify(e)));

If I have only one phone number everything works fine but when i have two or more phone numbers i get that something doens’t work. First of all from my getContactNameNumber function I get only one console.log() while i expect to have it n times based on the numbers i have. So my uniqueContacts.then() never run.

Where i’m wrong?