Fix sending voice messages without sound

This commit is contained in:
Ali 2020-10-19 00:55:26 +04:00
parent abcef0ff0e
commit a4a40a0aa3
5 changed files with 19 additions and 10 deletions

View File

@ -746,7 +746,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
} }
}, sendCurrentMessage: { [weak self] silentPosting in }, sendCurrentMessage: { [weak self] silentPosting in
if let strongSelf = self { if let strongSelf = self {
strongSelf.chatDisplayNode.sendCurrentMessage(silentPosting: silentPosting) if let _ = strongSelf.presentationInterfaceState.recordedMediaPreview {
strongSelf.sendMediaRecording(silently: silentPosting)
} else {
strongSelf.chatDisplayNode.sendCurrentMessage(silentPosting: silentPosting)
}
} }
}, sendMessage: { [weak self] text in }, sendMessage: { [weak self] text in
guard let strongSelf = self, canSendMessagesToChat(strongSelf.presentationInterfaceState) else { guard let strongSelf = self, canSendMessagesToChat(strongSelf.presentationInterfaceState) else {
@ -4646,8 +4650,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
strongSelf.lockMediaRecorder() strongSelf.lockMediaRecorder()
}, deleteRecordedMedia: { [weak self] in }, deleteRecordedMedia: { [weak self] in
self?.deleteMediaRecording() self?.deleteMediaRecording()
}, sendRecordedMedia: { [weak self] in }, sendRecordedMedia: { [weak self] silently in
self?.sendMediaRecording() self?.sendMediaRecording(silently: silently)
}, displayRestrictedInfo: { [weak self] subject, displayType in }, displayRestrictedInfo: { [weak self] subject, displayType in
guard let strongSelf = self else { guard let strongSelf = self else {
return return
@ -8278,7 +8282,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}) })
} }
private func sendMediaRecording() { private func sendMediaRecording(silently: Bool) {
self.chatDisplayNode.updateRecordedMediaDeleted(false) self.chatDisplayNode.updateRecordedMediaDeleted(false)
if let recordedMediaPreview = self.presentationInterfaceState.recordedMediaPreview { if let recordedMediaPreview = self.presentationInterfaceState.recordedMediaPreview {
if let _ = self.presentationInterfaceState.slowmodeState, !self.presentationInterfaceState.isScheduledMessages { if let _ = self.presentationInterfaceState.slowmodeState, !self.presentationInterfaceState.isScheduledMessages {
@ -8298,7 +8302,12 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
} }
}) })
self.sendMessages([.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: arc4random64()), partialReference: nil, resource: recordedMediaPreview.resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "audio/ogg", size: Int(recordedMediaPreview.fileSize), attributes: [.Audio(isVoice: true, duration: Int(recordedMediaPreview.duration), title: nil, performer: nil, waveform: waveformBuffer)])), replyToMessageId: self.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil)]) var attributes: [MessageAttribute] = []
if silently {
attributes.append(NotificationInfoMessageAttribute(flags: .muted))
}
self.sendMessages([.message(text: "", attributes: attributes, mediaReference: .standalone(media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: arc4random64()), partialReference: nil, resource: recordedMediaPreview.resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "audio/ogg", size: Int(recordedMediaPreview.fileSize), attributes: [.Audio(isVoice: true, duration: Int(recordedMediaPreview.duration), title: nil, performer: nil, waveform: waveformBuffer)])), replyToMessageId: self.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil)])
} }
} }

View File

@ -87,7 +87,7 @@ final class ChatPanelInterfaceInteraction {
let stopMediaRecording: () -> Void let stopMediaRecording: () -> Void
let lockMediaRecording: () -> Void let lockMediaRecording: () -> Void
let deleteRecordedMedia: () -> Void let deleteRecordedMedia: () -> Void
let sendRecordedMedia: () -> Void let sendRecordedMedia: (Bool) -> Void
let displayRestrictedInfo: (ChatPanelRestrictionInfoSubject, ChatPanelRestrictionInfoDisplayType) -> Void let displayRestrictedInfo: (ChatPanelRestrictionInfoSubject, ChatPanelRestrictionInfoDisplayType) -> Void
let displayVideoUnmuteTip: (CGPoint?) -> Void let displayVideoUnmuteTip: (CGPoint?) -> Void
let switchMediaRecordingMode: () -> Void let switchMediaRecordingMode: () -> Void
@ -163,7 +163,7 @@ final class ChatPanelInterfaceInteraction {
stopMediaRecording: @escaping () -> Void, stopMediaRecording: @escaping () -> Void,
lockMediaRecording: @escaping () -> Void, lockMediaRecording: @escaping () -> Void,
deleteRecordedMedia: @escaping () -> Void, deleteRecordedMedia: @escaping () -> Void,
sendRecordedMedia: @escaping () -> Void, sendRecordedMedia: @escaping (Bool) -> Void,
displayRestrictedInfo: @escaping (ChatPanelRestrictionInfoSubject, ChatPanelRestrictionInfoDisplayType) -> Void, displayRestrictedInfo: @escaping (ChatPanelRestrictionInfoSubject, ChatPanelRestrictionInfoDisplayType) -> Void,
displayVideoUnmuteTip: @escaping (CGPoint?) -> Void, displayVideoUnmuteTip: @escaping (CGPoint?) -> Void,
switchMediaRecordingMode: @escaping () -> Void, switchMediaRecordingMode: @escaping () -> Void,

View File

@ -91,7 +91,7 @@ final class ChatRecentActionsController: TelegramBaseController {
}, stopMediaRecording: { }, stopMediaRecording: {
}, lockMediaRecording: { }, lockMediaRecording: {
}, deleteRecordedMedia: { }, deleteRecordedMedia: {
}, sendRecordedMedia: { }, sendRecordedMedia: { _ in
}, displayRestrictedInfo: { _, _ in }, displayRestrictedInfo: { _, _ in
}, displayVideoUnmuteTip: { _ in }, displayVideoUnmuteTip: { _ in
}, switchMediaRecordingMode: { }, switchMediaRecordingMode: {

View File

@ -291,7 +291,7 @@ final class ChatRecordingPreviewInputPanelNode: ChatInputPanelNode {
} }
@objc func sendPressed() { @objc func sendPressed() {
self.interfaceInteraction?.sendRecordedMedia() self.interfaceInteraction?.sendRecordedMedia(false)
} }
@objc func waveformPressed() { @objc func waveformPressed() {

View File

@ -397,7 +397,7 @@ final class PeerInfoSelectionPanelNode: ASDisplayNode {
}, stopMediaRecording: { }, stopMediaRecording: {
}, lockMediaRecording: { }, lockMediaRecording: {
}, deleteRecordedMedia: { }, deleteRecordedMedia: {
}, sendRecordedMedia: { }, sendRecordedMedia: { _ in
}, displayRestrictedInfo: { _, _ in }, displayRestrictedInfo: { _, _ in
}, displayVideoUnmuteTip: { _ in }, displayVideoUnmuteTip: { _ in
}, switchMediaRecordingMode: { }, switchMediaRecordingMode: {