Support to update/delete by noti list 99/227899/5
authormk5004.lee <mk5004.lee@samsung.com>
Tue, 17 Mar 2020 06:08:03 +0000 (15:08 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Tue, 24 Mar 2020 07:06:27 +0000 (16:06 +0900)
Change-Id: Ia0c8bd04e586c495134e9e2acadc49e52fa4870d
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
src/notification_ex_service.cc

index 1740179..20ed93b 100644 (file)
@@ -75,18 +75,13 @@ class DPMFacade {
   }
 
   void DelegateReporterEvent(const IEventInfo& info,
-        shared_ptr<item::AbstractItem> item) {
-    reporter_->SendEvent(info, item);
-  }
-
-  void DelegateReporterEvent(const IEventInfo& info,
-        std::list<std::shared_ptr<item::AbstractItem>> itemList) {
+        list<shared_ptr<item::AbstractItem>> itemList) {
     reporter_->SendEvent(info, itemList);
   }
 
   void DelegateManagerEvent(const IEventInfo& info,
-        shared_ptr<item::AbstractItem> noti) {
-    manager_->SendEvent(info, noti);
+        list<shared_ptr<item::AbstractItem>> itemList) {
+    manager_->SendEvent(info, itemList);
   }
 
   void LaunchDefaultViewer(list<shared_ptr<item::AbstractItem>> item,
@@ -105,6 +100,7 @@ class DPMFacade {
                         static_pointer_cast<IItemInfoInternal>(
                             item.front()->GetInfo())->GetUid());
   }
+
   void LaunchDefaultViewer(shared_ptr<item::AbstractItem> item,
               notification_op_type_e status) {
     LaunchDefaultViewer(
@@ -187,6 +183,7 @@ class DPMFacade {
 
     return true;
   }
+
   bool CheckDoNoDisturbStatus(uid_t uid, const string& owner) {
     int ret;
     bool do_not_disturb = false;
@@ -318,7 +315,7 @@ static DPMFacade* facade_;
 class DPMReporter : public Reporter {
  protected:
   void OnUpdate(const IEventInfo& info,
-      shared_ptr<item::AbstractItem> updatedItem) {
+      list<shared_ptr<item::AbstractItem>> updatedItem) {
     DBG("Update !!!");
     int ret;
 
@@ -346,7 +343,7 @@ class DPMReporter : public Reporter {
   }
 
   void DoDelete(const IEventInfo& info,
-      shared_ptr<item::AbstractItem> deletedItem) {
+      list<shared_ptr<item::AbstractItem>> deletedItem) {
     int ret = DBManager::DeleteNotification(deletedItem);
     if (ret == ERROR_NONE) {
       /* noti owner */
@@ -363,7 +360,7 @@ class DPMReporter : public Reporter {
   }
 
   void OnDelete(const IEventInfo& info,
-      shared_ptr<item::AbstractItem> deletedItem) {
+      list<shared_ptr<item::AbstractItem>> deletedItem) {
     DBG("Delete !!!");
     if (info.GetEventType() == IEventInfo::EventType::DeleteAll) {
       list<shared_ptr<item::AbstractItem>> noti_list;
@@ -375,8 +372,7 @@ class DPMReporter : public Reporter {
                 facade_->GetUid(info), info.GetChannel());
 
       EventInfo event_info(EventInfo::Delete, info.GetOwner(), info.GetChannel());
-      for (auto& i : noti_list)
-        DoDelete(event_info, i);
+      DoDelete(event_info, noti_list);
     } else {
       DoDelete(info, deletedItem);
     }
@@ -386,25 +382,22 @@ class DPMReporter : public Reporter {
       list<shared_ptr<item::AbstractItem>> noti_list) override {
     LOGI("Event received (%d) !!", (int)info.GetEventType());
     int type = info.GetEventType();
-    if (type == IEventInfo::EventType::DeleteAll) {
-      OnDelete(info, nullptr);
-      return;
-    } else if (type == IEventInfo::EventType::Register) {
-      OnRegister(info);
-      return;
-    }
 
-    for (auto& i : noti_list) {
-      switch (type) {
+    switch (type) {
       case IEventInfo::EventType::Update:
-        OnUpdate(info, i);
+        OnUpdate(info, noti_list);
         break;
       case IEventInfo::EventType::Delete:
-        OnDelete(info, i);
+        OnDelete(info, noti_list);
+        break;
+      case IEventInfo::EventType::DeleteAll:
+        OnDelete(info, noti_list);
+        break;
+      case IEventInfo::EventType::Register:
+        OnRegister(info);
         break;
       default :
         break;
-      }
     }
   }
 
@@ -428,49 +421,50 @@ class DPMReporter : public Reporter {
     return DBManager::GetNotificationList(facade_->GetUid(info)).size();
   }
 
-  int UpdateHideApp(shared_ptr<item::AbstractItem> updatedItem) {
+  int UpdateHideApp(list<shared_ptr<item::AbstractItem>> updatedItem) {
     int ret;
-    string hide_list;
-    int uid = static_pointer_cast<IItemInfoInternal>(updatedItem->GetInfo())->GetUid();
-    DBG("try update hide app_id(%s) sender(%s) uid(%s)",
-      updatedItem->GetId().c_str(),
-      updatedItem->GetSenderAppId().c_str(), string(to_string(uid)).c_str());
-    string map_key = updatedItem->GetId() + updatedItem->GetSenderAppId() + string(to_string(uid));
-    list<string> updated_hide_list = static_pointer_cast<IItemInfoInternal>(updatedItem->GetInfo())->GetHideViewerList();
-
-    /* Check new hide app */
-    auto noti = facade_->hide_map_.find(map_key);
-    if (noti == facade_->hide_map_.end()) {
-      if (updated_hide_list.size() > 0) {
-        for (auto& i : updated_hide_list)
-          hide_list += i + ";";
-
-        ret = DBManager::UpdateHideList(updatedItem, hide_list);
-        if (ret != ERROR_NONE)
-          return ret;
-
-        facade_->hide_map_[map_key] = hide_list;
-        return ERROR_NONE;
-      } else {
-        DBG("Empty hide viewer list");
-        return ERROR_NOT_EXIST_ID;
+    for (auto& i : updatedItem) {
+      string hide_list;
+      int uid = static_pointer_cast<IItemInfoInternal>(i->GetInfo())->GetUid();
+      DBG("try update hide app_id(%s) sender(%s) uid(%s)",
+        i->GetId().c_str(),
+        i->GetSenderAppId().c_str(), string(to_string(uid)).c_str());
+      string map_key = i->GetId() + i->GetSenderAppId() + string(to_string(uid));
+      list<string> updated_hide_list = static_pointer_cast<IItemInfoInternal>(i->GetInfo())->GetHideViewerList();
+
+      /* Check new hide app */
+      auto noti = facade_->hide_map_.find(map_key);
+      if (noti == facade_->hide_map_.end()) {
+        if (updated_hide_list.size() > 0) {
+          for (auto& j : updated_hide_list)
+            hide_list += j + ";";
+
+          ret = DBManager::UpdateHideList(i, hide_list);
+          if (ret != ERROR_NONE)
+            return ret;
+
+          facade_->hide_map_[map_key] = hide_list;
+          return ERROR_NONE;
+        } else {
+          DBG("Empty hide viewer list");
+          return ERROR_NOT_EXIST_ID;
+        }
       }
-    }
 
-    /* Check new hide app */
-    hide_list = noti->second;
-    for (auto& i : updated_hide_list) {
-      if (hide_list.find(i + ";") == string::npos) {
-        string new_hide_list = hide_list + i + ";";
-        ret = DBManager::UpdateHideList(updatedItem, new_hide_list);
-        if (ret != ERROR_NONE)
-          return ret;
-
-        facade_->hide_map_[map_key] = new_hide_list;
-        return ERROR_NONE;
+      /* Check new hide app */
+      hide_list = noti->second;
+      for (auto& j : updated_hide_list) {
+        if (hide_list.find(j + ";") == string::npos) {
+          string new_hide_list = hide_list + j + ";";
+          ret = DBManager::UpdateHideList(i, new_hide_list);
+          if (ret != ERROR_NONE)
+            return ret;
+
+          facade_->hide_map_[map_key] = new_hide_list;
+          return ERROR_NONE;
+        }
       }
     }
-
     return ERROR_NOT_EXIST_ID;
   }
 
@@ -497,30 +491,6 @@ class DPMReporter : public Reporter {
 
 class DPMManager : public Manager {
  protected:
-  void UpdateHideApp(shared_ptr<item::AbstractItem> updatedItem) {
-    string hide_list;
-    int uid = static_pointer_cast<IItemInfoInternal>(updatedItem->GetInfo())->GetUid();
-    string map_key = updatedItem->GetId() + updatedItem->GetSenderAppId() + string(to_string(uid));
-    list<string> updated_hide_list =
-      static_pointer_cast<item::IItemInfoInternal>(updatedItem->GetInfo())->GetHideViewerList();
-
-    auto noti = facade_->hide_map_.find(map_key);
-    if (noti == facade_->hide_map_.end())
-      return;
-
-    /* hide app list synchronization */
-    hide_list = noti->second;
-    istringstream stream(hide_list);
-    string hide_app_id;
-
-    while (getline(stream, hide_app_id, ';')) {
-      list<string>::iterator iter = std::find(updated_hide_list.begin(),
-                                updated_hide_list.end(), hide_app_id);
-      if (iter == updated_hide_list.end())
-        static_pointer_cast<item::IItemInfoInternal>(updatedItem->GetInfo())->AddHideViewer(hide_app_id);
-    }
-  }
-
   void OnAdd(const IEventInfo& info,
       list<shared_ptr<item::AbstractItem>> addedItem) override {
     DBG("Add !!!");
@@ -554,7 +524,7 @@ class DPMManager : public Manager {
   }
 
   void OnUpdate(const IEventInfo& info,
-      shared_ptr<item::AbstractItem> updatedItem) override {
+      list<shared_ptr<item::AbstractItem>> updatedItem) override {
     DBG("Update !!!");
     int ret;
 
@@ -586,7 +556,7 @@ class DPMManager : public Manager {
   }
 
   int DoDelete(const IEventInfo& info,
-      shared_ptr<item::AbstractItem> deletedItem) {
+      list<shared_ptr<item::AbstractItem>> deletedItem) {
     int ret;
 
     ret = DBManager::DeleteNotification(deletedItem);
@@ -601,16 +571,14 @@ class DPMManager : public Manager {
   }
 
   void OnDelete(const IEventInfo& info,
-      shared_ptr<item::AbstractItem> deletedItem) override {
+      list<shared_ptr<item::AbstractItem>> deletedItem) override {
     DBG("Delete !!!");
     if (info.GetEventType() == IEventInfo::EventType::DeleteAll) {
       list<shared_ptr<item::AbstractItem>> noti_list =
           DBManager::GetNotificationList(info.GetOwner(), facade_->GetUid(info),
-              info.GetChannel());
-      for (auto& i : noti_list) {
-        EventInfo event_info(EventInfo::Delete, info.GetOwner(), info.GetChannel());
-        DoDelete(event_info, i);
-      }
+          info.GetChannel());
+      EventInfo event_info(EventInfo::Delete, info.GetOwner(), info.GetChannel());
+      DoDelete(event_info, noti_list);
       facade_->LaunchDefaultViewer(noti_list, NOTIFICATION_OP_DELETE);
     } else {
       int ret = DoDelete(info, deletedItem);
@@ -643,6 +611,32 @@ class DPMManager : public Manager {
     }
   }
 
+  void UpdateHideApp(list<shared_ptr<item::AbstractItem>> updatedItem) {
+    for (auto& i : updatedItem) {
+      string hide_list;
+      int uid = static_pointer_cast<IItemInfoInternal>(i->GetInfo())->GetUid();
+      string map_key = i->GetId() + i->GetSenderAppId() + string(to_string(uid));
+      list<string> updated_hide_list =
+          static_pointer_cast<item::IItemInfoInternal>(i->GetInfo())->GetHideViewerList();
+
+      auto noti = facade_->hide_map_.find(map_key);
+      if (noti == facade_->hide_map_.end())
+        return;
+
+      /* hide app list synchronization */
+      hide_list = noti->second;
+      istringstream stream(hide_list);
+      string hide_app_id;
+
+      while (getline(stream, hide_app_id, ';')) {
+        list<string>::iterator iter = std::find(updated_hide_list.begin(),
+                      updated_hide_list.end(), hide_app_id);
+        if (iter == updated_hide_list.end())
+          static_pointer_cast<item::IItemInfoInternal>(i->GetInfo())->AddHideViewer(hide_app_id);
+      }
+    }
+  }
+
   void SetIndirectRequest(const IEventInfo& info,
           list<shared_ptr<AbstractItem>> addedItem) {
     for (auto& i : addedItem)