emailservices/nmailagent/src/nmmailagent.cpp
changeset 56 15bc1d5d6267
parent 51 d845db10c0d4
child 62 a8c646b56683
--- a/emailservices/nmailagent/src/nmmailagent.cpp	Fri Jul 09 12:17:13 2010 +0300
+++ b/emailservices/nmailagent/src/nmmailagent.cpp	Fri Jul 23 19:09:50 2010 +0300
@@ -79,7 +79,7 @@
   mActive(false),
   mInboxActive(false)
   {
-    NM_FUNCTION;
+      NM_FUNCTION;
   }
 
 /*!
@@ -98,7 +98,7 @@
      mSettingManager(NULL),
      mSilenceMode(NmSilenceModeOn)  // by default silent mode is on
      {
-    NM_FUNCTION;
+     NM_FUNCTION;
      }
 
 /*!
@@ -599,30 +599,48 @@
     \sa updateUnreadCount
 
     \param folderId Id of the folder that includes the message
+    \param messageIds Message ids that are checked
     \param mailboxId Id of the mailbox that includes the message
     \param updateNeeded Set to <code>true</code> if update needed otherwise not touched
     \param activate Set result value of updateUnreadCount method
  */
-void NmMailAgent::handleMessageChangedEvent(const NmId &folderId, const NmId &mailboxId,
+void NmMailAgent::handleMessageChangedEvent(const NmId &folderId, 
+    const QList<NmId> &messageIds,
+    const NmId &mailboxId,
     bool &updateNeeded, bool &activate)
 {
     NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
 
+    // we are interested only about changes in the inbox
     if (folderId == mailboxInfo->mInboxFolderId) {
         mailboxInfo->mInboxChangedMessages++;
-    }
-
-    // If not currently syncronizing the mailbox, this may mean
-    // that a message was read/unread
-    if (mailboxInfo && mailboxInfo->mSyncState == SyncComplete) {
 
-        // check the unread status again
-        int oldCount(mailboxInfo->mUnreadMailIdList.count());
-        activate = updateUnreadCount(mailboxId, *mailboxInfo);
+        // If not currently syncronizing the mailbox, this may mean
+        // that a message was read/unread
+        if (mailboxInfo && mailboxInfo->mSyncState == SyncComplete) {
+            // If there was no unread mails in the list, do nothing
+            int oldCount(mailboxInfo->mUnreadMailIdList.count());
+            if (oldCount>0) {
+                // Check how many messages were unread earlier
+                int unreadMessages = 0;
+                foreach (NmId messageId, messageIds) {
+                    if (mailboxInfo->mUnreadMailIdList.indexOf(messageId)>=0) {
+                        unreadMessages++;
+                    }
+                }
 
-        // new unread mails found or no more unread mails in the inbox
-        if (oldCount>0 && mailboxInfo->mUnreadMailIdList.count()==0) {
-            updateNeeded = true;
+                // Could lead the count drop to 0 => mailbox will be hidden
+                if (unreadMessages > 0) {
+                    // check the unread status again
+                    activate = updateUnreadCount(mailboxId, *mailboxInfo);
+
+                    // no more unread mails in the inbox
+                    if (mailboxInfo->mUnreadMailIdList.count()==0) {
+                        NM_COMMENT("NmMailAgent:handleMessageChangedEvent - no more unread msgs");
+                        updateNeeded = true;
+                    }
+                }
+            }
         }
     }
 }
@@ -720,7 +738,7 @@
                 if (!mailboxInfo) {
                     // Unable to initialise the mailbox. Try again later.
                     NM_COMMENT("Cannot initialise mailbox");
-                    
+
                     qRegisterMetaType<NmId>("NmId");
                     QMetaObject::invokeMethod(this, "delayedMailboxCreated",
                         Qt::QueuedConnection, Q_ARG(NmId,mailboxId));
@@ -769,9 +787,9 @@
 }
 
 /*!
-    Called when mailbox is initialised with a delay. This may happen at least when 
+    Called when mailbox is initialised with a delay. This may happen at least when
     NmMailboxCreated event is received.
-    
+
     \param mailboxId id of the mailbox
 */
 void NmMailAgent::delayedMailboxCreated(const NmId mailboxId)
@@ -877,7 +895,7 @@
             break;
         }
         case NmMessageChanged: {
-            handleMessageChangedEvent(folderId, mailboxId, updateNeeded, activate);
+            handleMessageChangedEvent(folderId, messageIds, mailboxId, updateNeeded, activate);
             break;
         }
         case NmMessageDeleted: {