Fix group name for noti_ex
[platform/core/api/notification.git] / notification-ex / item_info.cc
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <dlog.h>
18
19 #include <memory>
20 #include <algorithm>
21
22 #include "notification-ex/item_info_internal.h"
23 #include "notification-ex/ex_util.h"
24
25 #ifdef LOG_TAG
26 #undef LOG_TAG
27 #endif
28
29 #define LOG_TAG "NOTIFICATION_EX"
30
31 using namespace std;
32 namespace notification {
33 namespace item {
34
35 AbstractItem::Impl::ItemInfo::ItemInfo(AbstractItem::Impl* impl) : impl_(impl) {
36 }
37
38 uid_t AbstractItem::Impl::ItemInfo::GetUid() const {
39   return impl_->uid_;
40 }
41
42 void AbstractItem::Impl::ItemInfo::SetUid(uid_t uid) {
43   impl_->uid_ = uid;
44 }
45
46 time_t AbstractItem::Impl::ItemInfo::GetTime() const {
47   return impl_->time_;
48 }
49
50 void AbstractItem::Impl::ItemInfo::SetTime(time_t time) {
51   impl_->time_ = time;
52 }
53
54 int AbstractItem::Impl::ItemInfo::GetVersion() const {
55   return impl_->version_;
56 }
57
58 void AbstractItem::Impl::ItemInfo::SetVersion(int ver) {
59   impl_->version_ = ver;
60 }
61
62 void AbstractItem::Impl::ItemInfo::SetHideTime(int hide_time) {
63   impl_->hide_time_ = hide_time;
64 }
65
66 int AbstractItem::Impl::ItemInfo::GetHideTime() const {
67   return impl_->hide_time_;
68 }
69
70 void AbstractItem::Impl::ItemInfo::SetDeleteTime(int delete_time) {
71   impl_->delete_time_ = delete_time;
72 }
73
74 int AbstractItem::Impl::ItemInfo::GetDeleteTime() const {
75   return impl_->delete_time_;
76 }
77
78 void AbstractItem::Impl::ItemInfo::AddHideViewer(std::string appid) {
79   if (find(impl_->hide_viewer_list_.begin(),
80       impl_->hide_viewer_list_.end(), appid) !=
81       impl_->hide_viewer_list_.end()) {
82     return;
83   }
84   impl_->hide_viewer_list_.push_back(appid);
85 }
86
87 bool AbstractItem::Impl::ItemInfo::CanReceive(std::string receiver_group) const {
88   if (impl_->receiver_group_list_.size() != 0 && !receiver_group.empty()) {
89     list<string>::iterator iter =
90       std::find(impl_->receiver_group_list_.begin(),
91         impl_->receiver_group_list_.end(), receiver_group);
92
93     if (iter == impl_->receiver_group_list_.end())
94       return false;
95   }
96
97   if (impl_->hide_viewer_list_.size() == 0)
98     return true;
99
100   string app_id = util::GetAppId();
101   list<string>::iterator iter =
102     std::find(impl_->hide_viewer_list_.begin(),
103     impl_->hide_viewer_list_.end(), app_id);
104
105   if (iter != impl_->hide_viewer_list_.end())
106     return false;
107
108   return true;
109 }
110
111 std::list<std::string> AbstractItem::Impl::ItemInfo::GetHideViewerList() const {
112   return impl_->hide_viewer_list_;
113 }
114
115 }  // namespace item
116 }  // namespace notification