From 776be65518adab6fb70e127eb8f02b4b6e05f711 Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Thu, 19 Sep 2024 19:58:05 +0200 Subject: [PATCH] Prevent Audio memo download in service extension + auto download them in app if configured as such --- .../Chat/Views/MultilineMessageCell.swift | 21 ++++++++++++++++++- .../NotificationService.swift | 15 +++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Classes/Swift/Chat/Views/MultilineMessageCell.swift b/Classes/Swift/Chat/Views/MultilineMessageCell.swift index 0d9c5af06..16ea62738 100644 --- a/Classes/Swift/Chat/Views/MultilineMessageCell.swift +++ b/Classes/Swift/Chat/Views/MultilineMessageCell.swift @@ -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 diff --git a/msgNotificationService/NotificationService.swift b/msgNotificationService/NotificationService.swift index 0cda96771..6bc2e2aca 100644 --- a/msgNotificationService/NotificationService.swift +++ b/msgNotificationService/NotificationService.swift @@ -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() {