messagingapp/msgappfw/server/src/ccsconversationcachehelper.cpp
branchRCL_3
changeset 57 ebe688cedc25
equal deleted inserted replaced
54:fa1df4b99609 57:ebe688cedc25
       
     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:  This class helps CS Cache in processing the data.
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 // SYSTEM INCLUDE FILES
       
    20 #include <ccsdefs.h>
       
    21 #include <ccsconversationentry.h>
       
    22 #include <ccsclientconversation.h>
       
    23 
       
    24 // USER INCLUDE FILES
       
    25 #include "ccsconversationcachehelper.h"
       
    26 #include "ccsconversationcache.h"
       
    27 #include "ccsconversation.h"
       
    28 #include "ccsconversationentry.h"
       
    29 #include "ccsconversationevent.h"
       
    30 #include "ccscontactsmanager.h"
       
    31 #include "ccscontactsresolver.h"
       
    32 #include <xqconversions.h>
       
    33 #include "ccsdebug.h"
       
    34 
       
    35 // ============================== MEMBER FUNCTIONS ============================
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // CCsConversationCacheHelper::NewL
       
    39 // Two Phase Construction
       
    40 // ----------------------------------------------------------------------------
       
    41 CCsConversationCacheHelper*
       
    42 CCsConversationCacheHelper::NewL(CCsConversationCache* aConversationCache)
       
    43 {
       
    44     PRINT ( _L("Enter CCsConversationCacheHelper::NewL") );
       
    45 
       
    46     CCsConversationCacheHelper* self =
       
    47             new (ELeave) CCsConversationCacheHelper(aConversationCache);
       
    48 
       
    49     CActiveScheduler::Add(self);
       
    50     CleanupStack::PushL(self);
       
    51     self->ConstructL();
       
    52     CleanupStack::Pop(self);
       
    53 
       
    54     PRINT ( _L("End CCsConversationCacheHelper::NewL") );
       
    55 
       
    56     return self;
       
    57 }
       
    58 
       
    59 // ----------------------------------------------------------------------------
       
    60 // CCsConversationCacheHelper::CCsConversationCacheHelper
       
    61 // Construtor
       
    62 // ----------------------------------------------------------------------------
       
    63 CCsConversationCacheHelper::CCsConversationCacheHelper(
       
    64                                                        CCsConversationCache* aConversationCache) :
       
    65     CActive(EPriorityLow), iConversationCache(aConversationCache)
       
    66 {
       
    67 }
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 // CCsConversationCacheHelper::ConstructL
       
    71 // Second phase constructor
       
    72 // ----------------------------------------------------------------------------
       
    73 void CCsConversationCacheHelper::ConstructL()
       
    74 {
       
    75     iConversationEvent = NULL;
       
    76     iConversationIndex = KErrNotFound;
       
    77     iCurrentConversationIndex = KErrNotFound;
       
    78 
       
    79     //initialize the event list
       
    80     iConversationEventList
       
    81             = new (ELeave) RPointerArray<CCsConversationEvent> ();
       
    82 
       
    83     // now create all special type of conversations
       
    84     // like BT, IRDA, Unknown Drafts etc.
       
    85     TInt loop = 0;
       
    86     for (loop = 0; loop < KMaxSpecialConversations; loop++)
       
    87     {
       
    88         CreateSpecialConversationL();
       
    89     }
       
    90 }
       
    91 
       
    92 // ----------------------------------------------------------------------------
       
    93 // CCsConversationCache::CreateSpecialConversationL
       
    94 // Second part of constructL
       
    95 // This shall create all special type of messages like BT, Unknown Draft, IRDA etc.
       
    96 // Pls note this shall be placed by order at starting of cache
       
    97 // ----------------------------------------------------------------------------
       
    98 void CCsConversationCacheHelper::CreateSpecialConversationL()
       
    99 {
       
   100     // Create a conversation for Drafts Unknown case and set it in
       
   101     // 0th position and the conversation Id for drafts unknown case is
       
   102     // KDratsUnknownConversationId
       
   103     CCsConversation* conversation = CCsConversation::NewL();
       
   104 
       
   105     conversation->SetConversationId(GetNextRowId());
       
   106 
       
   107     // add into the list
       
   108     iConversationCache->ConversationList()->AppendL(conversation);
       
   109 }
       
   110 
       
   111 // ----------------------------------------------------------------------------
       
   112 // CCsConversationCacheHelper::CCsConversationCacheHelper
       
   113 // Destructor
       
   114 // ----------------------------------------------------------------------------
       
   115 CCsConversationCacheHelper::~CCsConversationCacheHelper()
       
   116 {
       
   117     Cancel();
       
   118 
       
   119     // delete the event list
       
   120     if (iConversationEventList)
       
   121     {
       
   122         iConversationEventList->ResetAndDestroy();
       
   123         iConversationEventList->Close();
       
   124         delete iConversationEventList;
       
   125         iConversationEventList = NULL;
       
   126     }
       
   127 }
       
   128 // -----------------------------------------------------------------------------
       
   129 // CCsConversationCacheHelper::DoCancel()
       
   130 // DoCancel implementation from CActive Object
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CCsConversationCacheHelper::DoCancel()
       
   134 {
       
   135     // do nothing    
       
   136 }
       
   137 // ----------------------------------------------------------------------------
       
   138 // CCsConversationCacheHelper::Run
       
   139 // Called from the scheduler
       
   140 // ----------------------------------------------------------------------------
       
   141 void CCsConversationCacheHelper::RunL()
       
   142 {
       
   143     switch (iState)
       
   144     {
       
   145         case ECsProcessConversation:
       
   146         {
       
   147             HandleProcessConversationL();
       
   148         }
       
   149             break;
       
   150 
       
   151         case ECsSpecialConversation:
       
   152         {
       
   153             HandleSpecialConversationL();
       
   154         }
       
   155             break;
       
   156 
       
   157         case ECsConversationFoundInCache:
       
   158         {
       
   159             HandleConversationInCacheL();
       
   160         }
       
   161             break;
       
   162 
       
   163         case ECsResolveConversation:
       
   164         {
       
   165             ResolveContact(iConversationEvent);
       
   166         }
       
   167             break;
       
   168     }
       
   169 }
       
   170 // ----------------------------------------------------------------------------
       
   171 // CCsConversationCacheHelper::StartCacheUpdate
       
   172 // this shall start looking at cache data and update if entry already exist
       
   173 // shall put request to phonebook in case new data
       
   174 // ----------------------------------------------------------------------------
       
   175 void CCsConversationCacheHelper::StartCacheUpdate()
       
   176 {
       
   177     iState = ECsProcessConversation;
       
   178     IssueRequest();
       
   179 }
       
   180 // ---------------------------------------------------------------------------
       
   181 // CCsConversationCacheHelper::HandleProcessConversationL()
       
   182 // Process Conversation and update cache
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 void CCsConversationCacheHelper::HandleProcessConversationL()
       
   186 {
       
   187     iConversationEvent = GetNextEvent();
       
   188     // check to see if all the events are consumed
       
   189     // then mark cache as caching done..
       
   190     if (!iConversationEvent)
       
   191     {
       
   192         iConversationCache->CachingCompletedL();
       
   193         return;
       
   194     }
       
   195 
       
   196     CCsConversationEntry* conEntry =
       
   197             iConversationEvent->ClientConversation()->GetConversationEntry();
       
   198 
       
   199     //handle add, modify events
       
   200     if (iConversationEvent->Event() != KConversationEventDelete)
       
   201     {
       
   202         TUint8 SpecialId = NeedsSpecialProcessing(conEntry);
       
   203 
       
   204         if (SpecialId)
       
   205         {
       
   206             // this is for draft(unlnown)/BT/IR processing            
       
   207             iState = ECsSpecialConversation;
       
   208         }
       
   209         // check only if contact is a valid address
       
   210         else if (conEntry->Contact())
       
   211         {
       
   212             iCurrentConversationIndex
       
   213                     = iConversationCache->FindConversation(* (conEntry->Contact()));
       
   214             if (iCurrentConversationIndex != KErrNotFound)
       
   215             {
       
   216                 iState = ECsConversationFoundInCache;
       
   217             }
       
   218             else
       
   219             {
       
   220                 iState = ECsResolveConversation;
       
   221             }
       
   222         }
       
   223         else
       
   224         {
       
   225             // this is when contact number is NULL
       
   226             // delete the entry from temp list
       
   227             DeleteEvent(*iConversationEvent);
       
   228             iState = ECsProcessConversation;
       
   229         }
       
   230     }
       
   231     else
       
   232     {
       
   233         //handle delete event
       
   234         DeleteConversationEntryL(conEntry);
       
   235         DeleteEvent(*iConversationEvent);
       
   236         iState = ECsProcessConversation;
       
   237     }
       
   238     //move to other state
       
   239     IssueRequest();
       
   240 }
       
   241 // ---------------------------------------------------------------------------
       
   242 // CCsConversationCacheHelper::HandleSpecialConversationL()
       
   243 // Hnadle the case when the conversation has no contact,
       
   244 // BlueTooth/IrDa messages
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 void CCsConversationCacheHelper::HandleSpecialConversationL()
       
   248 {
       
   249     CCsConversationEntry* conEntry =
       
   250         iConversationEvent->ClientConversation()->GetConversationEntry();
       
   251 
       
   252     if (ECsBlueTooth == conEntry->GetType()|| ECsBlueTooth_VCard == conEntry->GetType()|| ECsBlueTooth_VCal == conEntry->GetType())
       
   253     {
       
   254         AddConversationEntryL(conEntry, KBluetoothMsgsConversationId);
       
   255     }
       
   256     else
       
   257     {
       
   258         AddConversationEntryL(conEntry, KUnknownConversationId);
       
   259     }
       
   260     DeleteEvent(*iConversationEvent);
       
   261     iState = ECsProcessConversation;
       
   262     IssueRequest();
       
   263 
       
   264     PRINT ( _L("CCsConversationCacheHelper::HandleSpecialConversationL") );
       
   265 }
       
   266 // ---------------------------------------------------------------------------
       
   267 // CCsConversationCacheHelper::HandleConversationInCacheL()
       
   268 // Handle the case when the conversation is found in the cache
       
   269 // so there is no need for resolving the contact
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 void CCsConversationCacheHelper::HandleConversationInCacheL()
       
   273 {
       
   274     CCsConversationEntry* conEntry =
       
   275             iConversationEvent->ClientConversation()->GetConversationEntry();
       
   276 
       
   277     AddConversationEntryL(conEntry, iCurrentConversationIndex);
       
   278 
       
   279     DeleteEvent(*iConversationEvent);
       
   280 
       
   281     // reset back the conversation index
       
   282     iCurrentConversationIndex = KErrNotFound;
       
   283     iState = ECsProcessConversation;
       
   284     IssueRequest();
       
   285 }
       
   286 // ----------------------------------------------------------------------------
       
   287 // This function identifies if the conentry needs special processing
       
   288 // Drafts message with NULL contact/Bluetooth/IRDA etc
       
   289 // ----------------------------------------------------------------------------
       
   290 TUint8 CCsConversationCacheHelper::NeedsSpecialProcessing(
       
   291                                                           CCsConversationEntry* aConversationEntry)
       
   292 {
       
   293     if (ECsBlueTooth == aConversationEntry->GetType() || ECsBlueTooth_VCard == aConversationEntry->GetType() || ECsBlueTooth_VCal == aConversationEntry->GetType())
       
   294     {
       
   295         return 1;
       
   296     }
       
   297     return 0;
       
   298 }
       
   299 
       
   300 // ---------------------------------------------------------------------------
       
   301 // Move to next state
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 void CCsConversationCacheHelper::IssueRequest()
       
   305 {
       
   306     if (!IsActive())
       
   307     {
       
   308         iStatus = KRequestPending;
       
   309         TRequestStatus* status = &iStatus;
       
   310         SetActive();
       
   311         User::RequestComplete(status, KErrNone);
       
   312     }
       
   313 }
       
   314 
       
   315 // ----------------------------------------------------------------------------
       
   316 // CCsConversationCacheHelper::ContactResolved
       
   317 // Handle a contact resolved in the contact database
       
   318 // ----------------------------------------------------------------------------
       
   319 void CCsConversationCacheHelper::ResolveContact(
       
   320                                                 CCsConversationEvent* aConverastionEvent)
       
   321 {
       
   322     CCsContactDetail contactDetail;
       
   323 
       
   324     //get contact from event
       
   325     CCsConversationEntry* ConvEntry =
       
   326             aConverastionEvent->ClientConversation()->GetConversationEntry();
       
   327 
       
   328     if (ConvEntry)
       
   329     {
       
   330         HBufC* Contact = ConvEntry->Contact();
       
   331         if (Contact)
       
   332         {
       
   333             QString contactAddress =
       
   334                     XQConversions::s60DescToQString(Contact->Des());
       
   335 
       
   336             iConversationCache->ContactsManager()->resolver()->resolveContact(contactAddress,
       
   337                                                                               contactDetail);
       
   338 
       
   339             int contactId = contactDetail.contactId;
       
   340             TInt cIndex = iConversationCache->FindConversation(contactId);
       
   341 
       
   342             if (cIndex == KErrNotFound)
       
   343             {
       
   344                 // Add as new conversation
       
   345                 HBufC* displayName = NULL;
       
   346                 if(!contactDetail.displayName.isEmpty())
       
   347                 {
       
   348                     displayName=XQConversions::qStringToS60Desc(contactDetail.displayName);
       
   349                 }
       
   350                 TRAPD(error, AddNewConversationL( aConverastionEvent->
       
   351                                 ClientConversation()->GetConversationEntry(),
       
   352                                 contactId,
       
   353                                 displayName));
       
   354 
       
   355                 if (displayName) delete displayName;                
       
   356 
       
   357                 if (error != KErrNone)
       
   358                 {
       
   359                     // handle error
       
   360                 }
       
   361             }
       
   362             else
       
   363             {
       
   364                 // this is when two contacts are having same contact Id,
       
   365                 // in that case it should add into an existing conversation
       
   366                 TRAPD(error, AddConversationEntryL( 
       
   367                         aConverastionEvent->ClientConversation(
       
   368                                 )->GetConversationEntry(), cIndex));
       
   369                 if (error != KErrNone)
       
   370                 {
       
   371                     // handle error
       
   372                 }
       
   373             }
       
   374 
       
   375             // now remove the entry from event list
       
   376             DeleteEvent(*aConverastionEvent);
       
   377 
       
   378             // call start update cache
       
   379             StartCacheUpdate();
       
   380         }
       
   381     }
       
   382 }
       
   383 
       
   384 // ----------------------------------------------------------------------------
       
   385 // Handles the case where conversation is already in cache
       
   386 // This will add new conversation entry into the corresponding conversation
       
   387 // pls note there is already a conversation exist for this entry
       
   388 // hence this entry gets appended inside conversation list
       
   389 // ----------------------------------------------------------------------------
       
   390 void CCsConversationCacheHelper::AddConversationEntryL(
       
   391                                                        CCsConversationEntry *aConEntry,
       
   392                                                        TInt aConversationIndex)
       
   393 {
       
   394     RPointerArray<CCsConversation>* conversationList =
       
   395             iConversationCache->ConversationList();
       
   396 
       
   397     CCsConversation* conversation = (*conversationList)[aConversationIndex];
       
   398 
       
   399     CCsConversationEntry* prevLatestEntry = conversation->GetLatestEntryL();
       
   400 
       
   401     if (prevLatestEntry)
       
   402     {
       
   403         prevLatestEntry = prevLatestEntry->CloneL();
       
   404     }
       
   405     else
       
   406     {
       
   407         prevLatestEntry = aConEntry->CloneL();
       
   408     }
       
   409 
       
   410     CleanupStack::PushL(prevLatestEntry);
       
   411 
       
   412     // save the previous unread message count
       
   413     TUint16 prevUnreadCount = conversation->GetUnreadMessageCount();
       
   414 
       
   415     TUint32 event;
       
   416     conversation->UpdateEntryL(aConEntry, event);
       
   417 
       
   418     // Send update notify to conversation list
       
   419     if (IsNotifyRequiredL(conversation,
       
   420                           prevLatestEntry,
       
   421                           KConversationListEventUpdate,
       
   422                           prevUnreadCount))
       
   423     {
       
   424         CCsConversationEntry* convEntry = conversation->GetLatestEntryL();
       
   425         CCsClientConversation* clientConvLatest =
       
   426                 iConversationCache->CreateClientConvLC(conversation, convEntry);
       
   427         
       
   428         // THIS IS USED FOR SHOWING NOTIFICATIONS. NOTIFICATION IS SHOWN ONLY
       
   429         // WHEN ECsAttributeNewEntryAdded IS SET. 
       
   430         if(iConversationEvent->IsUpdateConversationEventSet() 
       
   431                 && event == KConversationEventNew)
       
   432             {
       
   433             clientConvLatest->GetConversationEntry()->
       
   434             ChangeAttributes(ECsAttributeNewEntryAdded,ECsAttributeNone);
       
   435             }
       
   436         
       
   437         iConversationCache->NotifyL(clientConvLatest,
       
   438                                     KConversationListEventUpdate);
       
   439         CleanupStack::PopAndDestroy(clientConvLatest);
       
   440     }
       
   441 
       
   442     // Send update notify to conversations
       
   443     CCsClientConversation* clientConv =
       
   444             iConversationCache->CreateClientConvLC(conversation, aConEntry);
       
   445     iConversationCache->NotifyL(clientConv, event);
       
   446 
       
   447     // Cleanup
       
   448     CleanupStack::PopAndDestroy(clientConv);
       
   449     CleanupStack::PopAndDestroy(prevLatestEntry);
       
   450 }
       
   451 
       
   452 // ----------------------------------------------------------------------------
       
   453 // CCsConversationCache::DeleteConversationL
       
   454 // Delete conversation entry from conversation list
       
   455 // there are few checks of how to notify the UI about the changes 
       
   456 // for the various use cases. 
       
   457 // Delete requires the conversation Id and type (SMS, MMS etc.)
       
   458 // ----------------------------------------------------------------------------
       
   459 void CCsConversationCacheHelper::DeleteConversationEntryL(
       
   460                                                           CCsConversationEntry* aConversationEntry)
       
   461 {
       
   462     // For MMS, search the entry inside all conversations and delete.
       
   463     // For SMS, stop on first match.
       
   464     TBool stopOnFirstMatch = ETrue;
       
   465 
       
   466     RPointerArray<CCsConversation>* conversationList =
       
   467             iConversationCache->ConversationList();
       
   468 
       
   469     // the deletion needs search the entryId inside whole conversation
       
   470     // search the entry id and delete the entry
       
   471     for (TInt loop = 0; loop < iConversationCache->ConversationList()->Count(); loop++)
       
   472     {
       
   473         CCsConversation* conversation =
       
   474                 static_cast<CCsConversation*> ( (*conversationList)[loop]);
       
   475 
       
   476         TInt indexDeletion = conversation->FindEntry(aConversationEntry);
       
   477 
       
   478         if (indexDeletion != KErrNotFound)
       
   479         {
       
   480             // Get the entry from cache to check the type
       
   481             CCsConversationEntry* cacheEntry =
       
   482                     conversation->GetEntryL(indexDeletion);
       
   483 
       
   484             if (cacheEntry->GetType() == ECsMMS || cacheEntry->GetType()
       
   485                     == ECsAudio)
       
   486             {
       
   487                 stopOnFirstMatch = EFalse;
       
   488             }
       
   489             
       
   490             TUint16 prevUnreadCount = conversation->GetUnreadMessageCount();
       
   491 
       
   492             // Delete the conversation entry from this conversation
       
   493             conversation->DeleteEntryL(indexDeletion);
       
   494 
       
   495             // Notify client of conversation list change.
       
   496             if (IsNotifyRequiredL(conversation,
       
   497                                   aConversationEntry,
       
   498                                   KConversationListEventDelete,
       
   499                                   prevUnreadCount))
       
   500             {
       
   501                 // Delete
       
   502                 CCsClientConversation
       
   503                         * clientConv =
       
   504                                 iConversationCache->CreateClientConvLC(conversation,
       
   505                                                                        aConversationEntry);
       
   506                 iConversationCache->NotifyL(clientConv,
       
   507                                             KConversationListEventDelete);
       
   508                 CleanupStack::PopAndDestroy(clientConv);
       
   509 
       
   510                 // Update with latest entry
       
   511                 CCsConversationEntry* conEntry =
       
   512                         conversation->GetLatestEntryL();
       
   513                 if (conEntry)
       
   514                 {
       
   515                     CCsClientConversation
       
   516                             * clientConv =
       
   517                                     iConversationCache->CreateClientConvLC(conversation,
       
   518                                                                            conEntry);
       
   519                     iConversationCache->NotifyL(clientConv,
       
   520                                                 KConversationListEventNew);
       
   521                     CleanupStack::PopAndDestroy(clientConv);
       
   522                 }
       
   523             }
       
   524 
       
   525             // Notify client of conversation change
       
   526             if (!conversation->IsDeleted())
       
   527             {
       
   528                 CCsClientConversation
       
   529                         * clientConv =
       
   530                                 iConversationCache->CreateClientConvLC(conversation,
       
   531                                                                        aConversationEntry);
       
   532                 iConversationCache->NotifyL(clientConv,
       
   533                                             KConversationEventDelete);
       
   534                 CleanupStack::PopAndDestroy(clientConv);
       
   535             }
       
   536 
       
   537             // check if all entries are deleted then 
       
   538             // delete the conversation from cache
       
   539             if (conversation->GetEntryCount() == 0
       
   540                     && !conversation->IsSpecialConversation())
       
   541             {
       
   542             
       
   543             conversationList->Remove(loop);
       
   544             delete conversation;
       
   545             //reset the counters
       
   546             loop -= 1;
       
   547             }
       
   548 
       
   549             // Stop searching    
       
   550             if (stopOnFirstMatch) break;
       
   551         }
       
   552     } // for
       
   553 }
       
   554 
       
   555 // ----------------------------------------------------------------------------
       
   556 // CCsConversationCacheHelper::AddNewConversationL
       
   557 // add new conversation into cache
       
   558 // this shall be called after resolving entry from phonebook
       
   559 // ----------------------------------------------------------------------------
       
   560 void CCsConversationCacheHelper::AddNewConversationL(
       
   561                                                      CCsConversationEntry* aConversationEntry,
       
   562                                                      TInt32 aContactId,
       
   563                                                      const HBufC* aDisplayName)
       
   564 {
       
   565     CCsConversation* conversation = CCsConversation::NewL();
       
   566     CleanupStack::PushL(conversation);
       
   567 
       
   568     //set conversation entry id
       
   569     // by default just set the count of list as of now, as it will be unique
       
   570     conversation->SetConversationId(GetNextRowId());
       
   571 
       
   572     // add the conversation entry
       
   573     conversation->AddEntryL(aConversationEntry);
       
   574 
       
   575     // fill firstname and lastname and contact Id
       
   576     if(aDisplayName)
       
   577    		conversation->AddContactDetailsL(aContactId,
       
   578                                      aDisplayName);
       
   579 
       
   580     // fill the phone number
       
   581     if (aConversationEntry->Contact())
       
   582     {
       
   583         conversation->AddContactDetailsL(* (aConversationEntry->Contact()));
       
   584     }
       
   585 
       
   586     // add into the list
       
   587     iConversationCache->ConversationList()->AppendL(conversation);
       
   588 
       
   589     // Send add notify to conversation list
       
   590     CCsClientConversation* clientConv =
       
   591             iConversationCache->CreateClientConvLC(conversation,
       
   592                                                    aConversationEntry);
       
   593     
       
   594     // THIS IS USED FOR SHOWING NOTIFICATIONS. NOTIFICATION IS SHOWN ONLY
       
   595     // WHEN ECsAttributeNewEntryAdded IS SET.
       
   596     if(iConversationEvent->IsUpdateConversationEventSet()) 
       
   597         {
       
   598         clientConv->GetConversationEntry()->
       
   599         ChangeAttributes(ECsAttributeNewEntryAdded,ECsAttributeNone);
       
   600         }
       
   601 
       
   602     iConversationCache->NotifyL(clientConv, KConversationListEventNew);
       
   603     // send the new conversation event as well, so that if there are nay listeners for the cv
       
   604     // then they will get the notification.
       
   605     iConversationCache->NotifyL(clientConv, KConversationEventNew);
       
   606     CleanupStack::PopAndDestroy(clientConv);
       
   607 
       
   608     CleanupStack::Pop(conversation);
       
   609 
       
   610     PRINT ( _L("CCsConversationCacheHelper::AddNewConversationL - Conversation Added") );
       
   611 }
       
   612 
       
   613 // ----------------------------------------------------------------------------
       
   614 // CCsConversationCache::GetPendingEventCount
       
   615 // Pending event count
       
   616 // ----------------------------------------------------------------------------
       
   617 TInt CCsConversationCacheHelper::GetPendingEventCount()
       
   618 {
       
   619     return iConversationEventList->Count();
       
   620 }
       
   621 
       
   622 // ---------------------------------------------------------------------------
       
   623 // Get next event from event list
       
   624 // ---------------------------------------------------------------------------
       
   625 //
       
   626 CCsConversationEvent* CCsConversationCacheHelper::GetNextEvent()
       
   627 {
       
   628     // check in case there are no events in cache
       
   629     if (iConversationEventList->Count() > 0)
       
   630     {
       
   631         return (*iConversationEventList)[0];
       
   632     }
       
   633     return NULL;
       
   634 }
       
   635 
       
   636 // ---------------------------------------------------------------------------
       
   637 // Find CCsConversationEvent from event Q based on ConversationEntryId.
       
   638 // ---------------------------------------------------------------------------
       
   639 TInt CCsConversationCacheHelper::FindEvent(
       
   640                                            const CCsConversationEvent& aConvEvent)
       
   641 {
       
   642     // find the event inside event list and send the index
       
   643     // KErrNotFound in  case None
       
   644     TInt
       
   645             index =
       
   646                     iConversationEventList->Find(&aConvEvent,
       
   647                                                  CCsConversationEvent::CompareByEntryId);
       
   648 
       
   649     return index;
       
   650 }
       
   651 
       
   652 // ----------------------------------------------------------------------------
       
   653 // CCsConversationCache::GetNextRowId
       
   654 // Get the conversation list count where to add next conversation
       
   655 // ----------------------------------------------------------------------------
       
   656 TInt16 CCsConversationCacheHelper::GetNextRowId()
       
   657 {
       
   658     // increment the index and return
       
   659     iConversationIndex++;
       
   660     return iConversationIndex;
       
   661 }
       
   662 
       
   663 // ---------------------------------------------------------------------------
       
   664 // Find CCsConversationEvent based on ConversationEntryId and delete it.
       
   665 // ---------------------------------------------------------------------------
       
   666 //
       
   667 void CCsConversationCacheHelper::DeleteEvent(
       
   668                                              const CCsConversationEvent& aConvEvent)
       
   669 {
       
   670     TInt index = FindEvent(aConvEvent);
       
   671 
       
   672     if (KErrNotFound != index)
       
   673     {
       
   674         CCsConversationEvent* conversationEvent =
       
   675                 (*iConversationEventList)[index];
       
   676         iConversationEventList->Remove(index);
       
   677         delete conversationEvent;
       
   678     }
       
   679 }
       
   680 
       
   681 // ----------------------------------------------------------------------------
       
   682 // CCsConversationCache::IsNotifyRequiredL
       
   683 // checks whether notification for conversation list is required
       
   684 // ----------------------------------------------------------------------------
       
   685 TBool CCsConversationCacheHelper::IsNotifyRequiredL(
       
   686                                                     CCsConversation* aConversation,
       
   687                                                     CCsConversationEntry* aConversationEntry,
       
   688                                                     TUint32 aEvent,
       
   689                                                     TUint16 aPreviousUnreadMsgsCount)
       
   690 {
       
   691     TUint16 presentUnreadMessageCount = aConversation->GetUnreadMessageCount();
       
   692     CCsConversationEntry* latestEntry = aConversation->GetLatestEntryL();
       
   693 
       
   694     // Add & Update
       
   695     if (aEvent & KConversationListEventNew || aEvent
       
   696             & KConversationListEventUpdate)
       
   697     {
       
   698         // Check whether deleted is ongoing. Don't Notify.
       
   699         if (aConversation->IsDeleted())
       
   700         {
       
   701             return EFalse;
       
   702         }
       
   703 
       
   704         // Check whether latest entry is same and unread count has not changed. Don't Notify.
       
   705         if (CCsConversationEntry::Compare(*latestEntry, *aConversationEntry)
       
   706                 == 0 && (presentUnreadMessageCount == aPreviousUnreadMsgsCount)
       
   707                 && (latestEntry->GetSendState()
       
   708                         == aConversationEntry->GetSendState()))
       
   709         {
       
   710             return EFalse;
       
   711         }
       
   712     }
       
   713 
       
   714     // Delete
       
   715     if (aEvent & KConversationListEventDelete)
       
   716     {
       
   717         // Not Last entry during delete. Don't Notify.
       
   718         if (aConversation->IsDeleted() && aConversation->GetEntryCount() > 0)
       
   719         {
       
   720             return EFalse;
       
   721         }
       
   722     }
       
   723 
       
   724     // Notify.
       
   725     return ETrue;
       
   726 }
       
   727 
       
   728 // ----------------------------------------------------------------------------
       
   729 // CCsConversationCacheHelper::ConversationEventList
       
   730 // Pls refer to .h file
       
   731 // ----------------------------------------------------------------------------
       
   732 RPointerArray<CCsConversationEvent>*
       
   733 CCsConversationCacheHelper::ConversationEventList()
       
   734 {
       
   735     return iConversationEventList;
       
   736 }
       
   737 
       
   738 //end of file