From: Dmytro Dragan Date: Fri, 7 Oct 2016 12:37:43 +0000 (+0300) Subject: TizenRefApp-7099 Need to improve update algorithm of deleted messages X-Git-Tag: submit/tizen/20161012.145055~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=de932d0aea43e56f0859163e07ef36b9817e0496;p=profile%2Fmobile%2Fapps%2Fnative%2Fmessage.git TizenRefApp-7099 Need to improve update algorithm of deleted messages Change-Id: I4c8c13da6280b59d1a881ae97a1f8c3bed7fd5f2 Signed-off-by: Dmytro Dragan --- diff --git a/src/Common/MsgEngine/inc/MsgStorage.h b/src/Common/MsgEngine/inc/MsgStorage.h index a16415aa..f81efb1e 100644 --- a/src/Common/MsgEngine/inc/MsgStorage.h +++ b/src/Common/MsgEngine/inc/MsgStorage.h @@ -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) {}; }; } diff --git a/src/Common/MsgEngine/src/private/MsgStoragePrivate.cpp b/src/Common/MsgEngine/src/private/MsgStoragePrivate.cpp index 9ba14476..6b888a09 100644 --- a/src/Common/MsgEngine/src/private/MsgStoragePrivate.cpp +++ b/src/Common/MsgEngine/src/private/MsgStoragePrivate.cpp @@ -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 +void MsgStoragePrivate::notifyListeners(const T& delta, ListenerMethod 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(user_param); + ThreadId tId = static_cast(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() { } diff --git a/src/Common/MsgEngine/src/private/MsgStoragePrivate.h b/src/Common/MsgEngine/src/private/MsgStoragePrivate.h index 83ae95b8..95f69acc 100644 --- a/src/Common/MsgEngine/src/private/MsgStoragePrivate.h +++ b/src/Common/MsgEngine/src/private/MsgStoragePrivate.h @@ -71,11 +71,14 @@ namespace Msg virtual MsgConversationItemRef getConversationItem(MsgId id); private: - typedef void (IMsgStorageListener::*ListenerMethod)(const MsgIdList &); + template + using ListenerMethod = void (IMsgStorageListener::*)(const T&); - void notifyListeners(const MsgIdList &idList, ListenerMethod method); + template + void notifyListeners(const T& delta, ListenerMethod 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(); diff --git a/src/MsgThread/Controller/inc/ThreadList.h b/src/MsgThread/Controller/inc/ThreadList.h index c32a3288..ea15cd91 100644 --- a/src/MsgThread/Controller/inc/ThreadList.h +++ b/src/MsgThread/Controller/inc/ThreadList.h @@ -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(); diff --git a/src/MsgThread/Controller/inc/ThreadListItem.h b/src/MsgThread/Controller/inc/ThreadListItem.h index c9d07cab..09916e1c 100644 --- a/src/MsgThread/Controller/inc/ThreadListItem.h +++ b/src/MsgThread/Controller/inc/ThreadListItem.h @@ -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: diff --git a/src/MsgThread/Controller/src/ThreadList.cpp b/src/MsgThread/Controller/src/ThreadList.cpp index fecf8b8d..2bfb22e7 100644 --- a/src/MsgThread/Controller/src/ThreadList.cpp +++ b/src/MsgThread/Controller/src/ThreadList.cpp @@ -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 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(); } diff --git a/src/MsgThread/Controller/src/ThreadListItem.cpp b/src/MsgThread/Controller/src/ThreadListItem.cpp index d64b5f87..6e59927b 100644 --- a/src/MsgThread/Controller/src/ThreadListItem.cpp +++ b/src/MsgThread/Controller/src/ThreadListItem.cpp @@ -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); }