Bug 847738 - B2G MMS: provide nsIDOMMobileMessageManager.getMessage(). r=vicamo sr=sicking a=leo+

This commit is contained in:
Gene Lian 2013-03-08 11:46:16 +08:00
parent 10c5a08bbb
commit dcf1f7e4a0
14 changed files with 278 additions and 191 deletions

View File

@ -919,7 +919,7 @@ MmsService.prototype = {
* @param intermediate
* Intermediate MMS message parsed from PDU.
*/
convertFromIntermediateToSavable: function convertFromIntermediateToSavable(intermediate) {
convertIntermediateToSavable: function convertIntermediateToSavable(intermediate) {
intermediate.type = "mms";
intermediate.delivery = DELIVERY_NOT_DOWNLOADED;
intermediate.timestamp = Date.now();
@ -934,47 +934,49 @@ MmsService.prototype = {
},
/**
* Convert intermediate message to indexedDB savable object.
* Merge the retrieval confirmation into the savable message.
*
* @param intermediate
* Intermediate MMS message parsed from PDU.
* @param record
* Record stored in the database.
* Intermediate MMS message parsed from PDU, which carries
the retrieval confirmation.
* @param savable
* The indexedDB savable MMS message, which is going to be
* merged with the extra retrieval confirmation.
*/
mergeRetrievalConfirmationIntoRecord: function mergeRetrievalConfirmationIntoRecord(intermediate, record) {
mergeRetrievalConfirmation: function mergeRetrievalConfirmation(intermediate, savable) {
if (intermediate.headers["Date"]) {
record.timestamp = Date.parse(intermediate.headers["Date"]);
savable.timestamp = Date.parse(intermediate.headers["Date"]);
}
if (intermediate.headers.from) {
record.sender = intermediate.headers.from.address;
savable.sender = intermediate.headers.from.address;
} else {
record.sender = "anonymous";
savable.sender = "anonymous";
}
record.receivers = [];
savable.receivers = [];
// We don't have Bcc in recevied MMS message.
for each (let type in ["cc", "to"]) {
if (intermediate.headers[type]) {
if (intermediate.headers[type] instanceof Array) {
for (let index in intermediate.headers[type]) {
record.receivers.push(intermediate.headers[type][index].address)
savable.receivers.push(intermediate.headers[type][index].address)
}
} else {
record.receivers.push(intermediate.headers[type].address);
savable.receivers.push(intermediate.headers[type].address);
}
}
}
record.delivery = DELIVERY_RECEIVED;
savable.delivery = DELIVERY_RECEIVED;
for (let field in intermediate.headers) {
record.headers[field] = intermediate.headers[field];
savable.headers[field] = intermediate.headers[field];
}
if (intermediate.parts) {
record.parts = intermediate.parts;
savable.parts = intermediate.parts;
}
if (intermediate.content) {
record.content = intermediate.content;
savable.content = intermediate.content;
}
return record;
return savable;
},
/**
@ -1011,10 +1013,10 @@ MmsService.prototype = {
// For X-Mms-Report-Allowed
let wish = notification.headers["x-mms-delivery-report"];
notification = this.convertFromIntermediateToSavable(notification);
let savableMessage = this.convertIntermediateToSavable(notification);
gMobileMessageDatabaseService.saveReceivedMessage(notification,
(function (rv, messageRecord) {
gMobileMessageDatabaseService.saveReceivedMessage(savableMessage,
(function (rv, domMessage) {
// TODO: Bug 760065 - B2G MMS: Implement MMS DOM API
// Connect to DOM API for notifing new comming MMS to Gaia.
let success = Components.isSuccessCode(rv);
@ -1022,7 +1024,7 @@ MmsService.prototype = {
// At this point we could send a message to content to notify the
// user that storing an incoming MMS notify indication failed,
// ost likely due to a full disk.
debug("Could not store MMS " + JSON.stringify(notification) +
debug("Could not store MMS " + JSON.stringify(savableMessage) +
", error code " + rv);
// Because MMSC will resend the notification indication once we don't
// response the notification. Hope the end user will clean some space
@ -1036,10 +1038,13 @@ MmsService.prototype = {
} catch (e) {}
if (RETRIEVAL_MODE_AUTOMATIC !== retrievalMode) {
let mmsStatus = RETRIEVAL_MODE_NEVER === retrievalMode ?
MMS.MMS_PDU_STATUS_REJECTED : MMS.MMS_PDU_STATUS_DEFERRED;
let mmsStatus = RETRIEVAL_MODE_NEVER === retrievalMode
? MMS.MMS_PDU_STATUS_REJECTED
: MMS.MMS_PDU_STATUS_DEFERRED;
// For X-Mms-Report-Allowed
let reportAllowed = this.getReportAllowed(this.confSendDeliveryReport, wish);
let reportAllowed = this.getReportAllowed(this.confSendDeliveryReport,
wish);
let transaction = new NotifyResponseTransaction(transactionId,
mmsStatus,
@ -1048,30 +1053,34 @@ MmsService.prototype = {
}
this.retrieveMessage(url, (function responseNotify(mmsStatus,
retrievedMsg) {
retrievedMessage) {
// `The absence of the field does not indicate any default
// value.` So we go checking the same field in retrieved
// message instead.
if ((wish == null) && retrievedMsg) {
wish = retrievedMsg.headers["x-mms-delivery-report"];
if ((wish == null) && retrievedMessage) {
wish = retrievedMessage.headers["x-mms-delivery-report"];
}
let reportAllowed = this.getReportAllowed(
this.confSendDeliveryReport, wish);
let reportAllowed = this.getReportAllowed(this.confSendDeliveryReport,
wish);
// Should update the retrievedStatus in databse.
debug("retrievedMsg = " + JSON.stringify(retrievedMsg));
debug("retrievedMessage = " + JSON.stringify(retrievedMessage));
// If the mmsStatus is still MMS_PDU_STATUS_DEFERRED after retry, we
// should not store into database.
if (MMS.MMS_PDU_STATUS_RETRIEVED !== mmsStatus) {
let transaction =
new NotifyResponseTransaction(transactionId, mmsStatus, reportAllowed);
new NotifyResponseTransaction(transactionId,
mmsStatus,
reportAllowed);
transaction.run();
}
messageRecord = this.mergeRetrievalConfirmationIntoRecord(retrievedMsg, messageRecord);
gMobileMessageDatabaseService.saveReceivedMessage(messageRecord,
(function (rv, messageRecord) {
savableMessage = this.mergeRetrievalConfirmation(retrievedMessage,
savableMessage);
gMobileMessageDatabaseService.saveReceivedMessage(savableMessage,
(function (rv, domMessage) {
// TODO: Bug 760065 - B2G MMS: Implement MMS DOM API
// Connect to DOM API for notifing new comming MMS to Gaia.
let success = Components.isSuccessCode(rv);
@ -1079,11 +1088,13 @@ MmsService.prototype = {
// At this point we could send a message to content to
// notify the user that storing an incoming MMS failed, most
// likely due to a full disk.
debug("Could not store MMS " + messageRecord.id +
debug("Could not store MMS " + domMessage.id +
", error code " + rv);
let transaction = new NotifyResponseTransaction(
transactionId, MMS.MMS_PDU_STATUS_DEFERRED, reportAllowed);
let transaction =
new NotifyResponseTransaction(transactionId,
MMS.MMS_PDU_STATUS_DEFERRED,
reportAllowed);
transaction.run();
return;
}
@ -1177,48 +1188,6 @@ MmsService.prototype = {
return message;
},
createMmsMessageFromRecord: function createMmsMessageFromRecord(aRecord) {
debug("createMmsMessageFromRecord: aRecord: " + JSON.stringify(aRecord));
let headers = aRecord["headers"];
let subject = headers["subject"];
if (subject == undefined) {
subject = "";
}
let smil = "";
let attachments = [];
let parts = aRecord.parts;
if (parts) {
for (let i = 0; i < parts.length; i++) {
let part = parts[i];
let partHeaders = part["headers"];
let partContent = part["content"];
// Don't need to make the SMIL part if it's present.
if (partHeaders["content-type"]["media"] == "application/smil") {
smil = part.content;
continue;
}
attachments.push({
"id": partHeaders["content-id"],
"location": partHeaders["content-location"],
"content": partContent
});
}
}
debug("createMmsMessageFromRecord: attachments: " + JSON.stringify(attachments));
return gMobileMessageService.createMmsMessage(aRecord.id,
aRecord.delivery,
aRecord.deliveryStatus,
aRecord.sender,
aRecord.receivers,
aRecord.timestamp,
aRecord.read,
subject,
smil,
attachments);
},
// nsIMmsService
send: function send(aParams, aRequest) {
@ -1230,44 +1199,43 @@ MmsService.prototype = {
let self = this;
let sendTransactionCb = function sendTransactionCb(aIsSentSuccess, aMmsMessage) {
debug("sendTransactionCb: aIsSentSuccess: " + aIsSentSuccess);
let sendTransactionCb = function sendTransactionCb(aRecordId, aIsSentSuccess) {
debug("The success status of sending transaction: " + aIsSentSuccess);
gMobileMessageDatabaseService
.setMessageDelivery(aMmsMessage.id,
.setMessageDelivery(aRecordId,
null,
aIsSentSuccess ? "sent" : "error",
aIsSentSuccess ? null : "error",
function notifySetDeliveryResult(setDeliveryRv, record) {
function notifySetDeliveryResult(aRv, aDomMessage) {
debug("Marking the delivery state/staus is done. Notify sent or failed.");
if (!aIsSentSuccess) {
aRequest.notifySendMessageFailed(Ci.nsIMobileMessageCallback.INTERNAL_ERROR);
Services.obs.notifyObservers(aMmsMessage, kMmsFailedObserverTopic, null);
Services.obs.notifyObservers(aDomMessage, kMmsFailedObserverTopic, null);
return;
}
aRequest.notifyMessageSent(aMmsMessage);
Services.obs.notifyObservers(aMmsMessage, kMmsSentObserverTopic, null);
aRequest.notifyMessageSent(aDomMessage);
Services.obs.notifyObservers(aDomMessage, kMmsSentObserverTopic, null);
});
};
let savableMessage = this.createSavableFromParams(aParams);
gMobileMessageDatabaseService
.saveSendingMessage(savableMessage,
function notifySendingResult(sendingRv, sendingRecord) {
function notifySendingResult(aRv, aDomMessage) {
debug("Saving sending message is done. Start to send.");
let mmsMessage = self.createMmsMessageFromRecord(sendingRecord);
Services.obs.notifyObservers(mmsMessage, kMmsSendingObserverTopic, null);
Services.obs.notifyObservers(aDomMessage, kMmsSendingObserverTopic, null);
let sendTransaction;
try {
sendTransaction = new SendTransaction(sendingRecord);
sendTransaction = new SendTransaction(savableMessage);
} catch (e) {
debug("Fail to create a SendTransaction instance.");
sendTransactionCb(false, mmsMessage);
debug("Exception: fail to create a SendTransaction instance.");
sendTransactionCb(aDomMessage.id, false);
return;
}
sendTransaction.run(function callback(aMmsStatus, aMsg) {
let isSentSuccess = (aMmsStatus == MMS.MMS_PDU_ERROR_OK);
debug("The returned status of sendTransaction.run(): " + aMmsStatus);
sendTransactionCb(isSentSuccess, mmsMessage);
debug("The sending status of sendTransaction.run(): " + aMmsStatus);
sendTransactionCb(aDomMessage.id, isSentSuccess);
});
});
},

View File

@ -19,7 +19,7 @@ dictionary MmsParameters
jsval attachments; // MmsAttachment[]
};
[scriptable, builtinclass, uuid(f020e48e-84c7-11e2-939e-53a3106dde16)]
[scriptable, builtinclass, uuid(4e3b73f6-8d45-11e2-a590-534c61399fe5)]
interface nsIDOMMozMobileMessageManager : nsIDOMEventTarget
{
nsIDOMMozSmsSegmentInfo getSegmentInfoForText(in DOMString text);
@ -33,7 +33,7 @@ interface nsIDOMMozMobileMessageManager : nsIDOMEventTarget
nsIDOMDOMRequest sendMMS(in jsval parameters /* MmsParameters */);
[binaryname(GetMessageMoz)]
nsIDOMMozSmsRequest getMessage(in long id);
nsIDOMDOMRequest getMessage(in long id);
// The parameter can be either a message id or a SmsMessage.
nsIDOMMozSmsRequest delete(in jsval param);

View File

@ -13,9 +13,14 @@ dictionary MmsAttachment
nsIDOMBlob content;
};
[scriptable, builtinclass, uuid(df002ad2-71d7-11e2-9f1c-af6fa139069f)]
[scriptable, builtinclass, uuid(c9683d00-88a6-11e2-85cc-57a33dfbea3b)]
interface nsIDOMMozMmsMessage : nsISupports
{
/**
* |type| is always "mms".
*/
readonly attribute DOMString type;
readonly attribute long id;
/**

View File

@ -4,9 +4,14 @@
#include "nsISupports.idl"
[scriptable, builtinclass, uuid(59fc5ea8-33fe-40ba-890b-b9abaeb5ac26)]
[scriptable, builtinclass, uuid(d4d848c4-88a6-11e2-b6da-6f252cbfa716)]
interface nsIDOMMozSmsMessage : nsISupports
{
/**
* |type| is always "sms".
*/
readonly attribute DOMString type;
readonly attribute long id;
/**

View File

@ -4,8 +4,6 @@
#include "nsISupports.idl"
interface nsIDOMMozSmsMessage;
dictionary SmsThreadListItem
{
DOMString senderOrReceiver;
@ -14,7 +12,7 @@ dictionary SmsThreadListItem
unsigned long long unreadCount;
};
[scriptable, builtinclass, uuid(18d7c4da-848f-11e2-a3a5-f749c4ba31b5)]
[scriptable, builtinclass, uuid(edb1de12-8d58-11e2-b382-7bf132b20cb2)]
interface nsIMobileMessageCallback : nsISupports
{
/**
@ -29,21 +27,27 @@ interface nsIMobileMessageCallback : nsISupports
const unsigned short INTERNAL_ERROR = 4;
/**
* |message| can be either |nsIDOMMozSmsMessage| or |nsIDOMMozMmsMessage|.
* |message| can be nsIDOMMoz{Mms,Sms}Message.
*/
void notifyMessageSent(in nsISupports message);
void notifySendMessageFailed(in long error);
void notifyMessageGot(in nsIDOMMozSmsMessage message);
/**
* |message| can be nsIDOMMoz{Mms,Sms}Message.
*/
void notifyMessageGot(in nsISupports message);
void notifyGetMessageFailed(in long error);
void notifyMessageDeleted(in boolean deleted);
void notifyDeleteMessageFailed(in long error);
/**
* |message| can be nsIDOMMoz{Mms,Sms}Message.
*/
void notifyMessageListCreated(in long listId,
in nsIDOMMozSmsMessage message);
in nsISupports message);
void notifyReadMessageListFailed(in long error);
void notifyNextMessageInListGot(in nsIDOMMozSmsMessage message);
void notifyNextMessageInListGot(in nsISupports message);
void notifyNoMessageInList();
void notifyMessageMarkedRead(in boolean read);

View File

@ -6,13 +6,13 @@
#include "nsISupports.idl"
#include "nsIMobileMessageDatabaseService.idl"
[scriptable, function, uuid(0bffae74-71db-11e2-962a-73cf64d6393e)]
[scriptable, function, uuid(92986322-8d56-11e2-8816-73a531c493c2)]
interface nsIRilMobileMessageDatabaseCallback : nsISupports
{
/**
* |aRecord| Object: the mobile-message database record
* |aDomMessage|: the nsIDOMMoz{Mms,Sms}Message
*/
void notify(in nsresult aRv, in jsval aRecord);
void notify(in nsresult aRv, in nsISupports aDomMessage);
};
[scriptable, uuid(a31b1716-8631-11e2-afaa-2fbd087f426e)]

View File

@ -206,6 +206,13 @@ MmsMessage::Create(int32_t aId,
return NS_OK;
}
NS_IMETHODIMP
MmsMessage::GetType(nsAString& aType)
{
aType = NS_LITERAL_STRING("mms");
return NS_OK;
}
NS_IMETHODIMP
MmsMessage::GetId(int32_t* aId)
{

View File

@ -35,8 +35,8 @@ MobileMessageCallback::~MobileMessageCallback()
{
}
NS_IMETHODIMP
MobileMessageCallback::NotifyMessageSent(nsISupports *aMessage)
nsresult
MobileMessageCallback::NotifySuccess(nsISupports *aMessage)
{
nsresult rv;
nsIScriptContext* scriptContext = mDOMRequest->GetContextForEventHandlers(&rv);
@ -61,8 +61,8 @@ MobileMessageCallback::NotifyMessageSent(nsISupports *aMessage)
return NS_OK;
}
NS_IMETHODIMP
MobileMessageCallback::NotifySendMessageFailed(int32_t aError)
nsresult
MobileMessageCallback::NotifyError(int32_t aError)
{
nsCOMPtr<nsIDOMRequestService> rs = do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
@ -84,15 +84,27 @@ MobileMessageCallback::NotifySendMessageFailed(int32_t aError)
}
NS_IMETHODIMP
MobileMessageCallback::NotifyMessageGot(nsIDOMMozSmsMessage *aMessage)
MobileMessageCallback::NotifyMessageSent(nsISupports *aMessage)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NotifySuccess(aMessage);
}
NS_IMETHODIMP
MobileMessageCallback::NotifySendMessageFailed(int32_t aError)
{
return NotifyError(aError);
}
NS_IMETHODIMP
MobileMessageCallback::NotifyMessageGot(nsISupports *aMessage)
{
return NotifySuccess(aMessage);
}
NS_IMETHODIMP
MobileMessageCallback::NotifyGetMessageFailed(int32_t aError)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NotifyError(aError);
}
NS_IMETHODIMP
@ -109,7 +121,7 @@ MobileMessageCallback::NotifyDeleteMessageFailed(int32_t aError)
NS_IMETHODIMP
MobileMessageCallback::NotifyMessageListCreated(int32_t aListId,
nsIDOMMozSmsMessage *aMessage)
nsISupports *aMessage)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -121,7 +133,7 @@ MobileMessageCallback::NotifyReadMessageListFailed(int32_t aError)
}
NS_IMETHODIMP
MobileMessageCallback::NotifyNextMessageInListGot(nsIDOMMozSmsMessage *aMessage)
MobileMessageCallback::NotifyNextMessageInListGot(nsISupports *aMessage)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -28,6 +28,9 @@ private:
~MobileMessageCallback();
nsRefPtr<DOMRequest> mDOMRequest;
nsresult NotifySuccess(nsISupports *aMessage);
nsresult NotifyError(int32_t aError);
};
} // namespace mobilemessage

View File

@ -203,16 +203,18 @@ MobileMessageManager::SendMMS(const JS::Value& aParams, nsIDOMDOMRequest** aRequ
}
NS_IMETHODIMP
MobileMessageManager::GetMessageMoz(int32_t aId, nsIDOMMozSmsRequest** aRequest)
MobileMessageManager::GetMessageMoz(int32_t aId, nsIDOMDOMRequest** aRequest)
{
nsCOMPtr<nsIDOMMozSmsRequest> req = SmsRequest::Create(this);
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
nsCOMPtr<nsIMobileMessageCallback> forwarder =
new SmsRequestForwarder(static_cast<SmsRequest*>(req.get()));
mobileMessageDBService->GetMessageMoz(aId, forwarder);
req.forget(aRequest);
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
nsresult rv = mobileMessageDBService->GetMessageMoz(aId, msgCallback);
NS_ENSURE_SUCCESS(rv, rv);
request.forget(aRequest);
return NS_OK;
}

View File

@ -135,6 +135,13 @@ SmsMessage::GetData() const
return mData;
}
NS_IMETHODIMP
SmsMessage::GetType(nsAString& aType)
{
aType = NS_LITERAL_STRING("sms");
return NS_OK;
}
NS_IMETHODIMP
SmsMessage::GetId(int32_t* aId)
{

View File

@ -370,13 +370,21 @@ SmsRequest::NotifySendMessageFailed(int32_t aError)
}
NS_IMETHODIMP
SmsRequest::NotifyMessageGot(nsIDOMMozSmsMessage *aMessage)
SmsRequest::NotifyMessageGot(nsISupports *aMessage)
{
// We only support nsIDOMMozSmsMessage for SmsRequest.
nsCOMPtr<nsIDOMMozSmsMessage> message(do_QueryInterface(aMessage));
if (!message) {
return NS_ERROR_NOT_IMPLEMENTED;
}
SmsMessage* smsMessage = static_cast<SmsMessage*>(message.get());
if (mParent) {
SmsMessageData data = SmsMessageData(static_cast<SmsMessage*>(aMessage)->GetData());
SmsMessageData data = SmsMessageData(smsMessage->GetData());
return SendMessageReply(MessageReply(ReplyGetMessage(data)));
}
return NotifySuccess<nsIDOMMozSmsMessage*>(aMessage);
return NotifySuccess<nsIDOMMozSmsMessage*>(smsMessage);
}
@ -408,15 +416,22 @@ SmsRequest::NotifyDeleteMessageFailed(int32_t aError)
}
NS_IMETHODIMP
SmsRequest::NotifyMessageListCreated(int32_t aListId,
nsIDOMMozSmsMessage *aMessage)
SmsRequest::NotifyMessageListCreated(int32_t aListId, nsISupports *aMessage)
{
// We only support nsIDOMMozSmsMessage for SmsRequest.
nsCOMPtr<nsIDOMMozSmsMessage> message(do_QueryInterface(aMessage));
if (!message) {
return NS_ERROR_NOT_IMPLEMENTED;
}
SmsMessage* smsMessage = static_cast<SmsMessage*>(message.get());
if (mParent) {
SmsMessageData data = SmsMessageData(static_cast<SmsMessage*>(aMessage)->GetData());
SmsMessageData data = SmsMessageData(smsMessage->GetData());
return SendMessageReply(MessageReply(ReplyCreateMessageList(aListId, data)));
} else {
nsCOMPtr<SmsCursor> cursor = new SmsCursor(aListId, this);
cursor->SetMessage(aMessage);
cursor->SetMessage(smsMessage);
return NotifySuccess<nsIDOMMozSmsCursor*>(cursor);
}
}
@ -434,15 +449,23 @@ SmsRequest::NotifyReadMessageListFailed(int32_t aError)
}
NS_IMETHODIMP
SmsRequest::NotifyNextMessageInListGot(nsIDOMMozSmsMessage *aMessage)
SmsRequest::NotifyNextMessageInListGot(nsISupports *aMessage)
{
// We only support nsIDOMMozSmsMessage for SmsRequest.
nsCOMPtr<nsIDOMMozSmsMessage> message(do_QueryInterface(aMessage));
if (!message) {
return NS_ERROR_NOT_IMPLEMENTED;
}
SmsMessage* smsMessage = static_cast<SmsMessage*>(message.get());
if (mParent) {
SmsMessageData data = SmsMessageData(static_cast<SmsMessage*>(aMessage)->GetData());
SmsMessageData data = SmsMessageData(smsMessage->GetData());
return SendMessageReply(MessageReply(ReplyGetNextMessage(data)));
}
nsCOMPtr<SmsCursor> cursor = static_cast<SmsCursor*>(mCursor.get());
NS_ASSERTION(cursor, "Request should have an cursor in that case!");
cursor->SetMessage(aMessage);
cursor->SetMessage(smsMessage);
return NotifySuccess<nsIDOMMozSmsCursor*>(cursor);
}

View File

@ -22,6 +22,7 @@ const PARTICIPANT_STORE_NAME = "participant";
const MOST_RECENT_STORE_NAME = "most-recent";
const DELIVERY_SENDING = "sending";
const DELIVERY_SENT = "sent";
const DELIVERY_RECEIVED = "received";
const DELIVERY_STATUS_NOT_APPLICABLE = "not-applicable";
@ -117,7 +118,7 @@ MobileMessageDatabaseService.prototype = {
lastMessageListId: 0,
/**
* Last sms object store key value in the database.
* Last sms/mms object store key value in the database.
*/
lastMessageId: 0,
@ -558,19 +559,73 @@ MobileMessageDatabaseService.prototype = {
};
},
createSmsMessageFromRecord: function createSmsMessageFromRecord(aMessageRecord) {
createDomMessageFromRecord: function createDomMessageFromRecord(aMessageRecord) {
if (DEBUG) {
debug("createSmsMessageFromRecord: " + JSON.stringify(aMessageRecord));
debug("createDomMessageFromRecord: " + JSON.stringify(aMessageRecord));
}
if (aMessageRecord.type == "sms") {
return gMobileMessageService.createSmsMessage(aMessageRecord.id,
aMessageRecord.delivery,
aMessageRecord.deliveryStatus,
aMessageRecord.sender,
aMessageRecord.receiver,
aMessageRecord.body,
aMessageRecord.messageClass,
aMessageRecord.timestamp,
aMessageRecord.read);
} else if (aMessageRecord.type == "mms") {
let headers = aMessageRecord["headers"];
let subject = headers["subject"];
if (subject == undefined) {
subject = "";
}
let smil = "";
let attachments = [];
let parts = aMessageRecord.parts;
if (parts) {
for (let i = 0; i < parts.length; i++) {
let part = parts[i];
let partHeaders = part["headers"];
let partContent = part["content"];
// Don't need to make the SMIL part if it's present.
if (partHeaders["content-type"]["media"] == "application/smil") {
smil = part.content;
continue;
}
attachments.push({
"id": partHeaders["content-id"],
"location": partHeaders["content-location"],
"content": partContent
});
}
}
if (DEBUG) {
debug("createDomMessageFromRecord: createMmsMessage: " + JSON.stringify({
id: aMessageRecord.id,
delivery: aMessageRecord.delivery,
deliveryStatus: aMessageRecord.deliveryStatus,
sender: aMessageRecord.sender,
receivers: aMessageRecord.receivers,
timestamp: aMessageRecord.timestamp,
read: aMessageRecord.read,
subject: subject,
smil: smil,
attachments: attachments
}));
}
return gMobileMessageService.createMmsMessage(aMessageRecord.id,
aMessageRecord.delivery,
aMessageRecord.deliveryStatus,
aMessageRecord.sender,
aMessageRecord.receivers,
aMessageRecord.timestamp,
aMessageRecord.read,
subject,
smil,
attachments);
}
return gMobileMessageService.createSmsMessage(aMessageRecord.id,
aMessageRecord.delivery,
aMessageRecord.deliveryStatus,
aMessageRecord.sender,
aMessageRecord.receiver,
aMessageRecord.body,
aMessageRecord.messageClass,
aMessageRecord.timestamp,
aMessageRecord.read);
},
/**
@ -602,14 +657,14 @@ MobileMessageDatabaseService.prototype = {
// retrieving process. So we don't bother continuing to process further
// waiting requests here. This assumption comes from SmsCursor::Continue()
// implementation.
let smsRequest = aMessageList.requestWaiting;
let request = aMessageList.requestWaiting;
aMessageList.requestWaiting = null;
if (!aMessageList.results.length) {
// No fetched results yet.
if (!aMessageList.processing) {
if (DEBUG) debug("No messages matching the filter criteria");
smsRequest.notifyNoMessageInList();
request.notifyNoMessageInList();
}
// No fetched results yet and still processing. Let's wait a bit more.
return;
@ -619,7 +674,7 @@ MobileMessageDatabaseService.prototype = {
// An previous error found. Keep the answer in results so that we can
// reply INTERNAL_ERROR for further requests.
if (DEBUG) debug("An previous error found");
smsRequest.notifyReadMessageListFailed(Ci.nsIMobileMessageCallback.INTERNAL_ERROR);
request.notifyReadMessageListFailed(Ci.nsIMobileMessageCallback.INTERNAL_ERROR);
return;
}
@ -629,13 +684,14 @@ MobileMessageDatabaseService.prototype = {
let getRequest = aMessageStore.get(firstMessageId);
let self = this;
getRequest.onsuccess = function onsuccess(event) {
let sms = self.createSmsMessageFromRecord(event.target.result);
let messageRecord = event.target.result;
let domMessage = self.createDomMessageFromRecord(messageRecord);
if (aMessageList.listId >= 0) {
if (DEBUG) {
debug("notifyNextMessageInListGot - listId: "
+ aMessageList.listId + ", messageId: " + firstMessageId);
}
smsRequest.notifyNextMessageInListGot(sms);
request.notifyNextMessageInListGot(domMessage);
} else {
self.lastMessageListId += 1;
aMessageList.listId = self.lastMessageListId;
@ -644,7 +700,7 @@ MobileMessageDatabaseService.prototype = {
debug("notifyMessageListCreated - listId: "
+ aMessageList.listId + ", messageId: " + firstMessageId);
}
smsRequest.notifyMessageListCreated(aMessageList.listId, sms);
request.notifyMessageListCreated(aMessageList.listId, domMessage);
}
};
getRequest.onerror = function onerror(event) {
@ -652,7 +708,7 @@ MobileMessageDatabaseService.prototype = {
debug("notifyReadMessageListFailed - listId: "
+ aMessageList.listId + ", messageId: " + firstMessageId);
}
smsRequest.notifyReadMessageListFailed(Ci.nsIMobileMessageCallback.INTERNAL_ERROR);
request.notifyReadMessageListFailed(Ci.nsIMobileMessageCallback.INTERNAL_ERROR);
};
},
@ -976,7 +1032,8 @@ MobileMessageDatabaseService.prototype = {
if (!aCallback) {
return;
}
aCallback.notify(rv, aMessageRecord);
let domMessage = self.createDomMessageFromRecord(aMessageRecord);
aCallback.notify(rv, domMessage);
}
this.newTxn(READ_WRITE, function(error, txn, stores) {
@ -1188,7 +1245,8 @@ MobileMessageDatabaseService.prototype = {
if (!callback) {
return;
}
callback.notify(rv, messageRecord);
let domMessage = self.createDomMessageFromRecord(messageRecord);
callback.notify(rv, domMessage);
}
this.newTxn(READ_WRITE, function (error, txn, messageStore) {
@ -1313,8 +1371,8 @@ MobileMessageDatabaseService.prototype = {
aRequest.notifyGetMessageFailed(Ci.nsIMobileMessageCallback.UNKNOWN_ERROR);
return;
}
let sms = self.createSmsMessageFromRecord(messageRecord);
aRequest.notifyMessageGot(sms);
let domMessage = self.createDomMessageFromRecord(messageRecord);
aRequest.notifyMessageGot(domMessage);
};
txn.onerror = function onerror(event) {
@ -1447,7 +1505,7 @@ MobileMessageDatabaseService.prototype = {
contexts: null,
// Result queues for multiple numbers filter's case.
numberQueues: null,
// Pending createMessageList or getNextMessageInList SmsRequest.
// Pending createMessageList or getNextMessageInList request.
requestWaiting: aRequest,
results: []
};
@ -1758,8 +1816,8 @@ MobileMessageDatabaseService.prototype = {
if (DEBUG) debug("Could not get message id " + messageId);
aRequest.notifyReadMessageListFailed(Ci.nsIMobileMessageCallback.NOT_FOUND_ERROR);
}
let sms = self.createSmsMessageFromRecord(messageRecord);
aRequest.notifyNextMessageInListGot(sms);
let domMessage = self.createDomMessageFromRecord(messageRecord);
aRequest.notifyNextMessageInListGot(domMessage);
};
txn.onerror = function onerror(event) {

View File

@ -1485,18 +1485,6 @@ RadioInterfaceLayer.prototype = {
0, options);
},
createSmsMessageFromRecord: function createSmsMessageFromRecord(aRecord) {
return gMobileMessageService.createSmsMessage(aRecord.id,
aRecord.delivery,
aRecord.deliveryStatus,
aRecord.sender,
aRecord.receiver,
aRecord.body,
aRecord.messageClass,
aRecord.timestamp,
aRecord.read);
},
portAddressedSmsApps: null,
handleSmsReceived: function handleSmsReceived(message) {
debug("handleSmsReceived: " + JSON.stringify(message));
@ -1540,8 +1528,7 @@ RadioInterfaceLayer.prototype = {
return true;
}
let notifyReceived = function notifyReceived(rv, record) {
let sms = this.createSmsMessageFromRecord(record);
let notifyReceived = function notifyReceived(rv, domMessage) {
let success = Components.isSuccessCode(rv);
// Acknowledge the reception of the SMS.
@ -1570,7 +1557,7 @@ RadioInterfaceLayer.prototype = {
read: false
});
Services.obs.notifyObservers(sms, kSmsReceivedObserverTopic, null);
Services.obs.notifyObservers(domMessage, kSmsReceivedObserverTopic, null);
}.bind(this);
if (message.messageClass != RIL.GECKO_SMS_MESSAGE_CLASSES[RIL.PDU_DCS_MSG_CLASS_0]) {
@ -1582,7 +1569,18 @@ RadioInterfaceLayer.prototype = {
message.deliveryStatus = RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS;
message.read = false;
notifyReceived(Cr.NS_OK, message);
let domMessage =
gMobileMessageService.createSmsMessage(message.id,
message.delivery,
message.deliveryStatus,
message.sender,
message.receiver,
message.body,
message.messageClass,
message.timestamp,
message.read);
notifyReceived(Cr.NS_OK, domMessage);
}
// SMS ACK will be sent in notifyReceived. Return false here.
@ -1616,8 +1614,7 @@ RadioInterfaceLayer.prototype = {
null,
DOM_MOBILE_MESSAGE_DELIVERY_SENT,
options.sms.deliveryStatus,
function notifyResult(rv, record) {
let sms = this.createSmsMessageFromRecord(record);
function notifyResult(rv, domMessage) {
//TODO bug 832140 handle !Components.isSuccessCode(rv)
gSystemMessenger.broadcastMessage("sms-sent",
{id: options.sms.id,
@ -1634,12 +1631,11 @@ RadioInterfaceLayer.prototype = {
// No more used if STATUS-REPORT not requested.
delete this._sentSmsEnvelopes[message.envelopeId];
} else {
options.sms = sms;
options.sms = domMessage;
}
options.request.notifyMessageSent(sms);
Services.obs.notifyObservers(sms, kSmsSentObserverTopic, null);
options.request.notifyMessageSent(domMessage);
Services.obs.notifyObservers(domMessage, kSmsSentObserverTopic, null);
}.bind(this));
},
@ -1656,13 +1652,12 @@ RadioInterfaceLayer.prototype = {
null,
options.sms.delivery,
message.deliveryStatus,
function notifyResult(rv, record) {
let sms = this.createSmsMessageFromRecord(record);
function notifyResult(rv, domMessage) {
//TODO bug 832140 handle !Components.isSuccessCode(rv)
let topic = (message.deliveryStatus == RIL.GECKO_SMS_DELIVERY_STATUS_SUCCESS)
? kSmsDeliverySuccessObserverTopic
: kSmsDeliveryErrorObserverTopic;
Services.obs.notifyObservers(sms, topic, null);
Services.obs.notifyObservers(domMessage, topic, null);
}.bind(this));
},
@ -1686,11 +1681,10 @@ RadioInterfaceLayer.prototype = {
null,
DOM_MOBILE_MESSAGE_DELIVERY_ERROR,
RIL.GECKO_SMS_DELIVERY_STATUS_ERROR,
function notifyResult(rv, record) {
let sms = this.createSmsMessageFromRecord(record);
function notifyResult(rv, domMessage) {
//TODO bug 832140 handle !Components.isSuccessCode(rv)
options.request.notifySendMessageFailed(error);
Services.obs.notifyObservers(sms, kSmsFailedObserverTopic, null);
Services.obs.notifyObservers(domMessage, kSmsFailedObserverTopic, null);
}.bind(this));
},
@ -2689,15 +2683,14 @@ RadioInterfaceLayer.prototype = {
};
let id = gMobileMessageDatabaseService.saveSendingMessage(sendingMessage,
function notifyResult(rv, record) {
let sms = this.createSmsMessageFromRecord(record);
function notifyResult(rv, domMessage) {
//TODO bug 832140 handle !Components.isSuccessCode(rv)
Services.obs.notifyObservers(sms, kSmsSendingObserverTopic, null);
Services.obs.notifyObservers(domMessage, kSmsSendingObserverTopic, null);
// Keep current SMS message info for sent/delivered notifications
options.envelopeId = this.createSmsEnvelope({
request: request,
sms: sms,
sms: domMessage,
requestStatusReport: options.requestStatusReport
});