Skip to content

Commit

Permalink
Merge pull request #7245 from vector-im/nimau/7235_prevent_new_voicem…
Browse files Browse the repository at this point in the history
…essage_during_VB

Send voice message should not be allowed during a voice broadcast recording (#7235)
  • Loading branch information
nimau authored Jan 9, 2023
2 parents ec02f51 + 3ba73df commit b1b2a4b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,8 @@ Tap the + to start adding people.";
"voice_message_remaining_recording_time" = "%@s left";
"voice_message_stop_locked_mode_recording" = "Tap on your recording to stop or listen";
"voice_message_lock_screen_placeholder" = "Voice message";
"voice_message_broadcast_in_progress_title" = "Can't start voice message";
"voice_message_broadcast_in_progress_message" = "You can't start a voice message as you are currently recording a live broadcast. Please end your live broadcast in order to start recording a voice message";

// Mark: - Voice broadcast
"voice_broadcast_unauthorized_title" = "Can't start a new voice broadcast";
Expand Down
8 changes: 8 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9207,6 +9207,14 @@ public class VectorL10n: NSObject {
public static var voiceBroadcastUnauthorizedTitle: String {
return VectorL10n.tr("Vector", "voice_broadcast_unauthorized_title")
}
/// You can't start a voice message as you are currently recording a live broadcast. Please end your live broadcast in order to start recording a voice message
public static var voiceMessageBroadcastInProgressMessage: String {
return VectorL10n.tr("Vector", "voice_message_broadcast_in_progress_message")
}
/// Can't start voice message
public static var voiceMessageBroadcastInProgressTitle: String {
return VectorL10n.tr("Vector", "voice_message_broadcast_in_progress_title")
}
/// Voice message
public static var voiceMessageLockScreenPlaceholder: String {
return VectorL10n.tr("Vector", "voice_message_lock_screen_placeholder")
Expand Down
14 changes: 14 additions & 0 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7887,6 +7887,20 @@ - (void)voiceMessageControllerDidRequestMicrophonePermission:(VoiceMessageContro
}];
}

- (BOOL)voiceMessageControllerDidRequestRecording:(VoiceMessageController *)voiceMessageController
{
MXSession* session = self.roomDataSource.mxSession;
// Check whether the user is not already broadcasting here or in another room
if (session.voiceBroadcastService)
{
[self showAlertWithTitle:[VectorL10n voiceMessageBroadcastInProgressTitle] message:[VectorL10n voiceMessageBroadcastInProgressMessage]];

return NO;
}

return YES;
}

- (void)voiceMessageController:(VoiceMessageController *)voiceMessageController
didRequestSendForFileAtURL:(NSURL *)url
duration:(NSUInteger)duration
Expand Down
8 changes: 8 additions & 0 deletions Riot/Modules/Room/VoiceMessages/VoiceMessageController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import DSWaveformImage

@objc public protocol VoiceMessageControllerDelegate: AnyObject {
func voiceMessageControllerDidRequestMicrophonePermission(_ voiceMessageController: VoiceMessageController)
func voiceMessageControllerDidRequestRecording(_ voiceMessageController: VoiceMessageController) -> Bool
func voiceMessageController(_ voiceMessageController: VoiceMessageController, didRequestSendForFileAtURL url: URL, duration: UInt, samples: [Float]?, completion: @escaping (Bool) -> Void)
}

Expand Down Expand Up @@ -106,6 +107,13 @@ public class VoiceMessageController: NSObject, VoiceMessageToolbarViewDelegate,
guard let temporaryFileURL = temporaryFileURL else {
return
}

// Ask our delegate if we can start recording
let canStartRecording = delegate?.voiceMessageControllerDidRequestRecording(self) ?? true
guard canStartRecording else {
return
}

guard AVAudioSession.sharedInstance().recordPermission == .granted else {
delegate?.voiceMessageControllerDidRequestMicrophonePermission(self)
return
Expand Down
1 change: 1 addition & 0 deletions changelog.d/7235.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Voice Broadcast: Prevent sending voice message during a voice broadcast recording

0 comments on commit b1b2a4b

Please sign in to comment.