messagingapp/msgappfw/server/src/ccsconversationmarkreadhandler.cpp
changeset 27 e4592d119491
parent 25 84d9eb65b26f
child 47 5b14749788d7
--- a/messagingapp/msgappfw/server/src/ccsconversationmarkreadhandler.cpp	Mon May 03 12:29:07 2010 +0300
+++ b/messagingapp/msgappfw/server/src/ccsconversationmarkreadhandler.cpp	Fri May 14 15:49:35 2010 +0300
@@ -19,7 +19,6 @@
 #include <ccsconversationentry.h>
 #include "ccsconversationcache.h"
 #include "ccsconversationmarkreadhandler.h"
-#include "mcsconversationmarkreadobserver.h"
 #include <mmsconst.h>
 
 // ----------------------------------------------------------------------------
@@ -27,12 +26,12 @@
 // Two Phase Construction
 // ----------------------------------------------------------------------------
 CCsConversationMarkReadHandler* CCsConversationMarkReadHandler::
-NewL(CCsConversationCache* aCache, MCsConversationMarkReadObserver* aObserver)
+NewL(CCsConversationCache* aCache)
     {
     CCsConversationMarkReadHandler* self = 
             new (ELeave) CCsConversationMarkReadHandler();
     CleanupStack::PushL(self);
-    self->ConstructL(aCache, aObserver);
+    self->ConstructL(aCache);
     CleanupStack::Pop(self); // self
     return self;
     }
@@ -49,13 +48,11 @@
 // ----------------------------------------------------------------------------
 // Constructor
 // ----------------------------------------------------------------------------
-void CCsConversationMarkReadHandler::ConstructL(CCsConversationCache* aCache,
-        MCsConversationMarkReadObserver* aObserver)
+void CCsConversationMarkReadHandler::ConstructL(CCsConversationCache* aCache)
     {
     iCache = aCache;
     iState = EMarkReadIdle;
-    iObserver = aObserver;
-    
+       
     iConversationEntryList = new (ELeave)RPointerArray<CCsConversationEntry> ();  
     iSession = CMsvSession::OpenSyncL(*this);
     }
@@ -64,9 +61,19 @@
 // Destructor
 // ----------------------------------------------------------------------------
 CCsConversationMarkReadHandler::~CCsConversationMarkReadHandler()
+{
+    Cancel();
+    if (iConversationEntryList)
     {
-    if(iSession)
-        {
+		iConversationEntryList->ResetAndDestroy();
+        iConversationEntryList->Close();
+        delete iConversationEntryList;
+        iConversationEntryList = NULL;
+        
+    }
+
+    if (iSession)
+    {
         delete iSession;
         iSession = NULL;
         }
@@ -81,10 +88,7 @@
     CCsClientConversation* clientConversation = CCsClientConversation::NewL();
     clientConversation->SetConversationEntryId(aConversationId);
     CleanupStack::PushL(clientConversation);
-    
-    // Create entry list
-    iConversationEntryList = new (ELeave)RPointerArray<CCsConversationEntry> ();  
-    
+
     // Get conversationlist for given client conversation
     iCache->GetConversationsL (clientConversation, iConversationEntryList);
     
@@ -123,8 +127,8 @@
             if(entry.iMtm != KUidMsgTypeMultimedia)
             {
                 entry.SetUnread( EFalse );
+                cEntry->ChangeL( entry );
             }
-           cEntry->ChangeL( entry );
            }
         CleanupStack::PopAndDestroy(cEntry);
         }
@@ -167,30 +171,17 @@
             break;
             
         case EMarkReadComplete:
-            // Cleanup
-            iMarkReadCount = 0;
-            iConversationEntryList->ResetAndDestroy();
-            iConversationEntryList->Close();
-            delete iConversationEntryList;
-            iConversationEntryList = NULL;  
-            
-            // Notify observers
-            iObserver->MarkReadComplete(this);
+            // Cleanup, this is the last call RunL is not activated again.
+            delete this;
             break;
     }
 }
 
 TInt CCsConversationMarkReadHandler::RunError(TInt aError)
 {
-  iMarkReadCount = 0;
-  iConversationEntryList->ResetAndDestroy();
-  iConversationEntryList->Close();
-  delete iConversationEntryList;
-  iConversationEntryList = NULL;  
-            
-  // Notify observer
-  iObserver->MarkReadComplete(this);
-  return KErrNone;
+    // RunL left so stop processing the AO and clean it.
+    delete this;                     
+    return KErrNone;
 }
 
 // ----------------------------------------------------------------------------