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 16 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CONVERSATIONAL_MESSAGE_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CONVERSATIONAL_MESSAGE_H 18 19 #include "message_user.h" 20 #include "notification_json_convert.h" 21 #include "parcel.h" 22 #include "uri.h" 23 24 namespace OHOS { 25 namespace Notification { 26 class NotificationConversationalMessage : public Parcelable, public NotificationJsonConvertionBase { 27 public: 28 /** 29 * @brief A constructor used to create a NotificationConversationalMessage instance with the input parameters 30 * passed. 31 * 32 * @param text Indicates the text to be displayed as the message content. This parameter cannot be null. 33 * @param timestamp Indicates the time when the message arrived. 34 * @param sender Indicates the MessageUser who sent the message. 35 */ 36 NotificationConversationalMessage( 37 const std::string &text, int64_t timestamp, const MessageUser &sender); 38 39 ~NotificationConversationalMessage() = default; 40 41 /** 42 * @brief Obtains the text to be displayed as the content of this message. 43 * 44 * @return Returns the message content. 45 */ 46 std::string GetText() const; 47 48 /** 49 * @brief Obtains the time when this message arrived. 50 * 51 * @return Returns the time when this message arrived. 52 */ 53 int64_t GetArrivedTime() const; 54 55 /** 56 * @brief Obtains the sender of this message. 57 * 58 * @return Returns the message sender. 59 */ 60 MessageUser GetSender() const; 61 62 /** 63 * @brief Sets the MIME type and URI of this message. 64 * 65 * @param mimeType Indicates the MIME type of this message. 66 * @param uri Indicates the URI that points to the message content whose type is specified by the given MIME type. 67 */ 68 void SetData(const std::string &mimeType, const std::shared_ptr<Uri> &uri); 69 70 /** 71 * @brief Obtains the MIME type of this message. 72 * 73 * @return Returns the MIME type of this message. 74 */ 75 std::string GetMimeType() const; 76 77 /** 78 * @brief Obtains the URI of the message content with the specific MIME type. 79 * 80 * @return Returns the URI of the message content with the specific MIME type. 81 */ 82 const std::shared_ptr<Uri> GetUri() const; 83 84 /** 85 * @brief Returns a string representation of the object. 86 * 87 * @return Returns a string representation of the object. 88 */ 89 std::string Dump(); 90 91 /** 92 * @brief Converts a NotificationConversationalMessage object into a Json. 93 * 94 * @param jsonObject Indicates the Json object. 95 * @return Returns true if succeed; returns false otherwise. 96 */ 97 bool ToJson(nlohmann::json &jsonObject) const override; 98 99 /** 100 * @brief Creates a NotificationConversationalMessage object from a Json. 101 * 102 * @param jsonObject Indicates the Json object. 103 * @return Returns the NotificationConversationalMessage. 104 */ 105 static NotificationConversationalMessage *FromJson(const nlohmann::json &jsonObject); 106 107 /** 108 * @brief Marshal a object into a Parcel. 109 * 110 * @param parcel Indicates the object into the parcel. 111 * @return Returns true if succeed; returns false otherwise. 112 */ 113 virtual bool Marshalling(Parcel &parcel) const override; 114 115 /** 116 * @brief Unmarshal object from a Parcel. 117 * 118 * @param parcel Indicates the parcel object. 119 * @return Returns the NotificationConversationalMessage. 120 */ 121 static NotificationConversationalMessage *Unmarshalling(Parcel &parcel); 122 123 private: 124 NotificationConversationalMessage() = default; 125 126 /** 127 * @brief Read a NotificationConversationalMessage object from a Parcel. 128 * 129 * @param parcel Indicates the parcel object. 130 * @return Returns true if succeed; returns false otherwise. 131 */ 132 bool ReadFromParcel(Parcel &parcel); 133 134 private: 135 int64_t arrivedTime_ {0}; 136 std::string text_ {}; 137 MessageUser sender_ {}; 138 std::shared_ptr<Uri> uri_ {}; 139 std::string mimeType_ {}; 140 }; 141 } // namespace Notification 142 } // namespace OHOS 143 144 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CONVERSATIONAL_MESSAGE_H