Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,16 @@ fun ChatInputBar(
}
}

val voiceRecorder = rememberVoiceRecorder { path, duration, waveform ->
if (!canSendVoice || isSlowModeActive) return@rememberVoiceRecorder
actions.onSendVoice(path, duration, waveform)
activateSlowModeCooldown()
}
val voiceRecorder = rememberVoiceRecorder(
onRecordingFinished = { path, duration, waveform ->
if (!canSendVoice || isSlowModeActive) return@rememberVoiceRecorder
actions.onSendVoice(path, duration, waveform)
activateSlowModeCooldown()
},
onPermissionDenied = {
microphonePermissionLauncher.launch(Manifest.permission.RECORD_AUDIO)
}
)
val maxMessageLength by remember(
state.pendingMediaPaths,
state.pendingDocumentPaths,
Expand Down Expand Up @@ -614,6 +619,9 @@ fun ChatInputBar(
hasCameraPermission.value = granted
if (granted) showCamera = true
}
val microphonePermissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) { }
val documentsPickerLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.OpenMultipleDocuments()
) { uris ->
Expand Down Expand Up @@ -1093,4 +1101,5 @@ fun ChatInputBar(
}
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import kotlin.math.log10

@Composable
fun rememberVoiceRecorder(
onRecordingFinished: (String, Int, ByteArray) -> Unit
onRecordingFinished: (String, Int, ByteArray) -> Unit,
onPermissionDenied: () -> Unit = {}
): VoiceRecorderState {
val context = LocalContext.current
val state = remember { VoiceRecorderState(context) }
Expand All @@ -23,6 +24,10 @@ fun rememberVoiceRecorder(
state.onRecordingFinished = onRecordingFinished
}

LaunchedEffect(onPermissionDenied) {
state.onPermissionDenied = onPermissionDenied
}

DisposableEffect(Unit) {
onDispose {
state.stopRecording(cancel = true)
Expand Down Expand Up @@ -55,6 +60,7 @@ class VoiceRecorderState(private val context: Context) {
private var startTime = 0L

var onRecordingFinished: ((String, Int, ByteArray) -> Unit)? = null
var onPermissionDenied: (() -> Unit)? = null

@Suppress("DEPRECATION")
fun startRecording() {
Expand All @@ -65,7 +71,7 @@ class VoiceRecorderState(private val context: Context) {
Manifest.permission.RECORD_AUDIO
) != PackageManager.PERMISSION_GRANTED
) {
// TODO: Request permission
onPermissionDenied?.invoke()
return
}

Expand Down