Add UI to record a voice message from the composer toolbar (#1892)

This commit is contained in:
Nicolas Mauri
2023-10-16 17:18:51 +02:00
committed by GitHub
parent 0d72554e6f
commit 9ab3b20a49
43 changed files with 1241 additions and 87 deletions
@@ -40,6 +40,8 @@ enum RoomScreenComposerMode: Equatable {
case `default`
case reply(itemID: TimelineItemIdentifier, replyDetails: TimelineItemReplyDetails, isThread: Bool)
case edit(originalItemId: TimelineItemIdentifier)
case recordVoiceMessage(state: AudioRecorderState)
case previewVoiceMessage(state: AudioPlayerState)
var isEdit: Bool {
switch self {
@@ -186,6 +186,15 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
trackComposerMode(mode)
case .composerFocusedChanged(isFocused: let isFocused):
composerFocusedSubject.send(isFocused)
case .startRecordingVoiceMessage:
timelineController.pauseAudio()
startRecordingVoiceMessage()
case .stopRecordingVoiceMessage:
stopRecordingVoiceMessage()
case .deleteRecordedVoiceMessage:
deleteCurrentVoiceMessage()
case .sendVoiceMessage:
Task { await sendCurrentVoiceMessage() }
}
}
@@ -466,9 +475,11 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
await timelineController.editMessage(message, html: html, original: originalItemId)
case .default:
await timelineController.sendMessage(message, html: html)
case .recordVoiceMessage, .previewVoiceMessage:
fatalError("invalid composer mode.")
}
}
private func trackComposerMode(_ mode: RoomScreenComposerMode) {
var isEdit = false
var isReply = false
@@ -888,6 +899,34 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
private func audioPlayerState(for itemID: TimelineItemIdentifier) -> AudioPlayerState {
timelineController.audioPlayerState(for: itemID)
}
// MARK: - Voice message
private func startRecordingVoiceMessage() {
// Partially implemented
let audioRecordState = AudioRecorderState()
actionsSubject.send(.composer(action: .setMode(mode: .recordVoiceMessage(state: audioRecordState))))
}
private func stopRecordingVoiceMessage() {
// Partially implemented
let audioPlayerState = AudioPlayerState(duration: 0)
actionsSubject.send(.composer(action: .setMode(mode: .previewVoiceMessage(state: audioPlayerState))))
}
private func deleteCurrentVoiceMessage() {
// Partially implemented
actionsSubject.send(.composer(action: .setMode(mode: .default)))
}
private func sendCurrentVoiceMessage() async {
// Partially implemented
actionsSubject.send(.composer(action: .setMode(mode: .default)))
}
}
private extension RoomProxyProtocol {