TizenRefApp-7099 Need to improve update algorithm of deleted messages 46/91446/2
authorDmytro Dragan <dm.dragan@samsung.com>
Fri, 7 Oct 2016 12:37:43 +0000 (15:37 +0300)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Wed, 12 Oct 2016 07:25:52 +0000 (00:25 -0700)
Change-Id: I4c8c13da6280b59d1a881ae97a1f8c3bed7fd5f2
Signed-off-by: Dmytro Dragan <dm.dragan@samsung.com>
src/Common/MsgEngine/inc/MsgStorage.h
src/Common/MsgEngine/src/private/MsgStoragePrivate.cpp
src/Common/MsgEngine/src/private/MsgStoragePrivate.h
src/MsgThread/Controller/inc/ThreadList.h
src/MsgThread/Controller/inc/ThreadListItem.h
src/MsgThread/Controller/src/ThreadList.cpp
src/MsgThread/Controller/src/ThreadListItem.cpp

index a16415aa4683b100c175cf780902d6e4d3d8664f..f81efb1e730e7baad6aaa3135dbbae45413c61cc 100644 (file)
@@ -257,6 +257,30 @@ namespace Msg
              * @param[in] msgIdList list of message identifiers relevant to this notification.
              */
             virtual void onMsgStorageContact(const MsgIdList &msgIdList) {};
+
+            /**
+             * @brief Message-storage updates for the given thread.
+             * @param[in] threadId Id of updated conversation.
+             */
+            virtual void onMsgStorageThreadUpdate(const ThreadId &threadId) {};
+
+            /**
+             * @brief Notification about new thread addition.
+             * @param[in] threadId Id of created conversation.
+             */
+            virtual void onMsgStorageThreadInsert(const ThreadId &threadId) {};
+
+            /**
+             * @brief Notification about thread deletion.
+             * @param[in] threadId Id of deleted conversation.
+             */
+            virtual void onMsgStorageThreadDelete(const ThreadId &threadId) {};
+
+            /**
+             * @brief Notifies that recipient stored in contacts was updated.
+             * @param[in] threadId Id of conversation identifier relevant to this notification.
+             */
+            virtual void onMsgStorageThreadContact(const ThreadId &threadId) {};
     };
 }
 
index 9ba14476042bc182ea95938d4f130bcf6b94262e..6b888a09693d5939d6defec93dcec7a017bc7e22 100644 (file)
@@ -36,13 +36,15 @@ MsgStoragePrivate::MsgStoragePrivate(msg_handle_t serviceHandle)
 {
     TRACE;
     msg_reg_storage_change_callback(m_ServiceHandle, msg_storage_change_cb, this);
+    msg_reg_thread_change_callback(m_ServiceHandle, msg_thread_change_cb, this);
 }
 
-void MsgStoragePrivate::notifyListeners(const MsgIdList &idList, ListenerMethod method)
+template <typename T>
+void MsgStoragePrivate::notifyListeners(const T& delta, ListenerMethod<T> method)
 {
     for(auto listener: m_Listeners)
     {
-        (listener->*method)(idList);
+        (listener->*method)(delta);
     }
 }
 
@@ -77,6 +79,29 @@ void MsgStoragePrivate::msg_storage_change_cb(msg_handle_t handle, msg_storage_c
     }
 }
 
+void MsgStoragePrivate::msg_thread_change_cb(msg_handle_t handle, msg_storage_change_type_t storageChangeType, msg_thread_id_t threadId, void *user_param)
+{
+    TRACE;
+    MsgStoragePrivate *self = static_cast<MsgStoragePrivate *>(user_param);
+    ThreadId tId = static_cast<ThreadId>(threadId);
+
+    switch(storageChangeType)
+    {
+        case MSG_STORAGE_CHANGE_UPDATE:
+            self->notifyListeners(tId, &IMsgStorageListener::onMsgStorageThreadUpdate);
+            break;
+        case MSG_STORAGE_CHANGE_INSERT:
+            self->notifyListeners(tId, &IMsgStorageListener::onMsgStorageThreadInsert);
+            break;
+        case MSG_STORAGE_CHANGE_DELETE:
+            self->notifyListeners(tId, &IMsgStorageListener::onMsgStorageThreadDelete);
+            break;
+        case MSG_STORAGE_CHANGE_CONTACT:
+            self->notifyListeners(tId, &IMsgStorageListener::onMsgStorageThreadContact);
+            break;
+    }
+}
+
 MsgStoragePrivate::~MsgStoragePrivate()
 {
 }
index 83ae95b8e569499e6e48bc13d71e7d303e298977..95f69acc128e9aba0621ffb33629c96e2237ca2e 100644 (file)
@@ -71,11 +71,14 @@ namespace Msg
             virtual MsgConversationItemRef getConversationItem(MsgId id);
 
         private:
-            typedef void (IMsgStorageListener::*ListenerMethod)(const MsgIdList &);
+            template <typename T>
+            using ListenerMethod = void (IMsgStorageListener::*)(const T&);
 
-            void notifyListeners(const MsgIdList &idList, ListenerMethod method);
+            template <typename T>
+            void notifyListeners(const T& delta, ListenerMethod<T> method);
 
             static void msg_storage_change_cb(msg_handle_t handle, msg_storage_change_type_t storageChangeType, msg_id_list_s *pMsgIdList, void *user_param);
+            static void msg_thread_change_cb(msg_handle_t handle, msg_storage_change_type_t storageChangeType, msg_thread_id_t threadId, void *user_param);
 
             MessageSMS *createSms();
 
index c32a3288edce805f9335ec6a4f59e4bbe8fdc01b..ea15cd91ac8042f3369bc167500e459fd52f83a0 100644 (file)
@@ -51,9 +51,9 @@ namespace Msg
 
         private:
             // IMsgStorageListener:
-            virtual void onMsgStorageUpdate(const MsgIdList &msgIdList);
-            virtual void onMsgStorageInsert(const MsgIdList &msgIdList);
-            virtual void onMsgStorageDelete(const MsgIdList &msgIdList);
+            virtual void onMsgStorageThreadUpdate(const ThreadId &threadId);
+            virtual void onMsgStorageThreadInsert(const ThreadId &threadId);
+            virtual void onMsgStorageThreadDelete(const ThreadId &threadId);
 
             // IContactManagerListener:
             virtual void onContactChanged();
index c9d07cab6686c0d851ee9c62942ab1c762a8d87c..09916e1c3217ec895c529763e82b1f5aa0423a9d 100644 (file)
@@ -35,8 +35,8 @@ namespace Msg
             virtual ~ThreadListItem();
 
             ThreadId getThreadId() const;
-            void update(const MsgThreadItem &threadItem);
-            void update();
+            void updateModel(const MsgThreadItem &threadItem);
+            void updateModel();
 
         private:
             // ThreadListViewItem:
index fecf8b8d172f287354e319d988a430542722d6cd..2bfb22e731d181b2f6130afe6cbc97835855445f 100644 (file)
@@ -267,7 +267,7 @@ void ThreadList::updateItems()
 void ThreadList::update(ThreadListItem &item)
 {
     time_t time = item.getRawTime();
-    item.update();
+    item.updateModel();
     if(item.getRawTime() < time)
     {
         // TODO: JIRA issue TSAM-8683
@@ -276,6 +276,7 @@ void ThreadList::update(ThreadListItem &item)
     {
         // TODO: JIRA issue TSAM-8683
     }
+    item.update();
 }
 
 std::set<ThreadId> ThreadList::getThreadIdSet(const MsgIdList &idList)
@@ -307,49 +308,35 @@ void ThreadList::onListItemChecked(ListItem &listItem)
         checkHandler(*it);
 }
 
-void ThreadList::onMsgStorageUpdate(const MsgIdList &msgIdList)
+void ThreadList::onMsgStorageThreadUpdate(const ThreadId &threadId)
 {
     MSG_LOG("");
-    updateItems(msgIdList);
+    auto* thread = getItem(threadId);
+    if(thread)
+        update(*thread);
 }
 
-void ThreadList::onMsgStorageInsert(const MsgIdList &msgIdList)
+void ThreadList::onMsgStorageThreadInsert(const ThreadId &threadId)
 {
     MSG_LOG("");
 
-    bool inserted = false;
-    bool updated = false;
-
-    auto threadSet = getThreadIdSet(msgIdList);
-    for(ThreadId id : threadSet)
-    {
-        ThreadListItem *item = getItem(id);
-        if(item)
-        {
-            update(*item);
-            updated = true;
-        }
-        else
-        {
-            insertItem(id);
-            inserted = true;
-        }
-    }
-
-    if(inserted)
-        updateSelectAllItem();
-    if(updated)
-        updateRealizedItems();
+    insertItem(threadId);
+    updateSelectAllItem();
 
     if(m_pListener)
         m_pListener->onThreadListChanged();
 }
 
-void ThreadList::onMsgStorageDelete(const MsgIdList &msgIdList)
+void ThreadList::onMsgStorageThreadDelete(const ThreadId &threadId)
 {
     MSG_LOG("");
-    deleteItems();
-    updateItems(); // TODO: Inefficiently. How to get list of threads by dead msgIdList ?
+    auto* thread = getItem(threadId);
+    if(thread)
+    {
+        ListView::deleteItem(*thread);
+        updateSelectAllItem();
+    }
+
     if(m_pListener)
         m_pListener->onThreadListChanged();
 }
index d64b5f870c8a27e8dd025bb253ac0a135a84edf8..6e59927b5f60b4de8d0a61b014b4accaf9116d79 100644 (file)
@@ -33,7 +33,7 @@ ThreadListItem::ThreadListItem(const MsgThreadItem &threadItem, App &app)
     : BaseThreadListItem(app)
     , m_ThreadId()
 {
-    update(threadItem);
+    updateModel(threadItem);
 }
 
 ThreadListItem::~ThreadListItem()
@@ -55,7 +55,7 @@ Evas_Object *ThreadListItem::getIcon()
     return makeUnreadIcon(m_UnreadCount);
 }
 
-void ThreadListItem::update(const MsgThreadItem &threadItem)
+void ThreadListItem::updateModel(const MsgThreadItem &threadItem)
 {
     m_ThreadId = threadItem.getId();
 
@@ -100,11 +100,11 @@ void ThreadListItem::update(const MsgThreadItem &threadItem)
     updateTime(threadItem.getTime());
 }
 
-void ThreadListItem::update()
+void ThreadListItem::updateModel()
 {
     MsgThreadItemRef msgThread = m_App.getMsgEngine().getStorage().getThread(m_ThreadId);
     if(msgThread)
-        update(*msgThread);
+        updateModel(*msgThread);
 }