• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_MESSAGE_USER_H
16 #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_MESSAGE_USER_H
17 
18 #include "notification_json_convert.h"
19 #include "pixel_map.h"
20 #include "parcel.h"
21 #include "uri.h"
22 
23 namespace OHOS {
24 namespace Notification {
25 class MessageUser final : public Parcelable, public NotificationJsonConvertionBase {
26 public:
27     /**
28      * A constructor used to construct MessageUser
29      */
30     MessageUser();
31 
32     /**
33      * Default deconstructor used to deconstruct.
34      */
35     ~MessageUser();
36 
37     /**
38      * Sets the key used to uniquely identify this MessageUser.
39      * @note Sets the key used to uniquely identify this MessageUser.
40      *       If no key is set, the name set by SetName(string) is used to uniquely identify a MessageUser.
41      * @param key Indicates the key to set.
42      */
43     void SetKey(const std::string &key);
44 
45     /**
46      * Obtains the key of this MessageUser.
47      *
48      * @return Returns the key of this MessageUser.
49      */
50     std::string GetKey() const;
51 
52     /**
53      * Sets the name of this MessageUser.
54      * @name Indicates the name to set.
55      */
56     void SetName(const std::string &name);
57 
58     /**
59      * Obtains the name of this MessageUser.
60      *
61      * @return Returns the name of this MessageUser.
62      */
63     std::string GetName() const;
64 
65     /**
66      * Sets the pixel map of this MessageUser.
67      * @param pixelMap Indicates the pixel map to set.
68      */
69     void SetPixelMap(const std::shared_ptr<Media::PixelMap> &pixelMap);
70 
71     /**
72      * Obtains the pixel map of this MessageUser.
73      *
74      * @return Returns the pixel map of this MessageUser.
75      */
76     const std::shared_ptr<Media::PixelMap> GetPixelMap() const;
77 
78     /**
79      * Sets the URI of this MessageUser.
80      * @param uri Indicates the URI to set.
81      */
82     void SetUri(const Uri &uri);
83 
84     /**
85      * Obtains the URI of this MessageUser.
86      *
87      * @return Returns the URI of this MessageUser.
88      */
89     Uri GetUri() const;
90 
91     /**
92      * Sets whether this MessageUser is a machine.
93      * @param machine Specifies whether this MessageUser is a machine.
94      *                The value true indicates that it is, and the value false indicates not.
95      */
96     void SetMachine(bool machine);
97 
98     /**
99      * Checks whether this MessageUser is a machine.
100      *
101      * @return Returns true if this MessageUser is a machine; returns false otherwise.
102      */
103     bool IsMachine() const;
104 
105     /**
106      * Sets whether this MessageUser is important.
107      * @note This method can be used to denote users who frequently interact with the user of this device.
108      * @param userImportant Specifies whether this MessageUser is important.
109      *                      The value true indicates that it is important, and the value false indicates not.
110      */
111     void SetUserAsImportant(bool userImportant);
112 
113     /**
114      * Checks whether this MessageUser is important.
115      *
116      * @return Returns true if this MessageUser is important; returns false otherwise.
117      */
118     bool IsUserImportant() const;
119 
120     /**
121      * Dumps a string representation of the object.
122      *
123      * @return A string representation of the object.
124      */
125     std::string Dump() const;
126 
127     /**
128      * Converts a MessageUser object into a Json.
129      * @param jsonObject Indicates the Json object.
130      */
131     bool ToJson(nlohmann::json &jsonObject) const override;
132 
133     /**
134      * Creates a MessageUser object from a Json.
135      * @param jsonObject Indicates the Json object.
136      * @return the MessageUser.
137      */
138     static MessageUser *FromJson(const nlohmann::json &jsonObject);
139 
140     /**
141      * Marshals a MessageUser object into a Parcel.
142      *
143      * @param parcel Indicates the Parcel object for marshalling.
144      * @return Returns true if the marshalling is successful; returns false otherwise.
145      */
146     bool Marshalling(Parcel &parcel) const override;
147 
148     /**
149      * Unmarshals a MessageUser object from a Parcel.
150      *
151      * @param parcel Indicates the Parcel object for unmarshalling.
152      * @return Returns true if the unmarshalling is successful; returns false otherwise.
153      */
154     static MessageUser *Unmarshalling(Parcel &parcel);
155 
156 private:
157     /**
158      * Read NotificationSlot object from a Parcel.
159      *
160      * @param parcel the parcel
161      * @return read from parcel success or fail
162      */
163     bool ReadFromParcel(Parcel &parcel);
164 
165 private:
166     std::string key_ {};
167     std::string name_ {};
168     std::shared_ptr<Media::PixelMap> pixelMap_ {nullptr};
169     Uri uri_;
170     bool isMachine_ {false};
171     bool isUserImportant_ {false};
172 
173     // no object in parcel
174     static constexpr int VALUE_NULL = -1;
175     // object exist in parcel
176     static constexpr int VALUE_OBJECT = 1;
177 };
178 }  // namespace Notification
179 }  // namespace OHOS
180 
181 #endif  // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_MESSAGE_USER_H