Prevent Audio memo download in service extension + auto download them in app if configured as such

This commit is contained in:
Christophe Deschamps 2024-09-19 19:58:05 +02:00
parent abea256244
commit 776be65518
2 changed files with 35 additions and 1 deletions

View file

@ -646,6 +646,7 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
recordingDurationTextView.text = recordingDuration(filePathRecording)
recordingPlayButton.onClickAction = {
self.downloadAudioMemoIfNeeded(message: message)
self.playRecordedMessage(voiceRecorder: filePathRecording, recordingPlayButton: recordingPlayButton, recordingStopButton: recordingStopButton, recordingWaveView: recordingWaveView, message: message)
}
recordingStopButton.onClickAction = {
@ -661,9 +662,27 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
NSLayoutConstraint.activate(recordingWaveConstraints)
}
if (Core.get().autoDownloadVoiceRecordingsEnabled) {
downloadAudioMemoIfNeeded(message: message)
}
recordingView.isHidden = false
}
func downloadAudioMemoIfNeeded(message: ChatMessage) {
if let audioContent = message.contents.filter({$0.isVoiceRecording}).first {
if (audioContent.filePath == nil || !FileUtil.fileExistsAndIsNotEmpty(path: audioContent.filePath!)) {
audioContent.filePath = LinphoneManager.imagesDirectory() + audioContent.name!;
if message.downloadContent(content: audioContent) {
Log.i("Started downloading voice memo")
} else {
Log.i("An error occured downloading voice memo")
}
return
}
}
}
func initReplyView(){
//Reply - Contents
@ -1806,7 +1825,7 @@ class MultilineMessageCell: SwipeCollectionViewCell, UICollectionViewDataSource,
AudioPlayer.sharedModel.fileChanged.value = voiceRecorder
recordingPlayButton.isHidden = true
recordingStopButton.isHidden = false
AudioPlayer.startSharedPlayer(voiceRecorder)
isPlayingVoiceRecording = true

View file

@ -233,6 +233,21 @@ class NotificationService: UNNotificationServiceExtension {
NotificationService.logDelegate = try! LinphoneLoggingServiceManager(config: config!, log: NotificationService.log, domain: "msgNotificationService")
}
lc = try! Factory.Instance.createSharedCoreWithConfig(config: config!, systemContext: nil, appGroupId: APP_GROUP_ID, mainCore: false)
// Disable auto downloads in service extension
// Save config values
let configMaxSizeForAutoDownloadIncomingFiles = config?.getInt(section: "app", key: "auto_download_incoming_files_max_size", defaultValue: -1)
let configAutoDownloadVoiceRecordingsEnabled = config?.getBool(section: "app", key: "auto_download_incoming_voice_recordings", defaultValue: true)
// Disable downloads in service extension (API calls below will set the core attributes value + config)
lc?.maxSizeForAutoDownloadIncomingFiles = -1
lc?.autoDownloadVoiceRecordingsEnabled = false
// restore the config values for the app
config?.setInt(section: "app", key: "auto_download_incoming_files_max_size", value: configMaxSizeForAutoDownloadIncomingFiles!)
config?.setBool(section: "app", key: "auto_download_incoming_voice_recordings", value: configAutoDownloadVoiceRecordingsEnabled!)
}
func stopCore() {