mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 737456 - Contacts API: Improve number lookup. r=bent
This commit is contained in:
parent
b2f0cd3a2f
commit
247be5ee97
@ -225,8 +225,29 @@ ContactDB.prototype = {
|
||||
// Add search fields
|
||||
if (aContact.properties[field] && contact.search[field]) {
|
||||
for (let i = 0; i <= aContact.properties[field].length; i++) {
|
||||
if (aContact.properties[field][i])
|
||||
contact.search[field].push(aContact.properties[field][i].toLowerCase());
|
||||
if (aContact.properties[field][i]) {
|
||||
if (field == "tel") {
|
||||
// Special case telephone number.
|
||||
// "+1-234-567" should also be found with 1234, 234-56, 23456
|
||||
|
||||
// Chop off the first characters
|
||||
let number = aContact.properties[field][i];
|
||||
for(let i = 0; i < number.length; i++) {
|
||||
contact.search[field].push(number.substring(i, number.length));
|
||||
}
|
||||
// Store +1-234-567 as ["1234567", "234567"...]
|
||||
let digits = number.match(/\d/g);
|
||||
if (digits && number.length != digits.length) {
|
||||
digits = digits.join('');
|
||||
for(let i = 0; i < digits.length; i++) {
|
||||
contact.search[field].push(digits.substring(i, digits.length));
|
||||
}
|
||||
}
|
||||
debug("lookup: " + JSON.stringify(contact.search[field]));
|
||||
} else {
|
||||
contact.search[field].push(aContact.properties[field][i].toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ var properties1 = {
|
||||
familyName: ["TestFamilyName","Wagner"],
|
||||
givenName: ["Test1","Test2"],
|
||||
nickname: "nicktest",
|
||||
tel: ["123456"],
|
||||
tel: ["123456", "+9-876-5432"],
|
||||
adr: adr1
|
||||
};
|
||||
|
||||
@ -226,6 +226,51 @@ var steps = [
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Retrieving by substring tel1");
|
||||
var options = {filterBy: ["tel"],
|
||||
filterOp: "contains",
|
||||
filterValue: properties1.tel[1].substring(1,5)};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
ok(req.result.length == 1, "Found exactly 1 contact.");
|
||||
findResult1 = req.result[0];
|
||||
ok(findResult1.id == sample_id1, "Same ID");
|
||||
checkContacts(createResult1, properties1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Retrieving by substring tel2");
|
||||
var options = {filterBy: ["tel"],
|
||||
filterOp: "contains",
|
||||
filterValue: "7654"};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
ok(req.result.length == 1, "Found exactly 1 contact.");
|
||||
findResult1 = req.result[0];
|
||||
ok(findResult1.id == sample_id1, "Same ID");
|
||||
checkContacts(createResult1, properties1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Retrieving by substring tel3");
|
||||
var options = {filterBy: ["tel"],
|
||||
filterOp: "contains",
|
||||
filterValue: "876-5432"};
|
||||
req = mozContacts.find(options);
|
||||
req.onsuccess = function () {
|
||||
ok(req.result.length == 1, "Found exactly 1 contact.");
|
||||
findResult1 = req.result[0];
|
||||
ok(findResult1.id == sample_id1, "Same ID");
|
||||
checkContacts(createResult1, properties1);
|
||||
next();
|
||||
};
|
||||
req.onerror = onFailure;
|
||||
},
|
||||
function () {
|
||||
ok(true, "Retrieving by substring2");
|
||||
var options = {filterBy: ["givenName"],
|
||||
|
Loading…
Reference in New Issue
Block a user