Bug 865157 - B2G MMS: Receiving an MMS creates a redundant thread different from the one containing SMS (from the same sender). r=vicamo, sr=mounir, a=leo+
authorGene Lian <clian@mozilla.com>
Thu, 02 May 2013 11:06:44 +0800
changeset 119247 499c3627e89a1e16d366fdfb78493233428e7b2f
parent 119246 4451d7bc0912afe043957e139fd4513adcb8e389
child 119248 1087e3e68ef50222bbeb5194f34d602f375f49bb
push id747
push userryanvm@gmail.com
push dateThu, 02 May 2013 13:10:59 +0000
reviewersvicamo, mounir, leo
bugs865157
milestone18.0
Bug 865157 - B2G MMS: Receiving an MMS creates a redundant thread different from the one containing SMS (from the same sender). r=vicamo, sr=mounir, a=leo+
dom/mobilemessage/src/MmsMessage.cpp
dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
--- a/dom/mobilemessage/src/MmsMessage.cpp
+++ b/dom/mobilemessage/src/MmsMessage.cpp
@@ -381,21 +381,16 @@ MmsMessage::GetSender(nsAString& aSender
 {
   aSender = mSender;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 MmsMessage::GetReceivers(JSContext* aCx, JS::Value* aReceivers)
 {
-  uint32_t length = mReceivers.Length();
-  if (length == 0) {
-    return NS_ERROR_UNEXPECTED;
-  }
-
   JSObject* reveiversObj = nullptr;
   nsresult rv = nsTArrayToJSArray(aCx, mReceivers, &reveiversObj);
   NS_ENSURE_SUCCESS(rv, rv);
 
   aReceivers->setObject(*reveiversObj);
   return NS_OK;
 }
 
--- a/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
+++ b/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
@@ -1003,23 +1003,31 @@ MobileMessageDatabaseService.prototype =
     let self = this.getRilIccInfoMsisdn();
     let threadParticipants = [aMessage.sender];
     if (aMessage.type == "sms") {
       // TODO Bug 853384 - for some SIMs we cannot retrieve the vaild
       // phone number, thus setting the SMS' receiver to be null.
       aMessage.receiver = self;
     } else if (aMessage.type == "mms") {
       let receivers = aMessage.receivers;
-      if (!receivers.length) {
-        // TODO Bug 853384 - we cannot expose empty receivers for
-        // an MMS message. Returns 'myself' when .msisdn isn't valid.
-        receivers.push(self ? self : "myself");
-      } else {
-        // TODO Bug 853384 - we cannot correcly exclude the phone number
-        // from the receivers, thus wrongly building the index.
+      // We need to add the receivers (excluding our own) into the participants
+      // of a thread. Some cases we might encounter here:
+      // 1. receivers.length == 0
+      //    This usually happens when receiving an MMS notification indication
+      //    which doesn't carry any receivers.
+      // 2. receivers.length == 1
+      //    If the receivers contain single phone number, we don't need to
+      //    add it into participants because we know that number is our own.
+      // 3. receivers.length >= 2
+      //    If the receivers contain multiple phone numbers, we need to add all
+      //    of them but not our own into participants.
+      if (receivers.length >= 2) {
+        // TODO Bug 853384 - for some SIM cards, the phone number might not be
+        // available, so we cannot correcly exclude our own from the receivers,
+        // thus wrongly building the thread index.
         let slicedReceivers = receivers.slice();
         if (self) {
           let found = slicedReceivers.indexOf(self);
           if (found !== -1) {
             slicedReceivers.splice(found, 1);
           }
         }
         threadParticipants = threadParticipants.concat(slicedReceivers);