85 lines
2.5 KiB
TypeScript
85 lines
2.5 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import {Contacts } from "@capacitor-community/contacts";
|
|
import { Plugin} from "@capacitor/core";
|
|
//const { Contacts } = Plugins;
|
|
|
|
import {isPlatform, LoadingController} from "@ionic/angular";
|
|
import {SessionDataProviderService} from "./session-data-provider.service";
|
|
import {WrenchService} from "../services/wrench.service";
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class ContactsDataService {
|
|
|
|
constructor(public sessionDataProviderService:SessionDataProviderService,
|
|
private loadingCtrl: LoadingController,
|
|
private wrenchService: WrenchService) { }
|
|
|
|
|
|
async refeshContacts(){
|
|
|
|
if (isPlatform('android') || isPlatform('iphone') || isPlatform('ios')){
|
|
//return;
|
|
}
|
|
else{
|
|
return;
|
|
}
|
|
// phones: true,
|
|
Contacts.getContacts({projection: {
|
|
name: true,
|
|
emails: true
|
|
}}).then( result=>{
|
|
this.cacheContactsForAccount(result);
|
|
});
|
|
}
|
|
|
|
usrData: {
|
|
action:number,
|
|
member_id: number,
|
|
uid: string,
|
|
sessionid: string,
|
|
raw_contacts : string
|
|
mmode: number,
|
|
pcount: number
|
|
};
|
|
pPesult:any;
|
|
async cacheContactsForAccount(contactResult){
|
|
//alert('AAAA->001');
|
|
/* this.usrData = {action:22010,
|
|
member_id: this.sessionDataProviderService.member_id,
|
|
uid: this.sessionDataProviderService.member_uid,
|
|
sessionid: this.sessionDataProviderService.session ,
|
|
raw_contacts: JSON.stringify(contactResult.contacts),
|
|
|
|
}
|
|
*/
|
|
const loading = await this.loadingCtrl.create({
|
|
message: 'Refresing...',
|
|
duration: 7000,
|
|
});
|
|
const myString = JSON.stringify(contactResult.contacts);
|
|
// alert(myString.length);
|
|
// alert(myString);
|
|
await loading.present();
|
|
const chunkSize = 3000;
|
|
for(let ic=0; ic< myString.length; ic=ic+chunkSize){
|
|
this.usrData = {action:22010,
|
|
member_id: this.sessionDataProviderService.member_id,
|
|
uid: this.sessionDataProviderService.member_uid,
|
|
sessionid: this.sessionDataProviderService.session ,
|
|
raw_contacts: myString.substring(ic,ic+chunkSize),
|
|
mmode: ic,
|
|
pcount: myString.length
|
|
}
|
|
|
|
await this.wrenchService.processUsersContacts(this.usrData).subscribe(
|
|
pPesult => {
|
|
this.pPesult = pPesult;
|
|
console.log("pPesult RETURN->", this.pPesult);
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|