Always send a filename

// FREEBIE
This commit is contained in:
Michael Kirk 2017-04-24 14:03:28 -04:00
parent 1aa8e35f55
commit 26b94bf94b
2 changed files with 22 additions and 1 deletions

View File

@ -181,6 +181,27 @@ class SignalAttachment: NSObject {
return mimeType?.takeRetainedValue() as? String
}
// Use the filename if known. If not, e.g. if the attachment was copy/pasted, we'll generate a filename
// like: "signal-2017-04-24-095918.zip"
var filenameOrDefault: String {
if let filename = filename {
return filename
} else {
let kDefaultAttachmentName = "signal"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "YYYY-MM-dd-HHmmss"
let dateString = dateFormatter.string(from: Date())
let withoutExtension = "\(kDefaultAttachmentName)-\(dateString)"
if let fileExtension = self.fileExtension {
return "\(withoutExtension).\(fileExtension)"
}
return withoutExtension
}
}
// Returns the file extension for this attachment or nil if no file extension
// can be identified.
var fileExtension: String? {

View File

@ -64,7 +64,7 @@ NS_ASSUME_NONNULL_BEGIN
expiresInSeconds:(configuration.isEnabled ? configuration.durationSeconds : 0)];
[messageSender sendAttachmentData:attachment.data
contentType:attachment.mimeType
filename:attachment.filename
filename:attachment.filenameOrDefault
inMessage:message
success:^{
DDLogDebug(@"%@ Successfully sent message attachment.", self.tag);