Don’t load link preview on editing if it was disabled on sending

This commit is contained in:
Ilya Laktyushin 2021-01-23 23:42:02 +03:00
parent 0b1e72044a
commit 5c864ca979
5 changed files with 3557 additions and 7827 deletions

View File

@ -178,7 +178,6 @@ private final class VoiceChatVolumeContextItemNode: ASDisplayNode, ContextMenuCu
let delta = translation / self.bounds.width * 2.0
self.value = max(0.0, min(2.0, self.value + delta))
self.valueChanged(self.value, true)
break
default:
break
}

View File

@ -4569,13 +4569,20 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}
}
var inputTextMaxLength: Int32 = 4096
var webpageUrl: String?
for media in message.media {
if media is TelegramMediaImage || media is TelegramMediaFile {
inputTextMaxLength = strongSelf.context.currentLimitsConfiguration.with { $0 }.maxMediaCaptionLength
break
} else if let webpage = media as? TelegramMediaWebpage, case let .Loaded(content) = webpage.content {
webpageUrl = content.url
}
}
return $0.withUpdatedEditMessage(ChatEditMessageState(messageId: messageId, inputState: ChatTextInputState(inputText: chatInputStateStringWithAppliedEntities(message.text, entities: entities)), disableUrlPreview: nil, inputTextMaxLength: inputTextMaxLength))
let inputText = chatInputStateStringWithAppliedEntities(message.text, entities: entities)
var disableUrlPreview: String?
if let detectedWebpageUrl = detectUrl(inputText), webpageUrl == nil {
disableUrlPreview = detectedWebpageUrl
}
return $0.withUpdatedEditMessage(ChatEditMessageState(messageId: messageId, inputState: ChatTextInputState(inputText: inputText), disableUrlPreview: disableUrlPreview, inputTextMaxLength: inputTextMaxLength))
}
updated = updatedChatEditInterfaceMessageState(state: updated, message: message)

View File

@ -417,19 +417,11 @@ func searchQuerySuggestionResultStateForChatInterfacePresentationState(_ chatPre
private let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType([.link]).rawValue)
func urlPreviewStateForInputText(_ inputText: NSAttributedString?, context: AccountContext, currentQuery: String?) -> (String?, Signal<(TelegramMediaWebpage?) -> TelegramMediaWebpage?, NoError>)? {
guard let text = inputText else {
if currentQuery != nil {
return (nil, .single({ _ in return nil }))
} else {
return nil
}
}
if let dataDetector = dataDetector {
func detectUrl(_ inputText: NSAttributedString?) -> String? {
var detectedUrl: String?
if let text = inputText, let dataDetector = dataDetector {
let utf16 = text.string.utf16
var detectedUrl: String?
let nsRange = NSRange(location: 0, length: utf16.count)
let matches = dataDetector.matches(in: text.string, options: [], range: nsRange)
if let match = matches.first {
@ -444,7 +436,20 @@ func urlPreviewStateForInputText(_ inputText: NSAttributedString?, context: Acco
}
})
}
}
return detectedUrl
}
func urlPreviewStateForInputText(_ inputText: NSAttributedString?, context: AccountContext, currentQuery: String?) -> (String?, Signal<(TelegramMediaWebpage?) -> TelegramMediaWebpage?, NoError>)? {
guard let _ = inputText else {
if currentQuery != nil {
return (nil, .single({ _ in return nil }))
} else {
return nil
}
}
if let _ = dataDetector {
let detectedUrl = detectUrl(inputText)
if detectedUrl != currentQuery {
if let detectedUrl = detectedUrl {
return (detectedUrl, webpagePreview(account: context.account, url: detectedUrl) |> map { value in