-
Notifications
You must be signed in to change notification settings - Fork 32
/
get-all-contacts-worker.android.js
34 lines (31 loc) · 1.21 KB
/
get-all-contacts-worker.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require('globals'); // necessary to bootstrap tns modules on the new thread
var Contact = require("./contact-model");
var helper = require("./contact-helper");
/* pass debug messages to main thread since web workers do not have console access */
function console_log(msg) { postMessage({ type: 'debug', message: msg }); }
function console_dump(msg) { postMessage({ type: 'dump', message: msg }); }
self.onmessage = function (event) {
try {
var c = helper.getContext().getContentResolver().query(android.provider.ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if(c.getCount() > 0){
var cts = [];
while(c.moveToNext()){
try {
var contactModel = new Contact();
contactModel.initializeFromNative(c,event.data.contactFields);
cts.push(contactModel);
} catch(e) {
console_log("Error processing contact");
}
}
c.close();
postMessage({ type: 'result', message: { data: cts, response: "fetch" }});
} else {
c.close();
postMessage({ type: 'result', message: { data: null, response: "fetch" }})
}
} catch (e) {
// console.log('error', e)
postMessage({ type: 'result', message: e });
}
}