From bf2acd6caaedf72f81c9833277bb9b63b8108d7d Mon Sep 17 00:00:00 2001 From: Maciek Blim Date: Mon, 22 Dec 2014 15:34:51 +0100 Subject: [PATCH] [Messasging] removeChangeListener (for emails) Change-Id: I2ba149529ecc4c99364be46696a45ba2e4331bd5 Signed-off-by: Maciek Blim --- src/messaging/change_listener_container.cc | 8 ++++---- src/messaging/message_storage.cc | 3 ++- src/messaging/message_storage.h | 2 +- src/messaging/messaging_api.js | 15 +++++++++++++-- src/messaging/messaging_instance.cc | 9 +++++++++ 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/messaging/change_listener_container.cc b/src/messaging/change_listener_container.cc index 4110353..b79b58a 100644 --- a/src/messaging/change_listener_container.cc +++ b/src/messaging/change_listener_container.cc @@ -139,10 +139,10 @@ void ChangeListenerContainer::removeChangeListener(long id) m_email_conversation_callbacks, id)) { LoggerD("Email conversation listener with id: %d removed", id); } - //else if (removeCallbackIfExists( - //context, m_email_folder_callbacks,id)) { - //LoggerD("Email folder listener with id: %d removed", id); - //} + else if (removeCallbackIfExists( + m_email_folder_callbacks,id)) { + LoggerD("Email folder listener with id: %d removed", id); + } else { LoggerW("WatchId %d not found", id); } diff --git a/src/messaging/message_storage.cc b/src/messaging/message_storage.cc index 9006744..d5abfe5 100644 --- a/src/messaging/message_storage.cc +++ b/src/messaging/message_storage.cc @@ -55,9 +55,10 @@ long MessageStorage::addFoldersChangeListener(std::shared_ptr callback); long addConversationsChangeListener(std::shared_ptr callback); long addFoldersChangeListener(std::shared_ptr callback); - void removeChangeListener(); + void removeChangeListener(long watchId); protected: int m_id; diff --git a/src/messaging/messaging_api.js b/src/messaging/messaging_api.js index 1e0ab73..0d588fd 100644 --- a/src/messaging/messaging_api.js +++ b/src/messaging/messaging_api.js @@ -1054,6 +1054,7 @@ MessageStorage.prototype.addMessagesChangeListener = function () { } }); + bridge.attach(cid, 'watchId', result); return result; }; @@ -1106,6 +1107,7 @@ MessageStorage.prototype.addConversationsChangeListener = function () { } }); + bridge.attach(cid, 'watchId', result); return result; }; @@ -1158,6 +1160,7 @@ MessageStorage.prototype.addFoldersChangeListener = function () { } }); + bridge.attach(cid, 'watchId', result); return result; }; @@ -1166,12 +1169,20 @@ MessageStorage.prototype.removeChangeListener = function () { {name: 'watchId', type: types_.LONG} ]); - bridge.sync({ + var self = this; + + var result = bridge.sync({ cmd: 'MessageStorage_removeChangeListener', args: { - watchId: args.watchId + watchId: args.watchId, + serviceId: self.service.id } }); + + bridge.find('watchId', args.watchId).forEach(function (e) { + bridge.remove(e.id); + }); + return result; }; function MessageConversation(data) { diff --git a/src/messaging/messaging_instance.cc b/src/messaging/messaging_instance.cc index 336a41a..cca250c 100644 --- a/src/messaging/messaging_instance.cc +++ b/src/messaging/messaging_instance.cc @@ -625,6 +625,15 @@ void MessagingInstance::MessageStorageRemoveChangeListener(const picojson::value picojson::object& out) { LoggerD("Entered"); + picojson::object data = args.get(JSON_DATA).get(); + const long watchId = static_cast( + data.at(REMOVE_CHANGE_LISTENER_ARGS_WATCHID).get()); + + int serviceId = static_cast(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get()); + auto service = MessagingManager::getInstance().getMessageServiceEmail(serviceId); + + service->getMsgStorage()->removeChangeListener(watchId); + ReportSuccess(out); } } // namespace messaging -- 2.7.4