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