Bundle b;
b = AbstractItem::Serialize();
- b.Add(CHATMESSAGE_NAME_KEY,
- reinterpret_cast<char*>(impl_->name_->Serialize().ToRaw().first.get()));
- b.Add(CHATMESSAGE_TEXT_KEY,
- reinterpret_cast<char*>(impl_->text_->Serialize().ToRaw().first.get()));
- b.Add(CHATMESSAGE_IMAGE_KEY,
- reinterpret_cast<char*>(impl_->image_->Serialize().ToRaw().first.get()));
- b.Add(CHATMESSAGE_TIME_KEY,
- reinterpret_cast<char*>(impl_->time_->Serialize().ToRaw().first.get()));
+ if (impl_->name_ != nullptr)
+ b.Add(CHATMESSAGE_NAME_KEY,
+ reinterpret_cast<char*>(impl_->name_->Serialize().ToRaw().first.get()));
+
+ if (impl_->text_ != nullptr)
+ b.Add(CHATMESSAGE_TEXT_KEY,
+ reinterpret_cast<char*>(impl_->text_->Serialize().ToRaw().first.get()));
+
+ if (impl_->image_ != nullptr)
+ b.Add(CHATMESSAGE_IMAGE_KEY,
+ reinterpret_cast<char*>(impl_->image_->Serialize().ToRaw().first.get()));
+
+ if (impl_->time_ != nullptr)
+ b.Add(CHATMESSAGE_TIME_KEY,
+ reinterpret_cast<char*>(impl_->time_->Serialize().ToRaw().first.get()));
+
b.Add(CHATMESSAGE_TYPE_KEY, std::to_string(static_cast<int>(impl_->type_)));
return b;
}
void ChatMessageItem::Deserialize(Bundle b) {
AbstractItem::Deserialize(b);
- std::shared_ptr<AbstractItem> name =
- FactoryManager::GetInst().CreateItem(AbstractItem::Text);
- name.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_NAME_KEY)));
- impl_->name_ = std::static_pointer_cast<TextItem>(name);
-
- std::shared_ptr<AbstractItem> text =
- FactoryManager::GetInst().CreateItem(AbstractItem::Text);
- text.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TEXT_KEY)));
- impl_->text_ = std::static_pointer_cast<TextItem>(text);
-
- std::shared_ptr<AbstractItem> image =
- FactoryManager::GetInst().CreateItem(AbstractItem::Image);
- image.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_IMAGE_KEY)));
- impl_->image_ = std::static_pointer_cast<ImageItem>(image);
-
- std::shared_ptr<AbstractItem> time =
- FactoryManager::GetInst().CreateItem(AbstractItem::Time);
- time.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TIME_KEY)));
- impl_->time_ = std::static_pointer_cast<TimeItem>(time);
+ if (!b.GetString(CHATMESSAGE_NAME_KEY).empty()) {
+ std::shared_ptr<AbstractItem> name =
+ FactoryManager::GetInst().CreateItem(AbstractItem::Text);
+ name.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_NAME_KEY)));
+ impl_->name_ = std::static_pointer_cast<TextItem>(name);
+ }
+
+ if (!b.GetString(CHATMESSAGE_TEXT_KEY).empty()) {
+ std::shared_ptr<AbstractItem> text =
+ FactoryManager::GetInst().CreateItem(AbstractItem::Text);
+ text.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TEXT_KEY)));
+ impl_->text_ = std::static_pointer_cast<TextItem>(text);
+ }
+
+ if (!b.GetString(CHATMESSAGE_IMAGE_KEY).empty()) {
+ std::shared_ptr<AbstractItem> image =
+ FactoryManager::GetInst().CreateItem(AbstractItem::Image);
+ image.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_IMAGE_KEY)));
+ impl_->image_ = std::static_pointer_cast<ImageItem>(image);
+ }
+
+ if (!b.GetString(CHATMESSAGE_TIME_KEY).empty()) {
+ std::shared_ptr<AbstractItem> time =
+ FactoryManager::GetInst().CreateItem(AbstractItem::Time);
+ time.get()->Deserialize(Bundle(b.GetString(CHATMESSAGE_TIME_KEY)));
+ impl_->time_ = std::static_pointer_cast<TimeItem>(time);
+ }
impl_->type_ = static_cast<Type>(std::stoi(b.GetString(CHATMESSAGE_TYPE_KEY)));
}
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<TextItem>(static_cast<Handle*>(name)->GetPtr()),
- dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
- dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
+ text == nullptr ? nullptr
+ : dynamic_pointer_cast<TextItem>(static_cast<Handle*>(text)->GetPtr()),
+ image == nullptr ? nullptr
+ : dynamic_pointer_cast<ImageItem>(static_cast<Handle*>(image)->GetPtr()),
dynamic_pointer_cast<TimeItem>(static_cast<Handle*>(time)->GetPtr()),
static_cast<ChatMessageItem::Type>(message_type));
if (p == nullptr) {