diff --git a/sharing/linux/nearby_sharing_app.cc b/sharing/linux/nearby_sharing_app.cc index dffce13a..d70236d1 100644 --- a/sharing/linux/nearby_sharing_app.cc +++ b/sharing/linux/nearby_sharing_app.cc @@ -258,8 +258,6 @@ class NearbySharingApp { return; } - auto attachment_container = std::make_unique(); - // Use the constructor that accepts size std::string file_name = path.GetFileName().ToString(); std::string mime_type = ""; // Will be auto-detected from extension @@ -277,8 +275,11 @@ class NearbySharingApp { // Set the file path after construction file_attachment.set_file_path(path); - - attachment_container->AddFileAttachment(std::move(file_attachment)); + + auto attachment_container = AttachmentContainer::Builder() + .AddFileAttachment( + std::move(file_attachment)) + .Build(); service_->SendAttachments( target_id, @@ -298,14 +299,15 @@ class NearbySharingApp { std::cout << "Target ID: " << target_id << std::endl; std::cout << "Text: " << text << std::endl; - auto attachment_container = std::make_unique(); - - attachment_container->AddTextAttachment(TextAttachment( - nearby::sharing::service::proto::TextMetadata::TEXT, - text, - std::nullopt, // text_title - std::nullopt // mime_type - )); + auto attachment_container = AttachmentContainer::Builder() + .AddTextAttachment(TextAttachment( + nearby::sharing::service::proto:: + TextMetadata::TEXT, + text, + std::nullopt, // text_title + std::nullopt // mime_type + )) + .Build(); service_->SendAttachments( target_id, diff --git a/sharing/linux/nearby_sharing_service_linux.cc b/sharing/linux/nearby_sharing_service_linux.cc index 0ee445a5..c33b1e7d 100644 --- a/sharing/linux/nearby_sharing_service_linux.cc +++ b/sharing/linux/nearby_sharing_service_linux.cc @@ -356,10 +356,10 @@ void NearbySharingServiceLinux::SendAttachments( } TransferState transfer_state; - transfer_state.attachments = *attachment_container; + transfer_state.attachments = std::move(*attachment_container); transfer_state.callback = callback; transfer_state.is_incoming = false; - active_transfers_[*endpoint_id] = transfer_state; + active_transfers_[*endpoint_id] = std::move(transfer_state); TransferMetadata metadata = TransferMetadataBuilder().set_status(TransferMetadata::Status::kConnecting) @@ -368,7 +368,8 @@ void NearbySharingServiceLinux::SendAttachments( attachment_container->GetAttachmentCount()) .build(); if (auto share_target = GetShareTarget(*endpoint_id)) { - NotifyTransferUpdate(*share_target, transfer_state, metadata); + NotifyTransferUpdate(*share_target, active_transfers_[*endpoint_id], + metadata); } connections::ConnectionOptions options; @@ -903,13 +904,13 @@ void NearbySharingServiceLinux::HandleIncomingConnectionInitiated( transfer_state.attachments = AttachmentContainer(); transfer_state.callback = PickReceiveTransferCallback(); transfer_state.is_incoming = true; - active_transfers_[endpoint_id] = transfer_state; + active_transfers_[endpoint_id] = std::move(transfer_state); TransferMetadata metadata = TransferMetadataBuilder() .set_status(TransferMetadata::Status::kAwaitingLocalConfirmation) .set_progress(0) .build(); - NotifyTransferUpdate(target, transfer_state, metadata); + NotifyTransferUpdate(target, active_transfers_[endpoint_id], metadata); } void NearbySharingServiceLinux::HandleOutgoingConnectionInitiated( @@ -965,7 +966,7 @@ void NearbySharingServiceLinux::HandleConnectionAccepted( const auto& file_attachment = attachments.GetFileAttachments()[0]; if (file_attachment.file_path().has_value()) { std::string file_path = file_attachment.file_path()->ToString(); - nearby::InputFile input_file(file_path, file_attachment.size()); + nearby::InputFile input_file(file_path); payload = std::make_unique( std::string(file_attachment.parent_folder()), std::string(file_attachment.file_name()), std::move(input_file));