From e049990bf48d13cfffc765a0669cc036d73e4b35 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Mon, 16 Nov 2026 13:39:27 +0100 Subject: [PATCH] fix(chat): don't upload voice message when only permissions were requested When the record button was held without audio or storage permissions, only the permission request was triggered. Releasing the button still went through the send path because the "recording in progress" LiveData is null initially, which resulted in an upload of a non-existing file and a "Failed to upload file" notification. Track whether the current touch gesture actually started a recording and skip up/cancel/move handling otherwise. Additionally, don't upload when no voice record file exists. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- .../nextcloud/talk/chat/MessageInputFragment.kt | 15 ++++++++++++++- .../talk/chat/viewmodels/ChatViewModel.kt | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/nextcloud/talk/chat/MessageInputFragment.kt b/app/src/main/java/com/nextcloud/talk/chat/MessageInputFragment.kt index 2f451b9083f..8dab479de58 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/MessageInputFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/MessageInputFragment.kt @@ -596,10 +596,13 @@ class MessageInputFragment : Fragment() { var prevDx = 0f var voiceRecordStartTime = 0L var voiceRecordEndTime: Long + // only true when recording was started by the current touch gesture (not when permissions were requested) + var isRecordingGesture = false binding.fragmentMessageInputView.recordAudioButton.setOnTouchListener { v, event -> v?.performClick() when (event?.action) { MotionEvent.ACTION_DOWN -> { + isRecordingGesture = false if (!chatActivity.isRecordAudioPermissionGranted()) { chatActivity.requestRecordAudioPermissions() return@setOnTouchListener true @@ -616,11 +619,16 @@ class MessageInputFragment : Fragment() { binding.fragmentMessageInputView.audioRecordDuration.start() chatActivity.chatViewModel.startAudioRecording(requireContext(), chatActivity.currentConversation!!) showRecordAudioUi(true) + isRecordingGesture = true prevDx = event.x } MotionEvent.ACTION_CANCEL -> { Log.d(TAG, "ACTION_CANCEL") + if (!isRecordingGesture) { + return@setOnTouchListener true + } + isRecordingGesture = false if (chatActivity.chatViewModel.getVoiceRecordingInProgress.value == false || !chatActivity.isRecordAudioPermissionGranted() ) { @@ -635,6 +643,10 @@ class MessageInputFragment : Fragment() { MotionEvent.ACTION_UP -> { Log.d(TAG, "ACTION_UP") + if (!isRecordingGesture) { + return@setOnTouchListener false + } + isRecordingGesture = false if (chatActivity.chatViewModel.getVoiceRecordingInProgress.value == false || chatActivity.chatViewModel.getVoiceRecordingLocked.value == true || !chatActivity.isRecordAudioPermissionGranted() @@ -664,7 +676,8 @@ class MessageInputFragment : Fragment() { } MotionEvent.ACTION_MOVE -> { - if (chatActivity.chatViewModel.getVoiceRecordingInProgress.value == false || + if (!isRecordingGesture || + chatActivity.chatViewModel.getVoiceRecordingInProgress.value == false || !chatActivity.isRecordAudioPermissionGranted() ) { return@setOnTouchListener false diff --git a/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt b/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt index 611afc278b1..14773d6d63b 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/viewmodels/ChatViewModel.kt @@ -2399,6 +2399,12 @@ class ChatViewModel @AssistedInject constructor( fun stopAndSendAudioRecording(roomToken: String = "", replyToMessageId: Int? = null, displayName: String) { stopAudioRecording() + val voiceRecordFile = mediaRecorderManager.currentVoiceRecordFile + if (voiceRecordFile.isEmpty() || !File(voiceRecordFile).exists()) { + Log.w(TAG, "No voice recording file available. Nothing to upload") + return + } + if (mediaRecorderManager.mediaRecorderState != MediaRecorderManager.MediaRecorderState.ERROR) { val uri = Uri.fromFile(File(mediaRecorderManager.currentVoiceRecordFile)) Log.d(TAG, "File uploaded")