Release version 0.5.85
[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 int64_t AbstractItem::Impl::ItemInfo::GetPrivateId() const {
39   return impl_->private_id_;
40 }
41
42 void AbstractItem::Impl::ItemInfo::SetPrivateId(int64_t private_id) {
43   impl_->private_id_ = private_id;
44 }
45
46 uid_t AbstractItem::Impl::ItemInfo::GetUid() const {
47   return impl_->uid_;
48 }
49
50 void AbstractItem::Impl::ItemInfo::SetUid(uid_t uid) {
51   impl_->uid_ = uid;
52 }
53
54 time_t AbstractItem::Impl::ItemInfo::GetTime() const {
55   return impl_->time_;
56 }
57
58 void AbstractItem::Impl::ItemInfo::SetTime(time_t time) {
59   impl_->time_ = time;
60 }
61
62 int AbstractItem::Impl::ItemInfo::GetVersion() const {
63   return impl_->version_;
64 }
65
66 void AbstractItem::Impl::ItemInfo::SetVersion(int ver) {
67   impl_->version_ = ver;
68 }
69
70 void AbstractItem::Impl::ItemInfo::SetHideTime(int hide_time) {
71   impl_->hide_time_ = hide_time;
72 }
73
74 int AbstractItem::Impl::ItemInfo::GetHideTime() const {
75   return impl_->hide_time_;
76 }
77
78 void AbstractItem::Impl::ItemInfo::SetDeleteTime(int delete_time) {
79   impl_->delete_time_ = delete_time;
80 }
81
82 int AbstractItem::Impl::ItemInfo::GetDeleteTime() const {
83   return impl_->delete_time_;
84 }
85
86 void AbstractItem::Impl::ItemInfo::AddHideViewer(std::string appid) {
87   if (find(impl_->hide_viewer_list_.begin(),
88       impl_->hide_viewer_list_.end(), appid) !=
89       impl_->hide_viewer_list_.end()) {
90     return;
91   }
92   impl_->hide_viewer_list_.push_back(appid);
93 }
94
95 bool AbstractItem::Impl::ItemInfo::CanReceive(std::string receiver_group) const {
96   if (impl_->receiver_group_list_.size() != 0 && !receiver_group.empty()) {
97     list<string>::iterator iter =
98       std::find(impl_->receiver_group_list_.begin(),
99         impl_->receiver_group_list_.end(), receiver_group);
100
101     if (iter == impl_->receiver_group_list_.end())
102       return false;
103   }
104
105   if (impl_->hide_viewer_list_.size() == 0)
106     return true;
107
108   string app_id = util::GetAppId();
109   list<string>::iterator iter =
110     std::find(impl_->hide_viewer_list_.begin(),
111     impl_->hide_viewer_list_.end(), app_id);
112
113   if (iter != impl_->hide_viewer_list_.end())
114     return false;
115
116   return true;
117 }
118
119 std::list<std::string> AbstractItem::Impl::ItemInfo::GetHideViewerList() const {
120   return impl_->hide_viewer_list_;
121 }
122
123 }  // namespace item
124 }  // namespace notification