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_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_MESSAGE_USER_H 16 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_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 MessageUser(); 28 29 ~MessageUser(); 30 31 /** 32 * @brief Sets the key used to uniquely identify this MessageUser.If no key is set, the name set by SetName(string) 33 * is used to uniquely identify a MessageUser. 34 * 35 * @param key Indicates the key to set. 36 */ 37 void SetKey(const std::string &key); 38 39 /** 40 * @brief Obtains the key of this MessageUser. 41 * 42 * @return Returns the key of this MessageUser. 43 */ 44 std::string GetKey() const; 45 46 /** 47 * @brief Sets the name of this MessageUser. 48 * 49 * @name Indicates the name to set. 50 */ 51 void SetName(const std::string &name); 52 53 /** 54 * @brief Obtains the name of this MessageUser. 55 * 56 * @return Returns the name of this MessageUser. 57 */ 58 std::string GetName() const; 59 60 /** 61 * @brief Sets the pixel map of this MessageUser. 62 * 63 * @param pixelMap Indicates the pixel map to set. 64 */ 65 void SetPixelMap(const std::shared_ptr<Media::PixelMap> &pixelMap); 66 67 /** 68 * @brief Obtains the pixel map of this MessageUser. 69 * 70 * @return Returns the pixel map of this MessageUser. 71 */ 72 const std::shared_ptr<Media::PixelMap> GetPixelMap() const; 73 74 /** 75 * @brief Sets the URI of this MessageUser. 76 * 77 * @param uri Indicates the URI to set. 78 */ 79 void SetUri(const Uri &uri); 80 81 /** 82 * @brief Obtains the URI of this MessageUser. 83 * 84 * @return Returns the URI of this MessageUser. 85 */ 86 Uri GetUri() const; 87 88 /** 89 * @brief Sets whether this MessageUser is a machine. 90 * 91 * @param machine Specifies whether this MessageUser is a machine.The value true indicates that it is, 92 * and the value false indicates not. 93 */ 94 void SetMachine(bool machine); 95 96 /** 97 * @brief Checks whether this MessageUser is a machine. 98 * 99 * @return Returns true if this MessageUser is a machine; returns false otherwise. 100 */ 101 bool IsMachine() const; 102 103 /** 104 * @brief Sets whether this MessageUser is important.This method can be used to denote users who frequently 105 * interact with the user of this device. 106 * 107 * @param userImportant Specifies whether this MessageUser is important.The value true indicates that it is 108 * important, and the value false indicates not. 109 */ 110 void SetUserAsImportant(bool userImportant); 111 112 /** 113 * @brief Checks whether this MessageUser is important. 114 * 115 * @return Returns true if this MessageUser is important; returns false otherwise. 116 */ 117 bool IsUserImportant() const; 118 119 /** 120 * @brief Dumps a string representation of the object. 121 * 122 * @return Returns a string representation of the object. 123 */ 124 std::string Dump() const; 125 126 /** 127 * @brief Converts a MessageUser object into a Json. 128 * 129 * @param jsonObject Indicates the Json object. 130 * @return Returns true if succeed; returns false otherwise. 131 */ 132 bool ToJson(nlohmann::json &jsonObject) const override; 133 134 /** 135 * @brief Creates a MessageUser object from a Json. 136 * 137 * @param jsonObject Indicates the Json object. 138 * @return Returns the MessageUser object. 139 */ 140 static MessageUser *FromJson(const nlohmann::json &jsonObject); 141 142 /** 143 * @brief Marshals a MessageUser object into a Parcel. 144 * 145 * @param parcel Indicates the Parcel object for marshalling. 146 * @return Returns true if the marshalling is successful; returns false otherwise. 147 */ 148 bool Marshalling(Parcel &parcel) const override; 149 150 /** 151 * @brief Unmarshals a MessageUser object from a Parcel. 152 * 153 * @param parcel Indicates the parcel object. 154 * @return Returns true if the unmarshalling is successful; returns false otherwise. 155 */ 156 static MessageUser *Unmarshalling(Parcel &parcel); 157 158 private: 159 /** 160 * @brief Read NotificationSlot object from a Parcel. 161 * 162 * @param parcel Indicates the parcel object. 163 * @return Returns true if succeed; returns false otherwise. 164 */ 165 bool ReadFromParcel(Parcel &parcel); 166 167 private: 168 std::string key_ {}; 169 std::string name_ {}; 170 std::shared_ptr<Media::PixelMap> pixelMap_ {nullptr}; 171 Uri uri_; 172 bool isMachine_ {false}; 173 bool isUserImportant_ {false}; 174 175 // no object in parcel 176 static constexpr int32_t VALUE_NULL = -1; 177 // object exist in parcel 178 static constexpr int32_t VALUE_OBJECT = 1; 179 }; 180 } // namespace Notification 181 } // namespace OHOS 182 183 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_MESSAGE_USER_H