Bug 863241 - Part 2: B2G MMS: the return items from getThreads should have type to identify mms or sms. r=vyang

This commit is contained in:
Chia-hung Tai 2013-04-26 16:40:42 +08:00
parent 1a9142851e
commit acde781295
6 changed files with 117 additions and 6 deletions

View File

@ -40,6 +40,9 @@ extern const char* kMmsReceivedObserverTopic;
#define MESSAGE_CLASS_CLASS_2 NS_LITERAL_STRING("class-2")
#define MESSAGE_CLASS_CLASS_3 NS_LITERAL_STRING("class-3")
#define MESSAGE_TYPE_SMS NS_LITERAL_STRING("sms")
#define MESSAGE_TYPE_MMS NS_LITERAL_STRING("mms")
} // namespace mobilemessage
} // namespace dom
} // namespace mozilla

View File

@ -107,6 +107,7 @@ MobileMessageService::CreateThread(uint64_t aId,
const JS::Value& aTimestamp,
const nsAString& aBody,
uint64_t aUnreadCount,
const nsAString& aLastMessageType,
JSContext* aCx,
nsIDOMMozMobileMessageThread** aThread)
{
@ -115,6 +116,7 @@ MobileMessageService::CreateThread(uint64_t aId,
aTimestamp,
aBody,
aUnreadCount,
aLastMessageType,
aCx,
aThread);
}

View File

@ -10,6 +10,8 @@
#include "nsJSUtils.h" // For nsDependentJSString
#include "nsContentUtils.h" // For nsTArrayHelpers.h
#include "nsTArrayHelpers.h" // For nsTArrayToJSArray
#include "Constants.h" // For MessageType
using namespace mozilla::dom::mobilemessage;
@ -33,6 +35,7 @@ MobileMessageThread::Create(const uint64_t aId,
const JS::Value& aTimestamp,
const nsAString& aBody,
const uint64_t aUnreadCount,
const nsAString& aLastMessageType,
JSContext* aCx,
nsIDOMMozMobileMessageThread** aThread)
{
@ -91,6 +94,19 @@ MobileMessageThread::Create(const uint64_t aId,
data.timestamp() = static_cast<uint64_t>(number);
}
// Set |aLastMessageType|.
{
MessageType lastMessageType;
if (aLastMessageType.Equals(MESSAGE_TYPE_SMS)) {
lastMessageType = eMessageType_SMS;
} else if (aLastMessageType.Equals(MESSAGE_TYPE_MMS)) {
lastMessageType = eMessageType_MMS;
} else {
return NS_ERROR_INVALID_ARG;
}
data.lastMessageType() = lastMessageType;
}
nsCOMPtr<nsIDOMMozMobileMessageThread> thread = new MobileMessageThread(data);
thread.forget(aThread);
return NS_OK;
@ -100,8 +116,9 @@ MobileMessageThread::MobileMessageThread(const uint64_t aId,
const nsTArray<nsString>& aParticipants,
const uint64_t aTimestamp,
const nsString& aBody,
const uint64_t aUnreadCount)
: mData(aId, aParticipants, aTimestamp, aBody, aUnreadCount)
const uint64_t aUnreadCount,
MessageType aLastMessageType)
: mData(aId, aParticipants, aTimestamp, aBody, aUnreadCount, aLastMessageType)
{
MOZ_ASSERT(aParticipants.Length());
}
@ -157,5 +174,24 @@ MobileMessageThread::GetTimestamp(JSContext* aCx,
return NS_OK;
}
NS_IMETHODIMP
MobileMessageThread::GetLastMessageType(nsAString& aLastMessageType)
{
switch (mData.lastMessageType()) {
case eMessageType_SMS:
aLastMessageType = MESSAGE_TYPE_SMS;
break;
case eMessageType_MMS:
aLastMessageType = MESSAGE_TYPE_MMS;
break;
case eMessageType_EndGuard:
default:
MOZ_NOT_REACHED("We shouldn't get any other delivery state!");
return NS_ERROR_UNEXPECTED;
}
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View File

@ -28,7 +28,8 @@ public:
const nsTArray<nsString>& aParticipants,
const uint64_t aTimestamp,
const nsString& aBody,
const uint64_t aUnreadCount);
const uint64_t aUnreadCount,
mobilemessage::MessageType aLastMessageType);
MobileMessageThread(const ThreadData& aData);
@ -37,6 +38,7 @@ public:
const JS::Value& aTimestamp,
const nsAString& aBody,
const uint64_t aUnreadCount,
const nsAString& aLastMessageType,
JSContext* aCx,
nsIDOMMozMobileMessageThread** aThread);

View File

@ -56,6 +56,14 @@ enum MessageClass {
eMessageClass_EndGuard
};
// For ThreadData.
enum MessageType {
eMessageType_SMS = 0,
eMessageType_MMS,
// This state should stay at the end.
eMessageType_EndGuard
};
} // namespace mobilemessage
} // namespace dom
} // namespace mozilla
@ -102,6 +110,16 @@ struct ParamTraits<mozilla::dom::mobilemessage::MessageClass>
mozilla::dom::mobilemessage::eMessageClass_EndGuard>
{};
/**
* MessageType class serializer.
*/
template <>
struct ParamTraits<mozilla::dom::mobilemessage::MessageType>
: public EnumSerializer<mozilla::dom::mobilemessage::MessageType,
mozilla::dom::mobilemessage::eMessageType_SMS,
mozilla::dom::mobilemessage::eMessageType_EndGuard>
{};
} // namespace IPC
#endif // mozilla_dom_mobilemessage_Types_h

View File

@ -21,7 +21,7 @@ const RIL_GETTHREADSCURSOR_CID =
const DEBUG = false;
const DB_NAME = "sms";
const DB_VERSION = 10;
const DB_VERSION = 11;
const MESSAGE_STORE_NAME = "sms";
const THREAD_STORE_NAME = "thread";
const PARTICIPANT_STORE_NAME = "participant";
@ -209,6 +209,10 @@ MobileMessageDatabaseService.prototype = {
if (DEBUG) debug("Upgrade to version 10. Upgrade type if it's not existing.");
self.upgradeSchema9(event.target.transaction);
break;
case 10:
if (DEBUG) debug("Upgrade to version 11. Add last message type into threadRecord.");
self.upgradeSchema10(event.target.transaction);
break;
default:
event.target.transaction.abort();
callback("Old database version: " + event.oldVersion, null);
@ -620,6 +624,49 @@ MobileMessageDatabaseService.prototype = {
};
},
upgradeSchema10: function upgradeSchema10(transaction) {
let threadStore = transaction.objectStore(THREAD_STORE_NAME);
// Add 'lastMessageType' to each thread record.
threadStore.openCursor().onsuccess = function(event) {
let cursor = event.target.result;
if (!cursor) {
return;
}
let threadRecord = cursor.value;
let lastMessageId = threadRecord.lastMessageId;
let messageStore = transaction.objectStore(MESSAGE_STORE_NAME);
let request = messageStore.mozGetAll(lastMessageId);
request.onsuccess = function onsuccess() {
let messageRecord = request.result[0];
if (!messageRecord) {
if (DEBUG) debug("Message ID " + lastMessageId + " not found");
return;
}
if (messageRecord.id != lastMessageId) {
if (DEBUG) {
debug("Requested message ID (" + lastMessageId + ") is different from" +
" the one we got");
}
return;
}
threadRecord.lastMessageType = messageRecord.type;
cursor.update(threadRecord);
};
request.onerror = function onerror(event) {
if (DEBUG) {
if (event.target) {
debug("Caught error on transaction", event.target.errorCode);
}
}
};
cursor.continue();
};
},
createDomMessageFromRecord: function createDomMessageFromRecord(aMessageRecord) {
if (DEBUG) {
debug("createDomMessageFromRecord: " + JSON.stringify(aMessageRecord));
@ -941,6 +988,7 @@ MobileMessageDatabaseService.prototype = {
threadRecord.lastTimestamp = timestamp;
threadRecord.subject = aMessageRecord.body;
threadRecord.lastMessageId = aMessageRecord.id;
threadRecord.lastMessageType = aMessageRecord.type;
needsUpdate = true;
}
@ -962,7 +1010,8 @@ MobileMessageDatabaseService.prototype = {
lastMessageId: aMessageRecord.id,
lastTimestamp: timestamp,
subject: aMessageRecord.body,
unreadCount: aMessageRecord.read ? 0 : 1})
unreadCount: aMessageRecord.read ? 0 : 1,
lastMessageType: aMessageRecord.type})
.onsuccess = function (event) {
let threadId = event.target.result;
insertMessageRecord(threadId);
@ -2140,7 +2189,8 @@ GetThreadsCursor.prototype = {
threadRecord.participantAddresses,
threadRecord.lastTimestamp,
threadRecord.subject,
threadRecord.unreadCount);
threadRecord.unreadCount,
threadRecord.lastMessageType);
self.callback.notifyCursorResult(thread);
};
getRequest.onerror = function onerror(event) {