From 62cd92e9d2c76860a0ebe51b6e77d2571e2bc59e Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sun, 23 Oct 2022 22:34:30 +0300 Subject: [PATCH] Voice to text improvements --- .../AccountContext/Sources/ChatController.swift | 17 +++++++++++++++-- .../TelegramUI/Sources/ChatControllerNode.swift | 2 ++ .../Sources/ChatHistoryListNode.swift | 9 +++++++-- .../ChatMessageInteractiveFileNode.swift | 4 ++-- ...ChatMessageInteractiveInstantVideoNode.swift | 8 ++++++-- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/submodules/AccountContext/Sources/ChatController.swift b/submodules/AccountContext/Sources/ChatController.swift index 4bd86d488e..80e10e4ea5 100644 --- a/submodules/AccountContext/Sources/ChatController.swift +++ b/submodules/AccountContext/Sources/ChatController.swift @@ -15,6 +15,19 @@ public final class ChatMessageItemAssociatedData: Equatable { case known(EnginePeer.Id?) } + public struct DisplayTranscribeButton: Equatable { + public let canBeDisplayed: Bool + public let displayForNotConsumed: Bool + + public init( + canBeDisplayed: Bool, + displayForNotConsumed: Bool + ) { + self.canBeDisplayed = canBeDisplayed + self.displayForNotConsumed = displayForNotConsumed + } + } + public let automaticDownloadPeerType: MediaAutoDownloadPeerType public let automaticDownloadNetworkType: MediaAutoDownloadNetworkType public let isRecentActions: Bool @@ -30,11 +43,11 @@ public final class ChatMessageItemAssociatedData: Equatable { public let defaultReaction: MessageReaction.Reaction? public let isPremium: Bool public let forceInlineReactions: Bool - public let alwaysDisplayTranscribeButton: Bool + public let alwaysDisplayTranscribeButton: DisplayTranscribeButton public let accountPeer: EnginePeer? public let topicAuthorId: EnginePeer.Id? - public init(automaticDownloadPeerType: MediaAutoDownloadPeerType, automaticDownloadNetworkType: MediaAutoDownloadNetworkType, isRecentActions: Bool = false, subject: ChatControllerSubject? = nil, contactsPeerIds: Set = Set(), channelDiscussionGroup: ChannelDiscussionGroupStatus = .unknown, animatedEmojiStickers: [String: [StickerPackItem]] = [:], additionalAnimatedEmojiStickers: [String: [Int: StickerPackItem]] = [:], forcedResourceStatus: FileMediaResourceStatus? = nil, currentlyPlayingMessageId: EngineMessage.Index? = nil, isCopyProtectionEnabled: Bool = false, availableReactions: AvailableReactions?, defaultReaction: MessageReaction.Reaction?, isPremium: Bool, accountPeer: EnginePeer?, forceInlineReactions: Bool = false, alwaysDisplayTranscribeButton: Bool = false, topicAuthorId: EnginePeer.Id? = nil) { + public init(automaticDownloadPeerType: MediaAutoDownloadPeerType, automaticDownloadNetworkType: MediaAutoDownloadNetworkType, isRecentActions: Bool = false, subject: ChatControllerSubject? = nil, contactsPeerIds: Set = Set(), channelDiscussionGroup: ChannelDiscussionGroupStatus = .unknown, animatedEmojiStickers: [String: [StickerPackItem]] = [:], additionalAnimatedEmojiStickers: [String: [Int: StickerPackItem]] = [:], forcedResourceStatus: FileMediaResourceStatus? = nil, currentlyPlayingMessageId: EngineMessage.Index? = nil, isCopyProtectionEnabled: Bool = false, availableReactions: AvailableReactions?, defaultReaction: MessageReaction.Reaction?, isPremium: Bool, accountPeer: EnginePeer?, forceInlineReactions: Bool = false, alwaysDisplayTranscribeButton: DisplayTranscribeButton = DisplayTranscribeButton(canBeDisplayed: false, displayForNotConsumed: false), topicAuthorId: EnginePeer.Id? = nil) { self.automaticDownloadPeerType = automaticDownloadPeerType self.automaticDownloadNetworkType = automaticDownloadNetworkType self.isRecentActions = isRecentActions diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index edae928325..e53864f3f2 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -3069,6 +3069,8 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { func sendCurrentMessage(silentPosting: Bool? = nil, scheduleTime: Int32? = nil, completion: @escaping () -> Void = {}) { if let textInputPanelNode = self.inputPanelNode as? ChatTextInputPanelNode { + self.historyNode.justSentTextMessage = true + if let textInputNode = textInputPanelNode.textInputNode, textInputNode.isFirstResponder() { Keyboard.applyAutocorrection(textView: textInputNode.textView) } diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index 4991347a36..12d8ec9695 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -315,7 +315,7 @@ private final class ChatHistoryTransactionOpaqueState { } } -private func extractAssociatedData(chatLocation: ChatLocation, view: MessageHistoryView, automaticDownloadNetworkType: MediaAutoDownloadNetworkType, animatedEmojiStickers: [String: [StickerPackItem]], additionalAnimatedEmojiStickers: [String: [Int: StickerPackItem]], subject: ChatControllerSubject?, currentlyPlayingMessageId: MessageIndex?, isCopyProtectionEnabled: Bool, availableReactions: AvailableReactions?, defaultReaction: MessageReaction.Reaction?, isPremium: Bool, alwaysDisplayTranscribeButton: Bool, accountPeer: EnginePeer?, topicAuthorId: EnginePeer.Id?) -> ChatMessageItemAssociatedData { +private func extractAssociatedData(chatLocation: ChatLocation, view: MessageHistoryView, automaticDownloadNetworkType: MediaAutoDownloadNetworkType, animatedEmojiStickers: [String: [StickerPackItem]], additionalAnimatedEmojiStickers: [String: [Int: StickerPackItem]], subject: ChatControllerSubject?, currentlyPlayingMessageId: MessageIndex?, isCopyProtectionEnabled: Bool, availableReactions: AvailableReactions?, defaultReaction: MessageReaction.Reaction?, isPremium: Bool, alwaysDisplayTranscribeButton: ChatMessageItemAssociatedData.DisplayTranscribeButton, accountPeer: EnginePeer?, topicAuthorId: EnginePeer.Id?) -> ChatMessageItemAssociatedData { var automaticMediaDownloadPeerType: MediaAutoDownloadPeerType = .channel var contactsPeerIds: Set = Set() var channelDiscussionGroup: ChatMessageItemAssociatedData.ChannelDiscussionGroupStatus = .unknown @@ -1220,7 +1220,12 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { isPremium = true } - let associatedData = extractAssociatedData(chatLocation: chatLocation, view: view, automaticDownloadNetworkType: networkType, animatedEmojiStickers: animatedEmojiStickers, additionalAnimatedEmojiStickers: additionalAnimatedEmojiStickers, subject: subject, currentlyPlayingMessageId: currentlyPlayingMessageId, isCopyProtectionEnabled: isCopyProtectionEnabled, availableReactions: availableReactions, defaultReaction: defaultReaction, isPremium: isPremium, alwaysDisplayTranscribeButton: suggestAudioTranscription.0 < 2, accountPeer: accountPeer, topicAuthorId: topicAuthorId) + let alwaysDisplayTranscribeButton = ChatMessageItemAssociatedData.DisplayTranscribeButton( + canBeDisplayed: suggestAudioTranscription.0 < 2, + displayForNotConsumed: suggestAudioTranscription.1 + ) + + let associatedData = extractAssociatedData(chatLocation: chatLocation, view: view, automaticDownloadNetworkType: networkType, animatedEmojiStickers: animatedEmojiStickers, additionalAnimatedEmojiStickers: additionalAnimatedEmojiStickers, subject: subject, currentlyPlayingMessageId: currentlyPlayingMessageId, isCopyProtectionEnabled: isCopyProtectionEnabled, availableReactions: availableReactions, defaultReaction: defaultReaction, isPremium: isPremium, alwaysDisplayTranscribeButton: alwaysDisplayTranscribeButton, accountPeer: accountPeer, topicAuthorId: topicAuthorId) let filteredEntries = chatHistoryEntriesForView( location: chatLocation, diff --git a/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift b/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift index d17f211e40..8666a411cb 100644 --- a/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageInteractiveFileNode.swift @@ -676,10 +676,10 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode { if arguments.message.id.peerId.namespace != Namespaces.Peer.SecretChat { if arguments.associatedData.isPremium { displayTranscribe = true - } else if arguments.associatedData.alwaysDisplayTranscribeButton { + } else if arguments.associatedData.alwaysDisplayTranscribeButton.canBeDisplayed { if audioDuration >= 60 { displayTranscribe = true - } else if isConsumed == false { + } else if arguments.incoming && isConsumed == false && arguments.associatedData.alwaysDisplayTranscribeButton.displayForNotConsumed { displayTranscribe = true } else { displayTranscribe = false diff --git a/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift b/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift index e79d7fd133..fc93674fee 100644 --- a/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageInteractiveInstantVideoNode.swift @@ -735,8 +735,12 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { if item.message.id.peerId.namespace != Namespaces.Peer.SecretChat && statusDisplayType == .free { if item.associatedData.isPremium { displayTranscribe = true - } else if item.associatedData.alwaysDisplayTranscribeButton { - displayTranscribe = true + } else if item.associatedData.alwaysDisplayTranscribeButton.canBeDisplayed { + if incoming && notConsumed && item.associatedData.alwaysDisplayTranscribeButton.displayForNotConsumed { + displayTranscribe = true + } else { + displayTranscribe = false + } } else { displayTranscribe = false }