messagingapp/msgappfw/server/inc/ccsconversationcache.h
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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 Conversation Cache class. This shall cache
       
    15  *                the conversation/messages from plugins and responds 
       
    16  *                to the server request
       
    17  *
       
    18  */
       
    19 
       
    20 #ifndef __C_CS_CONVERSATION_CACHE_H
       
    21 #define __C_CS_CONVERSATION_CACHE_H
       
    22 
       
    23 // SYSTEM INCLUDE FILES
       
    24 
       
    25 //USER INCLUDES
       
    26 #include "mcscontactsmanagerobserver.h"
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 class CCsConversation;
       
    30 class CCsConversationEntry;
       
    31 class CCsConversationEvent;
       
    32 class CCsClientConversation;
       
    33 class CCsServer;
       
    34 class CCsSession;
       
    35 class CCsConversationCacheHelper;
       
    36 class CCsContactsManager;
       
    37 class CCsContactDetail;
       
    38 
       
    39 // CLASS DECLARATION
       
    40 /** 
       
    41  * CS Conversation Cache main class.
       
    42  * This caches all the conversation from plugins. This is the actual cache of 
       
    43  * server data. Also,Resolves contacts in phonebook and related functionality.
       
    44  */
       
    45 class CCsConversationCache : public CBase, public MCsContactsManagerObserver
       
    46 {
       
    47 
       
    48 public:
       
    49 
       
    50     /**
       
    51      * Two phase construction
       
    52      * 
       
    53      * @param aContactManager CCsContactsManager object reference
       
    54      * @param aCsServer CCsServer object refernce
       
    55      * @return instance of CCsConversationCache
       
    56      */
       
    57     static CCsConversationCache* NewL(CCsContactsManager* aContactManager,
       
    58                                       CCsServer* aCsServer);
       
    59 
       
    60     /**
       
    61      * Destructor
       
    62      */
       
    63     ~CCsConversationCache();
       
    64 
       
    65     /**  
       
    66      * GetConversationListL
       
    67      * Get Conversation list with contact details and latest conversation
       
    68      * for all stored conversations
       
    69      * This API can be used to prepare conversation list
       
    70      * 
       
    71      * @param aClientConversationList list of CCsClientConversations 
       
    72      */
       
    73     void
       
    74             GetConversationListL(
       
    75                                  RPointerArray<CCsClientConversation>* aClientConversationList);
       
    76 
       
    77     /**
       
    78      * GetConversationUnreadListL
       
    79      * Get Conversation list with contact details and unread conversation
       
    80      * for all stored conversations
       
    81      * This API can be used to prepare conversation list
       
    82      *
       
    83      * @param aClientConversationList list of CCsClientConversations
       
    84      */
       
    85     void GetConversationUnreadListL(
       
    86             RPointerArray<CCsClientConversation>* aClientConversationList);
       
    87 
       
    88     /**
       
    89      * GetConversationsL
       
    90      * Gets the Conversation Entries of a given Client Conversation
       
    91      * 
       
    92      * @param aClientConversation object of CCsClientConversation
       
    93      * for which the Converstion entries needs to be fetched
       
    94      * @param aConversationEntryList list of CCsConversationEntries
       
    95      */
       
    96     void
       
    97             GetConversationsL(
       
    98                               const CCsClientConversation* aClientConversation,
       
    99                               RPointerArray<CCsConversationEntry>* aConversationEntryList);
       
   100 
       
   101     /**
       
   102      * HandleConversations
       
   103      * Handle the conversation notification from plugin
       
   104      * 
       
   105      * @param aConversationEntryLists array of conversation entries from pugin
       
   106      * @param aConversationEven an Unsigned number specifying the 
       
   107      * event type   add, update or delete
       
   108      */
       
   109     void
       
   110             HandleConversations(
       
   111                                 const RPointerArray<CCsConversationEntry>& aConversationEntryLists,
       
   112                                 const TUint32 aConversationEvent);
       
   113 
       
   114     /**
       
   115      * Gets the total number of unread conversation entries in all the
       
   116      * Client Conversations.
       
   117      *
       
   118      * @return Total number of unread conversation entries.
       
   119      */
       
   120     TUint32 GetTotalUnreadCount();
       
   121 
       
   122 public:
       
   123 
       
   124     // --------------From MCsContactsManagerObserver--------------------
       
   125 
       
   126     /**
       
   127      * HandleAddContact
       
   128      * This asynchronous callback is invoked when the new contact is added.
       
   129      */
       
   130     void HandleAddContact(CCsContactDetail& aDetail);
       
   131 
       
   132     /**
       
   133      * HandleContactChange
       
   134      * This asynchronous callback is invoked when the contact is changed.
       
   135      */
       
   136     void HandleContactChange(CCsContactDetail& aDetail);
       
   137 
       
   138     /**
       
   139      * HandleDeleteContact
       
   140      * This asynchronous callback is invoked when the contact is deleted.
       
   141      */
       
   142     void HandleDeleteContact(CCsContactDetail& aDetail);
       
   143 
       
   144     // ----- public API's ---------------  
       
   145     /**
       
   146      * MarkConversationAsDeleted
       
   147      * Marks a conversation as being deleted.
       
   148      * 
       
   149      * @param aConversationId Conversation Id.
       
   150      * @param aDeleted ETrue if conversation is being deleted else EFalse
       
   151      */
       
   152     void MarkConversationAsDeleted(TInt aConversationId, TBool aDeleted);
       
   153 
       
   154     /**
       
   155      * IsDeleted
       
   156      * Check if a conversation is being deleted.
       
   157      * 
       
   158      * @param aConversationId Conversation Id.
       
   159      * @return ETrue if deleted.
       
   160      */
       
   161     TBool IsDeleted(TInt aConversationId);
       
   162 
       
   163     /**
       
   164      * ConversationList
       
   165      * Returns the internal conversation list
       
   166      * @return pointer to array of conversations
       
   167      */
       
   168     RPointerArray<CCsConversation>* ConversationList();
       
   169 
       
   170     /**
       
   171      * ContactsManager
       
   172      * This returns the handle of contact manager
       
   173      * @return instance of CCsContactsManager
       
   174      */
       
   175     CCsContactsManager* ContactsManager() const;
       
   176 
       
   177     /**
       
   178      * Get conversation id for a contact id.
       
   179      * @param aContactId The contact id.
       
   180      * @return The conversation id.
       
   181      */
       
   182     TInt GetConversationIdL(TInt aContactId);
       
   183 	
       
   184     /**
       
   185      * Get conversation id for a contact address
       
   186      * @param aContactAddress contact address
       
   187      * @return The conversation id
       
   188      */
       
   189     TInt GetConversationIdFromAddressL(TDesC& aContactAddress);
       
   190 
       
   191 private:
       
   192 
       
   193     /**
       
   194      * private Constructor
       
   195      * 
       
   196      * @param aContactsManager instance of CCsContactsManager
       
   197      * @param aCsServer instance of CCsServer
       
   198      */
       
   199     CCsConversationCache(CCsContactsManager* aContactsManager,
       
   200                          CCsServer* aCsServer);
       
   201 
       
   202     /**
       
   203      * ConstructL
       
   204      * Second phase constructor
       
   205      */
       
   206     void ConstructL();
       
   207 
       
   208 private:
       
   209 
       
   210     /**  
       
   211      * NotifyL
       
   212      * Sends notification to client
       
   213      * 
       
   214      * @param aconversation, details of CCsClientConversation
       
   215      * @param aEvent an integer to specify the type of event
       
   216      * - add modify or delete
       
   217      */
       
   218     void NotifyL(CCsClientConversation* aconversation, TUint32 aEvent);
       
   219 
       
   220     /**
       
   221      * CachingCompleted
       
   222      * Sends the Caching Completed Event to the server,
       
   223      * as the temp list became zero.
       
   224      */
       
   225     void CachingCompletedL();
       
   226 
       
   227     /**
       
   228      * FindConversation 
       
   229      * Finds the conversation depending on the Contact Id
       
   230      * 
       
   231      * @param aContactId given contact link Integer Id
       
   232      * @return KErrNotFound or integer where find found
       
   233      */
       
   234     TInt FindConversation(TInt32 aContactId);
       
   235 
       
   236     /**
       
   237      * FindConversation
       
   238      * Find an associated conversation for a contact.
       
   239      * Contact specified in as a phone number
       
   240      * 
       
   241      * @param aPhoneNumber phone number
       
   242      * @return KErrNotFound or integer where find found
       
   243      */
       
   244     TInt FindConversation(TDesC& aPhoneNumber);
       
   245 
       
   246     /**
       
   247      * Redo the contact resolving for the contact at this index
       
   248      * 
       
   249      * @param index from where to pick conversation for redo the resolving
       
   250      */
       
   251     void RedoResolvingL(TInt aIndex);
       
   252 
       
   253     /**
       
   254      * CreateClientConvL
       
   255      * create CCsConversation from CCsConversation and CCsConversationEntry
       
   256      * 
       
   257      * @param aConversation  CCsConversation object
       
   258      * @param aConversationEntry CCsConversationEntry object
       
   259      * @return instance of CCsClientConversation
       
   260      */
       
   261     CCsClientConversation
       
   262             * CreateClientConvLC(const CCsConversation* aConversation,
       
   263                                  const CCsConversationEntry* aConversationEntry);
       
   264 
       
   265 private:
       
   266 
       
   267     /**
       
   268      * iCsServer
       
   269      * Reference to server (not owned)
       
   270      */
       
   271     CCsServer* iCsServer;
       
   272 
       
   273     /**
       
   274      * iContactsManager 
       
   275      * Contact manager for contact mapping
       
   276      * Not Owned
       
   277      */
       
   278     CCsContactsManager* iContactsManager;
       
   279 
       
   280     /**
       
   281      * iConversationList
       
   282      * Conversation Cache entry list
       
   283      * Own
       
   284      */
       
   285     RPointerArray<CCsConversation>* iConversationList;
       
   286 
       
   287 private:
       
   288     //Friend classes
       
   289 
       
   290     friend class CCsConversationCacheHelper;
       
   291 
       
   292     /** iConversationCacheHelper
       
   293      * This shall be cache helper, an active object which process over all the 
       
   294      * conversation and checks cache for add/update/delete data
       
   295      * In case of new entries, it shall be resolved by Contact Resolver class
       
   296      * 
       
   297      * Own
       
   298      */
       
   299     CCsConversationCacheHelper* iConversationCacheHelper;
       
   300 
       
   301     /**
       
   302      * The amount of digits to be used in contact matching
       
   303      */
       
   304     TInt iMatchDigitCount;
       
   305 };
       
   306 
       
   307 #endif // __C_CS_CONVERSATION_CACHE_H