mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 934931 - 1/2: B2G MMS : use matchPhoneNumbers(...) to match the receiver to update the delivery status. r=gene
This commit is contained in:
parent
82ebfa8a8a
commit
7a7df9b560
@ -65,10 +65,17 @@ const COLLECT_TIMESTAMP_UNUSED = 0;
|
|||||||
XPCOMUtils.defineLazyServiceGetter(this, "gMobileMessageService",
|
XPCOMUtils.defineLazyServiceGetter(this, "gMobileMessageService",
|
||||||
"@mozilla.org/mobilemessage/mobilemessageservice;1",
|
"@mozilla.org/mobilemessage/mobilemessageservice;1",
|
||||||
"nsIMobileMessageService");
|
"nsIMobileMessageService");
|
||||||
|
|
||||||
XPCOMUtils.defineLazyServiceGetter(this, "gMMSService",
|
XPCOMUtils.defineLazyServiceGetter(this, "gMMSService",
|
||||||
"@mozilla.org/mms/rilmmsservice;1",
|
"@mozilla.org/mms/rilmmsservice;1",
|
||||||
"nsIMmsService");
|
"nsIMmsService");
|
||||||
|
|
||||||
|
XPCOMUtils.defineLazyGetter(this, "MMS", function () {
|
||||||
|
let MMS = {};
|
||||||
|
Cu.import("resource://gre/modules/MmsPduHelper.jsm", MMS);
|
||||||
|
return MMS;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MobileMessageDatabaseService
|
* MobileMessageDatabaseService
|
||||||
*/
|
*/
|
||||||
@ -1130,7 +1137,7 @@ MobileMessageDatabaseService.prototype = {
|
|||||||
cursor.update(threadRecord);
|
cursor.update(threadRecord);
|
||||||
|
|
||||||
cursor.continue();
|
cursor.continue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
messageStore.get(threadRecord.lastMessageId).onsuccess = function(event) {
|
messageStore.get(threadRecord.lastMessageId).onsuccess = function(event) {
|
||||||
@ -1577,6 +1584,46 @@ MobileMessageDatabaseService.prototype = {
|
|||||||
return aMessageRecord.id;
|
return aMessageRecord.id;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
forEachMatchedMmsDeliveryInfo:
|
||||||
|
function forEachMatchedMmsDeliveryInfo(aDeliveryInfo, aNeedle, aCallback) {
|
||||||
|
|
||||||
|
let typedAddress = MMS.Address.resolveType(aNeedle);
|
||||||
|
let normalizedAddress, parsedAddress;
|
||||||
|
if (typedAddress.type === "PLMN") {
|
||||||
|
normalizedAddress = PhoneNumberUtils.normalize(aNeedle, false);
|
||||||
|
parsedAddress = PhoneNumberUtils.parse(normalizedAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let element of aDeliveryInfo) {
|
||||||
|
let typedStoredAddress = MMS.Address.resolveType(element.receiver);
|
||||||
|
if (typedAddress.type !== typedStoredAddress.type) {
|
||||||
|
// Not even my type. Skip.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typedAddress.address == typedStoredAddress.address) {
|
||||||
|
// Have a direct match.
|
||||||
|
aCallback(element);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typedAddress.type !== "PLMN") {
|
||||||
|
// Address type other than "PLMN" must have direct match. Or, skip.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Both are of "PLMN" type.
|
||||||
|
let normalizedStoredAddress =
|
||||||
|
PhoneNumberUtils.normalize(element.receiver, false);
|
||||||
|
let parsedStoredAddress =
|
||||||
|
PhoneNumberUtils.parseWithMCC(normalizedStoredAddress, null);
|
||||||
|
if (this.matchPhoneNumbers(normalizedAddress, parsedAddress,
|
||||||
|
normalizedStoredAddress, parsedStoredAddress)) {
|
||||||
|
aCallback(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
updateMessageDeliveryById: function updateMessageDeliveryById(
|
updateMessageDeliveryById: function updateMessageDeliveryById(
|
||||||
id, type, receiver, delivery, deliveryStatus, envelopeId, callback) {
|
id, type, receiver, delivery, deliveryStatus, envelopeId, callback) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@ -1634,102 +1681,37 @@ MobileMessageDatabaseService.prototype = {
|
|||||||
isRecordUpdated = true;
|
isRecordUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update |messageRecord.deliveryStatus| if needed.
|
// Attempt to update |deliveryStatus| and |deliveryTimestamp| of:
|
||||||
|
// - the |messageRecord| for SMS.
|
||||||
|
// - the element(s) in |messageRecord.deliveryInfo| for MMS.
|
||||||
if (deliveryStatus) {
|
if (deliveryStatus) {
|
||||||
if (messageRecord.type == "sms") {
|
// A callback for updating the deliveyStatus/deliveryTimestamp of
|
||||||
if (messageRecord.deliveryStatus != deliveryStatus) {
|
// each target.
|
||||||
messageRecord.deliveryStatus = deliveryStatus;
|
let updateFunc = function(aTarget) {
|
||||||
|
if (aTarget.deliveryStatus == deliveryStatus) {
|
||||||
// Update |deliveryTimestamp| if it's successfully delivered.
|
return;
|
||||||
if (deliveryStatus == DELIVERY_STATUS_SUCCESS) {
|
|
||||||
messageRecord.deliveryTimestamp = Date.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
isRecordUpdated = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
aTarget.deliveryStatus = deliveryStatus;
|
||||||
|
|
||||||
|
// Update |deliveryTimestamp| if it's successfully delivered.
|
||||||
|
if (deliveryStatus == DELIVERY_STATUS_SUCCESS) {
|
||||||
|
aTarget.deliveryTimestamp = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
isRecordUpdated = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (messageRecord.type == "sms") {
|
||||||
|
updateFunc(messageRecord);
|
||||||
} else if (messageRecord.type == "mms") {
|
} else if (messageRecord.type == "mms") {
|
||||||
if (!receiver) {
|
if (!receiver) {
|
||||||
let deliveryInfo = messageRecord.deliveryInfo;
|
// If the receiver is specified, we only need to update the
|
||||||
for (let i = 0; i < deliveryInfo.length; i++) {
|
// element(s) in deliveryInfo that match the same receiver.
|
||||||
if (deliveryInfo[i].deliveryStatus != deliveryStatus) {
|
messageRecord.deliveryInfo.forEach(updateFunc);
|
||||||
deliveryInfo[i].deliveryStatus = deliveryStatus;
|
|
||||||
|
|
||||||
// Update |deliveryTimestamp| if it's successfully delivered.
|
|
||||||
if (deliveryStatus == DELIVERY_STATUS_SUCCESS) {
|
|
||||||
deliveryInfo[i].deliveryTimestamp = Date.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
isRecordUpdated = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let normReceiver = PhoneNumberUtils.normalize(receiver, false);
|
self.forEachMatchedMmsDeliveryInfo(messageRecord.deliveryInfo,
|
||||||
if (!normReceiver) {
|
receiver, updateFunc);
|
||||||
if (DEBUG) {
|
|
||||||
debug("Normalized receiver is not valid. Fail to update.");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let parsedReveiver = PhoneNumberUtils.parseWithMCC(normReceiver, null);
|
|
||||||
|
|
||||||
let found = false;
|
|
||||||
for (let i = 0; i < messageRecord.receivers.length; i++) {
|
|
||||||
let storedReceiver = messageRecord.receivers[i];
|
|
||||||
let normStoreReceiver =
|
|
||||||
PhoneNumberUtils.normalize(storedReceiver, false);
|
|
||||||
if (!normStoreReceiver) {
|
|
||||||
if (DEBUG) {
|
|
||||||
debug("Normalized stored receiver is not valid. Skipping.");
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let match = (normReceiver === normStoreReceiver);
|
|
||||||
if (!match) {
|
|
||||||
if (parsedReveiver) {
|
|
||||||
if (normStoreReceiver.endsWith(parsedReveiver.nationalNumber)) {
|
|
||||||
match = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let parsedStoreReceiver =
|
|
||||||
PhoneNumberUtils.parseWithMCC(normStoreReceiver, null);
|
|
||||||
if (parsedStoreReceiver &&
|
|
||||||
normReceiver.endsWith(parsedStoreReceiver.nationalNumber)) {
|
|
||||||
match = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!match) {
|
|
||||||
if (DEBUG) debug("Stored receiver is not matched. Skipping.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
found = true;
|
|
||||||
let deliveryInfo = messageRecord.deliveryInfo;
|
|
||||||
for (let j = 0; j < deliveryInfo.length; j++) {
|
|
||||||
if (deliveryInfo[j].receiver != storedReceiver) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (deliveryInfo[j].deliveryStatus != deliveryStatus) {
|
|
||||||
deliveryInfo[j].deliveryStatus = deliveryStatus;
|
|
||||||
|
|
||||||
// Update |deliveryTimestamp| if it's successfully delivered.
|
|
||||||
if (deliveryStatus == DELIVERY_STATUS_SUCCESS) {
|
|
||||||
deliveryInfo[j].deliveryTimestamp = Date.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
isRecordUpdated = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
if (DEBUG) {
|
|
||||||
debug("Cannot find the receiver. Fail to set delivery status.");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user