Bug 927711 - B2G MMS : Handle message delivered timestamp for delivery report (part 2, implementation). r=ctai

This commit is contained in:
Gene Lian 2013-11-05 19:02:33 +08:00
parent 60b46de155
commit cdca045916
4 changed files with 75 additions and 15 deletions

View File

@ -15,6 +15,7 @@
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
#include "mozilla/dom/mobilemessage/SmsTypes.h"
#include "nsDOMFile.h"
#include "nsCxPusher.h"
using namespace mozilla::idl;
using namespace mozilla::dom::mobilemessage;
@ -100,8 +101,11 @@ MmsMessage::MmsMessage(const mobilemessage::MmsMessageData& aData)
for (uint32_t i = 0; i < len; i++) {
MmsDeliveryInfo info;
const MmsDeliveryInfoData &infoData = aData.deliveryInfo()[i];
// Prepare |info.receiver|.
info.receiver = infoData.receiver();
// Prepare |info.deliveryStatus|.
nsString statusStr;
switch (infoData.deliveryStatus()) {
case eDeliveryStatus_NotApplicable:
@ -127,6 +131,20 @@ MmsMessage::MmsMessage(const mobilemessage::MmsMessageData& aData)
MOZ_CRASH("We shouldn't get any other delivery status!");
}
info.deliveryStatus = statusStr;
// Prepare |info.deliveryTimestamp|.
info.deliveryTimestamp = JSVAL_NULL;
if (infoData.deliveryTimestamp() != 0) {
AutoJSContext cx;
JS::Rooted<JSObject*>
dateObj(cx, JS_NewDateObjectMsec(cx, infoData.deliveryTimestamp()));
if (!dateObj) {
NS_WARNING("MmsMessage: Unable to create Date for deliveryTimestamp.");
} else {
info.deliveryTimestamp = OBJECT_TO_JSVAL(dateObj);
}
}
mDeliveryInfo.AppendElement(info);
}
}
@ -327,8 +345,11 @@ MmsMessage::GetData(ContentParent* aParent,
for (uint32_t i = 0; i < mDeliveryInfo.Length(); i++) {
MmsDeliveryInfoData infoData;
const MmsDeliveryInfo &info = mDeliveryInfo[i];
// Prepare |infoData.receiver|.
infoData.receiver().Assign(info.receiver);
// Prepare |infoData.deliveryStatus|.
DeliveryStatus status;
if (info.deliveryStatus.Equals(DELIVERY_STATUS_NOT_APPLICABLE)) {
status = eDeliveryStatus_NotApplicable;
@ -346,6 +367,15 @@ MmsMessage::GetData(ContentParent* aParent,
return false;
}
infoData.deliveryStatus() = status;
// Prepare |infoData.deliveryTimestamp|.
if (info.deliveryTimestamp == JSVAL_NULL) {
infoData.deliveryTimestamp() = 0;
} else {
AutoJSContext cx;
convertTimeToInt(cx, info.deliveryTimestamp, infoData.deliveryTimestamp());
}
aData.deliveryInfo().AppendElement(infoData);
}
@ -484,6 +514,13 @@ MmsMessage::GetDeliveryInfo(JSContext* aCx, JS::Value* aDeliveryInfo)
return NS_ERROR_FAILURE;
}
// Get |info.deliveryTimestamp|.
if (!JS_DefineProperty(aCx, infoJsObj,
"deliveryTimestamp", info.deliveryTimestamp,
NULL, NULL, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
tmpJsVal = OBJECT_TO_JSVAL(infoJsObj);
if (!JS_SetElement(aCx, deliveryInfo, i, &tmpJsVal)) {
return NS_ERROR_FAILURE;

View File

@ -1544,19 +1544,19 @@ MmsService.prototype = {
// because the system message mechamism will rewrap the object
// based on the content window, which needs to know the properties.
gSystemMessenger.broadcastMessage(aName, {
type: aDomMessage.type,
id: aDomMessage.id,
threadId: aDomMessage.threadId,
delivery: aDomMessage.delivery,
deliveryInfo: aDomMessage.deliveryInfo,
sender: aDomMessage.sender,
receivers: aDomMessage.receivers,
timestamp: aDomMessage.timestamp,
read: aDomMessage.read,
subject: aDomMessage.subject,
smil: aDomMessage.smil,
attachments: aDomMessage.attachments,
expiryDate: aDomMessage.expiryDate
type: aDomMessage.type,
id: aDomMessage.id,
threadId: aDomMessage.threadId,
delivery: aDomMessage.delivery,
deliveryInfo: aDomMessage.deliveryInfo,
sender: aDomMessage.sender,
receivers: aDomMessage.receivers,
timestamp: aDomMessage.timestamp,
read: aDomMessage.read,
subject: aDomMessage.subject,
smil: aDomMessage.smil,
attachments: aDomMessage.attachments,
expiryDate: aDomMessage.expiryDate
});
},

View File

@ -1588,7 +1588,7 @@ MobileMessageDatabaseService.prototype = {
if (messageRecord.deliveryStatus != deliveryStatus) {
messageRecord.deliveryStatus = deliveryStatus;
// Update the delivery timestamp if it's successfully delivered.
// Update |deliveryTimestamp| if it's successfully delivered.
if (deliveryStatus == DELIVERY_STATUS_SUCCESS) {
messageRecord.deliveryTimestamp = Date.now();
}
@ -1601,6 +1601,12 @@ MobileMessageDatabaseService.prototype = {
for (let i = 0; i < deliveryInfo.length; i++) {
if (deliveryInfo[i].deliveryStatus != deliveryStatus) {
deliveryInfo[i].deliveryStatus = deliveryStatus;
// Update |deliveryTimestamp| if it's successfully delivered.
if (deliveryStatus == DELIVERY_STATUS_SUCCESS) {
deliveryInfo[i].deliveryTimestamp = Date.now();
}
isRecordUpdated = true;
}
}
@ -1655,6 +1661,12 @@ MobileMessageDatabaseService.prototype = {
}
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;
}
}
@ -1765,6 +1777,14 @@ MobileMessageDatabaseService.prototype = {
if (aMessage.type == "mms") {
aMessage.transactionIdIndex = aMessage.transactionId;
aMessage.isReadReportSent = false;
// If |deliveryTimestamp| is not specified, use 0 as default.
let deliveryInfo = aMessage.deliveryInfo;
for (let i = 0; i < deliveryInfo.length; i++) {
if (deliveryInfo[i].deliveryTimestamp == undefined) {
deliveryInfo[i].deliveryTimestamp = 0;
}
}
}
if (aMessage.type == "sms") {
@ -1818,7 +1838,9 @@ MobileMessageDatabaseService.prototype = {
aMessage.deliveryInfo = [];
for (let i = 0; i < receivers.length; i++) {
aMessage.deliveryInfo.push({
receiver: receivers[i], deliveryStatus: deliveryStatus });
receiver: receivers[i],
deliveryStatus: deliveryStatus,
deliveryTimestamp: 0 });
}
}

View File

@ -50,6 +50,7 @@ struct MmsDeliveryInfoData
{
nsString receiver;
DeliveryStatus deliveryStatus;
uint64_t deliveryTimestamp;
};
struct MmsMessageData