Always send a filename

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 1aa8e35f55
commit 26b94bf94b

@ -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? {

@ -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);

Loading…
Cancel
Save