1 /* 2 * Copyright (c) 2021-2022 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_CONTENT_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CONVERSATIONAL_CONTENT_H 18 19 #include "message_user.h" 20 #include "notification_basic_content.h" 21 #include "notification_conversational_message.h" 22 #include "notification_json_convert.h" 23 #include "parcel.h" 24 25 namespace OHOS { 26 namespace Notification { 27 class NotificationConversationalContent : public NotificationBasicContent { 28 public: 29 using MessagePtr = std::shared_ptr<NotificationConversationalMessage>; 30 using MessageVector = std::vector<MessagePtr>; 31 32 /** 33 * @brief A constructor used to create a NotificationConversationalContent instance with the MessageUser specified. 34 * 35 * @param messageUser Indicates the MessageUser who sends all Message objects in this conversation-like 36 * notification. This parameter cannot be null. 37 */ 38 explicit NotificationConversationalContent(const MessageUser &messageUser); 39 40 ~NotificationConversationalContent() = default; 41 42 /** 43 * @brief Obtains the message sender to be displayed for any messages sent by the user in this conversation-like 44 * notification. 45 * 46 * @return Returns the message sender. 47 */ 48 MessageUser GetMessageUser() const; 49 50 /** 51 * @brief Sets the title to be displayed for the conversation.The title set in this method will overwrite the one 52 * set by calling setTitle(std::string). 53 * 54 * @param conversationTitle Indicates the title to be displayed for the conversation. 55 */ 56 void SetConversationTitle(const std::string &conversationTitle); 57 58 /** 59 * @brief Obtains the title to be displayed for the conversation. 60 * 61 * @return Returns the title to be displayed for the conversation. 62 */ 63 std::string GetConversationTitle() const; 64 65 /** 66 * @brief Checks whether this notification represents a group conversation. 67 * 68 * @return Returns true if this notification represents a group conversation; returns false otherwise. 69 */ 70 bool IsConversationGroup() const; 71 72 /** 73 * @brief Sets whether this notification represents a group conversation. 74 * The big icon, if any, set for this notification by calling NotificationRequest::setBigIcon(PixelMap) 75 * will be displayed only when this method is set to true. 76 * 77 * @param isGroup Specifies whether this notification represents a group conversation. 78 */ 79 void SetConversationGroup(bool isGroup); 80 81 /** 82 * @brief Adds a message to this conversation-like notification based on the specified message content, timestamp, 83 * and MessageUser.All messages will be displayed in the order they are added. 84 * 85 * @param text Indicates the text to be displayed as the message content. 86 * @param timestamp Indicates the time when the message arrived. 87 * @param sender Indicates the MessageUser who sent the message. 88 */ 89 void AddConversationalMessage( 90 const std::string &text, int64_t timestamp, const MessageUser &sender); 91 92 /** 93 * @brief Adds a specified message to this conversation-like notification.All messages will be displayed in the 94 * order they are added. 95 * 96 * @param message Indicates the ConversationalMessage object to add. 97 */ 98 void AddConversationalMessage(const MessagePtr &message); 99 100 /** 101 * @brief Obtains all messages included in this conversation-like notification. 102 * 103 * @return Returns the list of all Message objects included. 104 */ 105 MessageVector GetAllConversationalMessages() const; 106 107 /** 108 * @brief Returns a string representation of the object. 109 * 110 * @return Returns a string representation of the object. 111 */ 112 std::string Dump() override; 113 114 /** 115 * @brief Converts a NotificationConversationalContent object into a Json. 116 * 117 * @param jsonObject Indicates the Json object. 118 * @return Returns true if succeed; returns false otherwise. 119 */ 120 virtual bool ToJson(nlohmann::json &jsonObject) const override; 121 122 /** 123 * @brief Creates a NotificationConversationalContent object from a Json. 124 * 125 * @param jsonObject Indicates the Json object. 126 * @return Returns the NotificationConversationalContent. 127 */ 128 static NotificationConversationalContent *FromJson(const nlohmann::json &jsonObject); 129 130 /** 131 * @brief Marshal a object into a Parcel. 132 * 133 * @param parcel Indicates the object into the parcel. 134 * @return Returns true if succeed; returns false otherwise. 135 */ 136 virtual bool Marshalling(Parcel &parcel) const override; 137 138 /** 139 * @brief Unmarshal object from a Parcel. 140 * 141 * @param parcel Indicates the parcel object. 142 * @return Returns the NotificationConversationalContent. 143 */ 144 static NotificationConversationalContent *Unmarshalling(Parcel &parcel); 145 146 protected: 147 /** 148 * @brief Read a NotificationConversationalContent object from a Parcel. 149 * 150 * @param parcel Indicates the parcel object. 151 * @return Returns true if succeed; returns false otherwise. 152 */ 153 bool ReadFromParcel(Parcel &parcel) override; 154 155 private: 156 NotificationConversationalContent() = default; 157 158 private: 159 MessageUser messageUser_ {}; 160 std::string conversationTitle_ {}; 161 bool isGroup_ {false}; 162 MessageVector messages_ {}; 163 }; 164 } // namespace Notification 165 } // namespace OHOS 166 167 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CONVERSATIONAL_CONTENT_H