messagingapp/msgappfw/server/src/ccsconversationcachehelper.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 37 518b245aa84c
child 47 5b14749788d7
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
   245 // ---------------------------------------------------------------------------
   245 // ---------------------------------------------------------------------------
   246 //
   246 //
   247 void CCsConversationCacheHelper::HandleSpecialConversationL()
   247 void CCsConversationCacheHelper::HandleSpecialConversationL()
   248 {
   248 {
   249     CCsConversationEntry* conEntry =
   249     CCsConversationEntry* conEntry =
   250             iConversationEvent->ClientConversation()->GetConversationEntry();
   250         iConversationEvent->ClientConversation()->GetConversationEntry();
   251 
   251 
   252     if (ECsBlueTooth == conEntry->GetType())
   252     if (ECsBlueTooth == conEntry->GetType())
   253     {
   253     {
   254         AddConversationEntryL(conEntry, KBluetoothMsgsConversationId);
   254         AddConversationEntryL(conEntry, KBluetoothMsgsConversationId);
   255     }
   255     }
   288 // Drafts message with NULL contact/Bluetooth/IRDA etc
   288 // Drafts message with NULL contact/Bluetooth/IRDA etc
   289 // ----------------------------------------------------------------------------
   289 // ----------------------------------------------------------------------------
   290 TUint8 CCsConversationCacheHelper::NeedsSpecialProcessing(
   290 TUint8 CCsConversationCacheHelper::NeedsSpecialProcessing(
   291                                                           CCsConversationEntry* aConversationEntry)
   291                                                           CCsConversationEntry* aConversationEntry)
   292 {
   292 {
   293     if (aConversationEntry->Contact() == NULL
   293     if (ECsBlueTooth == aConversationEntry->GetType())
   294             && aConversationEntry->IsAttributeSet(ECsAttributeDraft))
       
   295     {
   294     {
   296         return 1;
   295         return 1;
   297     }
   296     }
   298     return 0;
   297     return 0;
   299 }
   298 }
   341             TInt cIndex = iConversationCache->FindConversation(contactId);
   340             TInt cIndex = iConversationCache->FindConversation(contactId);
   342 
   341 
   343             if (cIndex == KErrNotFound)
   342             if (cIndex == KErrNotFound)
   344             {
   343             {
   345                 // Add as new conversation
   344                 // Add as new conversation
   346                 HBufC* firstName = NULL;
   345                 HBufC* displayName = NULL;
   347                 if(!contactDetail.firstName.isEmpty())
   346                 if(!contactDetail.displayName.isEmpty())
   348                 {
   347                 {
   349                     firstName=S60QConversions::qStringToS60Desc(contactDetail.firstName);
   348                     displayName=S60QConversions::qStringToS60Desc(contactDetail.displayName);
   350                 }
   349                 }
   351                 HBufC* lastName=NULL;
       
   352                 if(!contactDetail.lastName.isEmpty())
       
   353                 {
       
   354                     lastName=S60QConversions::qStringToS60Desc(contactDetail.lastName);
       
   355                 }
       
   356                 
       
   357                 HBufC* nickName=NULL;
       
   358                 if(!contactDetail.nickName.isEmpty())
       
   359                 {
       
   360                     nickName=S60QConversions::qStringToS60Desc(contactDetail.nickName);
       
   361                 }
       
   362                 
       
   363                 TRAPD(error, AddNewConversationL( aConverastionEvent->
   350                 TRAPD(error, AddNewConversationL( aConverastionEvent->
   364                                 ClientConversation()->GetConversationEntry(),
   351                                 ClientConversation()->GetConversationEntry(),
   365                                 contactId,
   352                                 contactId,
   366                                 firstName,
   353                                 displayName));
   367                                 lastName,
   354 
   368                                 nickName));
   355                 if (displayName) delete displayName;                
   369 
       
   370                 if (firstName) delete firstName;
       
   371                 if (lastName) delete lastName;
       
   372                 if (nickName) delete nickName;
       
   373 
   356 
   374                 if (error != KErrNone)
   357                 if (error != KErrNone)
   375                 {
   358                 {
   376                     // handle error
   359                     // handle error
   377                 }
   360                 }
   378             }
   361             }
   379             else
   362             else
   380             {
   363             {
   381                 // this is when two contacts are having same contact Id,
   364                 // this is when two contacts are having same contact Id,
   382                 // in that case it should add into an existing conversation
   365                 // in that case it should add into an existing conversation
   383                 TRAPD(error, AddConversationEntryL( aConverastionEvent->
   366                 TRAPD(error, AddConversationEntryL( 
   384                                 ClientConversation()->GetConversationEntry(), cIndex));
   367                         aConverastionEvent->ClientConversation(
       
   368                                 )->GetConversationEntry(), cIndex));
   385                 if (error != KErrNone)
   369                 if (error != KErrNone)
   386                 {
   370                 {
   387                     // handle error
   371                     // handle error
   388                 }
   372                 }
   389             }
   373             }
   410     RPointerArray<CCsConversation>* conversationList =
   394     RPointerArray<CCsConversation>* conversationList =
   411             iConversationCache->ConversationList();
   395             iConversationCache->ConversationList();
   412 
   396 
   413     CCsConversation* conversation = (*conversationList)[aConversationIndex];
   397     CCsConversation* conversation = (*conversationList)[aConversationIndex];
   414 
   398 
   415     CCsConversationEntry* prevLatestEntry =
   399     CCsConversationEntry* prevLatestEntry = conversation->GetLatestEntryL();
   416             conversation->GetLatestEntryL()->CloneL();
   400 
       
   401     if (prevLatestEntry)
       
   402     {
       
   403         prevLatestEntry = prevLatestEntry->CloneL();
       
   404     }
       
   405     else
       
   406     {
       
   407         prevLatestEntry = aConEntry->CloneL();
       
   408     }
   417 
   409 
   418     CleanupStack::PushL(prevLatestEntry);
   410     CleanupStack::PushL(prevLatestEntry);
   419 
   411 
   420     // save the previous unread message count
   412     // save the previous unread message count
   421     TUint16 prevUnreadCount = conversation->GetUnreadMessageCount();
   413     TUint16 prevUnreadCount = conversation->GetUnreadMessageCount();
   565 // this shall be called after resolving entry from phonebook
   557 // this shall be called after resolving entry from phonebook
   566 // ----------------------------------------------------------------------------
   558 // ----------------------------------------------------------------------------
   567 void CCsConversationCacheHelper::AddNewConversationL(
   559 void CCsConversationCacheHelper::AddNewConversationL(
   568                                                      CCsConversationEntry* aConversationEntry,
   560                                                      CCsConversationEntry* aConversationEntry,
   569                                                      TInt32 aContactId,
   561                                                      TInt32 aContactId,
   570                                                      const HBufC* aFirstName,
   562                                                      const HBufC* aDisplayName)
   571                                                      const HBufC* aLastName,
       
   572                                                      const HBufC* aNickName)
       
   573 {
   563 {
   574     CCsConversation* conversation = CCsConversation::NewL();
   564     CCsConversation* conversation = CCsConversation::NewL();
   575     CleanupStack::PushL(conversation);
   565     CleanupStack::PushL(conversation);
   576 
   566 
   577     //set conversation entry id
   567     //set conversation entry id
   581     // add the conversation entry
   571     // add the conversation entry
   582     conversation->AddEntryL(aConversationEntry);
   572     conversation->AddEntryL(aConversationEntry);
   583 
   573 
   584     // fill firstname and lastname and contact Id
   574     // fill firstname and lastname and contact Id
   585     conversation->AddContactDetailsL(aContactId,
   575     conversation->AddContactDetailsL(aContactId,
   586                                      *aFirstName,
   576                                      *aDisplayName);
   587                                      *aLastName,
       
   588                                      *aNickName);
       
   589 
   577 
   590     // fill the phone number
   578     // fill the phone number
   591     if (aConversationEntry->Contact())
   579     if (aConversationEntry->Contact())
   592     {
   580     {
   593         conversation->AddContactDetailsL(* (aConversationEntry->Contact()));
   581         conversation->AddContactDetailsL(* (aConversationEntry->Contact()));