Add a new constructor for FileAttachment to support precomputation of mime type and attachment type.

PiperOrigin-RevId: 672643121
This commit is contained in:
Anay Wadhera
2024-09-09 12:59:12 -07:00
committed by Copybara-Service
parent 48001e65cd
commit 5a1bfcb904
2 changed files with 3 additions and 1 deletions
+2 -1
View File
@@ -56,10 +56,11 @@ std::string MimeTypeFromPath(const std::filesystem::path& path) {
} // namespace
FileAttachment::FileAttachment(std::filesystem::path file_path,
absl::string_view mime_type,
std::string parent_folder, int32_t batch_id,
SourceType source_type)
: Attachment(Attachment::Family::kFile, /*size=*/0, batch_id, source_type),
mime_type_(MimeTypeFromPath(file_path)),
mime_type_(mime_type.empty() ? MimeTypeFromPath(file_path) : mime_type),
type_(FileAttachmentTypeFromMimeType(mime_type_)),
file_path_(std::move(file_path)),
parent_folder_(std::move(parent_folder)) {
+1
View File
@@ -36,6 +36,7 @@ class FileAttachment : public Attachment {
using Type = nearby::sharing::service::proto::FileMetadata::Type;
explicit FileAttachment(std::filesystem::path file_path,
absl::string_view mime_type = "",
std::string parent_folder = "", int32_t batch_id = 0,
SourceType source_type = SourceType::kUnknown);
FileAttachment(int64_t id, int64_t size, std::string file_name,