From: SukHyung, Kang Date: Fri, 15 Nov 2019 08:05:56 +0000 (+0900) Subject: Handling null value in chat-message X-Git-Tag: submit/tizen_5.5/20191121.005910^2~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb77668890115b584e87bc3b93aceaad0a3c8c67;p=platform%2Fcore%2Fapi%2Fnotification.git Handling null value in chat-message Change-Id: I564d2ef5978116fb3949ff7d09601f9b088d7f5f Signed-off-by: SukHyung, Kang --- diff --git a/notification-ex/chat_message_item.cc b/notification-ex/chat_message_item.cc index ea95e39b..be4e80ba 100644 --- a/notification-ex/chat_message_item.cc +++ b/notification-ex/chat_message_item.cc @@ -61,14 +61,22 @@ Bundle ChatMessageItem::Serialize() const { Bundle b; b = AbstractItem::Serialize(); - b.Add(CHATMESSAGE_NAME_KEY, - reinterpret_cast(impl_->name_->Serialize().ToRaw().first.get())); - b.Add(CHATMESSAGE_TEXT_KEY, - reinterpret_cast(impl_->text_->Serialize().ToRaw().first.get())); - b.Add(CHATMESSAGE_IMAGE_KEY, - reinterpret_cast(impl_->image_->Serialize().ToRaw().first.get())); - b.Add(CHATMESSAGE_TIME_KEY, - reinterpret_cast(impl_->time_->Serialize().ToRaw().first.get())); + if (impl_->name_ != nullptr) + b.Add(CHATMESSAGE_NAME_KEY, + reinterpret_cast(impl_->name_->Serialize().ToRaw().first.get())); + + if (impl_->text_ != nullptr) + b.Add(CHATMESSAGE_TEXT_KEY, + reinterpret_cast(impl_->text_->Serialize().ToRaw().first.get())); + + if (impl_->image_ != nullptr) + b.Add(CHATMESSAGE_IMAGE_KEY, + reinterpret_cast(impl_->image_->Serialize().ToRaw().first.get())); + + if (impl_->time_ != nullptr) + b.Add(CHATMESSAGE_TIME_KEY, + reinterpret_cast(impl_->time_->Serialize().ToRaw().first.get())); + b.Add(CHATMESSAGE_TYPE_KEY, std::to_string(static_cast(impl_->type_))); return b; } @@ -76,25 +84,33 @@ Bundle ChatMessageItem::Serialize() const { void ChatMessageItem::Deserialize(Bundle b) { AbstractItem::Deserialize(b); - std::shared_ptr name = - FactoryManager::GetInst().CreateItem(AbstractItem::Text); - name.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_NAME_KEY))); - impl_->name_ = std::static_pointer_cast(name); - - std::shared_ptr text = - FactoryManager::GetInst().CreateItem(AbstractItem::Text); - text.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TEXT_KEY))); - impl_->text_ = std::static_pointer_cast(text); - - std::shared_ptr image = - FactoryManager::GetInst().CreateItem(AbstractItem::Image); - image.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_IMAGE_KEY))); - impl_->image_ = std::static_pointer_cast(image); - - std::shared_ptr time = - FactoryManager::GetInst().CreateItem(AbstractItem::Time); - time.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TIME_KEY))); - impl_->time_ = std::static_pointer_cast(time); + if (!b.GetString(CHATMESSAGE_NAME_KEY).empty()) { + std::shared_ptr name = + FactoryManager::GetInst().CreateItem(AbstractItem::Text); + name.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_NAME_KEY))); + impl_->name_ = std::static_pointer_cast(name); + } + + if (!b.GetString(CHATMESSAGE_TEXT_KEY).empty()) { + std::shared_ptr text = + FactoryManager::GetInst().CreateItem(AbstractItem::Text); + text.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TEXT_KEY))); + impl_->text_ = std::static_pointer_cast(text); + } + + if (!b.GetString(CHATMESSAGE_IMAGE_KEY).empty()) { + std::shared_ptr image = + FactoryManager::GetInst().CreateItem(AbstractItem::Image); + image.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_IMAGE_KEY))); + impl_->image_ = std::static_pointer_cast(image); + } + + if (!b.GetString(CHATMESSAGE_TIME_KEY).empty()) { + std::shared_ptr time = + FactoryManager::GetInst().CreateItem(AbstractItem::Time); + time.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TIME_KEY))); + impl_->time_ = std::static_pointer_cast(time); + } impl_->type_ = static_cast(std::stoi(b.GetString(CHATMESSAGE_TYPE_KEY))); } diff --git a/notification-ex/stub.cc b/notification-ex/stub.cc index 0e37fe17..b890482a 100644 --- a/notification-ex/stub.cc +++ b/notification-ex/stub.cc @@ -441,15 +441,19 @@ extern "C" EXPORT_API int noti_ex_item_chat_message_create( noti_ex_item_h *handle, const char *id, noti_ex_item_h name, noti_ex_item_h text, noti_ex_item_h image, noti_ex_item_h time, noti_ex_item_chat_message_type_e message_type) { - if (handle == nullptr || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) { + if (handle == nullptr || (text == nullptr && image == nullptr) + || name == nullptr || time == nullptr + || message_type > NOTI_EX_ITEM_CHAT_MESSAGE_TYPE_SENDER) { LOGE("Invalid parameter"); return NOTI_EX_ERROR_INVALID_PARAMETER; } auto* p = new (std::nothrow) ChatMessageItem(id, dynamic_pointer_cast(static_cast(name)->GetPtr()), - dynamic_pointer_cast(static_cast(text)->GetPtr()), - dynamic_pointer_cast(static_cast(image)->GetPtr()), + text == nullptr ? nullptr + : dynamic_pointer_cast(static_cast(text)->GetPtr()), + image == nullptr ? nullptr + : dynamic_pointer_cast(static_cast(image)->GetPtr()), dynamic_pointer_cast(static_cast(time)->GetPtr()), static_cast(message_type)); if (p == nullptr) {