Skip to content

Commit

Permalink
/issues/4753 - Prevent unnecessary audio file conversions if final fi…
Browse files Browse the repository at this point in the history
…le already exists on disk.
  • Loading branch information
stefanceriu committed Dec 2, 2021
1 parent ec00c52 commit d3ea267
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ class VoiceMessageAttachmentCacheManager {
return
}

let newURL = temporaryFilesFolderURL.appendingPathComponent(ProcessInfo().globallyUniqueString).appendingPathExtension("m4a")
let newURL = temporaryFilesFolderURL.appendingPathComponent(identifier).appendingPathExtension("m4a")

VoiceMessageAudioConverter.convertToMPEG4AAC(sourceURL: URL(fileURLWithPath: filePath), destinationURL: newURL) { result in
let conversionCompletion: (Result<Void, VoiceMessageAudioConverterError>) -> Void = { result in
self.workQueue.async {
switch result {
case .success:
Expand Down Expand Up @@ -245,6 +245,12 @@ class VoiceMessageAttachmentCacheManager {
}
}
}

if FileManager.default.fileExists(atPath: newURL.path) {
conversionCompletion(Result.success(()))
} else {
VoiceMessageAudioConverter.convertToMPEG4AAC(sourceURL: URL(fileURLWithPath: filePath), destinationURL: newURL, completion: conversionCompletion)
}
}

private func sampleFileAtURL(_ url: URL, duration: TimeInterval, numberOfSamples: Int, identifier: String, semaphore: DispatchSemaphore) {
Expand Down
2 changes: 1 addition & 1 deletion changelog.d/4753.feature
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Allow audio file attachments to be played back inline by reusing the existing voice message UI.
Allow audio file attachments to be played back inline by reusing the existing voice message UI. Prevent unnecessary conversions if final file already exists on disk.

0 comments on commit d3ea267

Please sign in to comment.