messagingapp/msgappfw/server/src/ccsconversationmarkreadhandler.cpp
changeset 31 ebfee66fde93
child 44 36f374c67aa8
equal deleted inserted replaced
30:6a20128ce557 31:ebfee66fde93
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CS Server Mark read Handler
       
    15 *
       
    16 */
       
    17 // INCLUDES
       
    18 #include <ccsclientconversation.h>
       
    19 #include <ccsconversationentry.h>
       
    20 #include "ccsconversationcache.h"
       
    21 #include "ccsconversationmarkreadhandler.h"
       
    22 #include <mmsconst.h>
       
    23 
       
    24 // ----------------------------------------------------------------------------
       
    25 // CCsConversationMarkReadHandler::NewL
       
    26 // Two Phase Construction
       
    27 // ----------------------------------------------------------------------------
       
    28 CCsConversationMarkReadHandler* CCsConversationMarkReadHandler::
       
    29 NewL(CCsConversationCache* aCache)
       
    30     {
       
    31     CCsConversationMarkReadHandler* self = 
       
    32             new (ELeave) CCsConversationMarkReadHandler();
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL(aCache);
       
    35     CleanupStack::Pop(self); // self
       
    36     return self;
       
    37     }
       
    38 
       
    39 // ----------------------------------------------------------------------------
       
    40 // Constructor
       
    41 // ----------------------------------------------------------------------------
       
    42 CCsConversationMarkReadHandler::CCsConversationMarkReadHandler():
       
    43         CActive(CActive::EPriorityLow)
       
    44     {
       
    45     CActiveScheduler::Add( this );
       
    46     }
       
    47 
       
    48 // ----------------------------------------------------------------------------
       
    49 // Constructor
       
    50 // ----------------------------------------------------------------------------
       
    51 void CCsConversationMarkReadHandler::ConstructL(CCsConversationCache* aCache)
       
    52     {
       
    53     iCache = aCache;
       
    54     iState = EMarkReadIdle;
       
    55        
       
    56     iConversationEntryList = new (ELeave)RPointerArray<CCsConversationEntry> ();  
       
    57     iSession = CMsvSession::OpenSyncL(*this);
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // Destructor
       
    62 // ----------------------------------------------------------------------------
       
    63 CCsConversationMarkReadHandler::~CCsConversationMarkReadHandler()
       
    64 {
       
    65     Cancel();
       
    66     if (iConversationEntryList)
       
    67     {
       
    68 		iConversationEntryList->ResetAndDestroy();
       
    69         iConversationEntryList->Close();
       
    70         delete iConversationEntryList;
       
    71         iConversationEntryList = NULL;
       
    72         
       
    73     }
       
    74 
       
    75     if (iSession)
       
    76     {
       
    77         delete iSession;
       
    78         iSession = NULL;
       
    79         }
       
    80     }
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // Mark set of messages as read
       
    84 // ----------------------------------------------------------------------------
       
    85 void CCsConversationMarkReadHandler::MarkReadL(TInt aConversationId)
       
    86     {
       
    87     // Temp client conversation object
       
    88     CCsClientConversation* clientConversation = CCsClientConversation::NewL();
       
    89     clientConversation->SetConversationEntryId(aConversationId);
       
    90     CleanupStack::PushL(clientConversation);
       
    91 
       
    92     // Get conversationlist for given client conversation
       
    93     iCache->GetConversationsL (clientConversation, iConversationEntryList);
       
    94     
       
    95     iMarkReadCount = 0;
       
    96     
       
    97     // Cleanup  
       
    98     CleanupStack::PopAndDestroy(clientConversation);
       
    99         
       
   100     iState = EMarkReadStart;
       
   101     IssueRequest();
       
   102     }
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // Mark read a message
       
   106 // ----------------------------------------------------------------------------
       
   107 void CCsConversationMarkReadHandler::MarkReadOneMessageL()
       
   108     {
       
   109     CCsConversationEntry* entry = 
       
   110             static_cast<CCsConversationEntry*>((*iConversationEntryList)[iMarkReadCount]);    
       
   111   
       
   112     if ( entry->IsAttributeSet(ECsAttributeNew) ||
       
   113          entry->IsAttributeSet(ECsAttributeUnread) )
       
   114         {    
       
   115         TInt id = entry->EntryId();          
       
   116         
       
   117         CMsvEntry* cEntry = NULL;
       
   118         TRAPD(err, cEntry = iSession->GetEntryL(id));
       
   119         if ( err == KErrNotFound )
       
   120            return;
       
   121         CleanupStack::PushL(cEntry);
       
   122         	
       
   123         TMsvEntry entry = cEntry->Entry();
       
   124         if ( entry.Unread() ) 
       
   125            {
       
   126            // Mark the entry as read
       
   127             if(entry.iMtm != KUidMsgTypeMultimedia)
       
   128             {
       
   129                 entry.SetUnread( EFalse );
       
   130                 cEntry->ChangeL( entry );
       
   131             }
       
   132            }
       
   133         CleanupStack::PopAndDestroy(cEntry);
       
   134         }
       
   135     }
       
   136 
       
   137 // ----------------------------------------------------------------------------
       
   138 // RunL
       
   139 // ----------------------------------------------------------------------------
       
   140 void CCsConversationMarkReadHandler::RunL()
       
   141     {
       
   142     switch ( iState )
       
   143         {
       
   144         case EMarkReadStart:
       
   145             if ( iConversationEntryList->Count() > 0 )
       
   146                 {
       
   147                 iMarkReadCount = iConversationEntryList->Count();
       
   148                 iState = EMarkReadNext;
       
   149                 IssueRequest();
       
   150                 }
       
   151             else
       
   152                 {
       
   153                 iState = EMarkReadComplete;
       
   154                 IssueRequest();
       
   155                 }
       
   156             break;
       
   157         
       
   158         case EMarkReadNext:
       
   159             iMarkReadCount--;
       
   160             MarkReadOneMessageL();
       
   161             if ( iMarkReadCount > 0 )
       
   162                 {
       
   163                 iState = EMarkReadNext;
       
   164                 IssueRequest();
       
   165                 }
       
   166             else
       
   167                 {
       
   168                 iState = EMarkReadComplete;
       
   169                 IssueRequest();
       
   170                 }
       
   171             break;
       
   172             
       
   173         case EMarkReadComplete:
       
   174             // Cleanup, this is the last call RunL is not activated again.
       
   175             delete this;
       
   176             break;
       
   177     }
       
   178 }
       
   179 
       
   180 TInt CCsConversationMarkReadHandler::RunError(TInt aError)
       
   181 {
       
   182     // RunL left so stop processing the AO and clean it.
       
   183     delete this;                     
       
   184     return KErrNone;
       
   185 }
       
   186 
       
   187 // ----------------------------------------------------------------------------
       
   188 // DoCancel
       
   189 // ----------------------------------------------------------------------------
       
   190 void CCsConversationMarkReadHandler::DoCancel()
       
   191     {
       
   192     // Not supported
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // Move to next state
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CCsConversationMarkReadHandler::IssueRequest()
       
   200     {
       
   201     if( !IsActive() )
       
   202         {
       
   203         iStatus = KRequestPending;
       
   204         TRequestStatus* status = &iStatus;
       
   205         SetActive();
       
   206         User::RequestComplete(status, KErrNone);
       
   207         }
       
   208     }
       
   209 
       
   210 // EOF