diff --git a/submodules/ContextUI/Sources/ContextControllerExtractedPresentationNode.swift b/submodules/ContextUI/Sources/ContextControllerExtractedPresentationNode.swift index b86814d61b..dd554d8402 100644 --- a/submodules/ContextUI/Sources/ContextControllerExtractedPresentationNode.swift +++ b/submodules/ContextUI/Sources/ContextControllerExtractedPresentationNode.swift @@ -755,9 +755,12 @@ final class ContextControllerExtractedPresentationNode: ASDisplayNode, ContextCo } else { return } - case .controller: + case let .controller(source): if let contentNode = controllerContentNode { var defaultContentSize = CGSize(width: layout.size.width - 12.0 * 2.0, height: layout.size.height - 12.0 * 2.0 - contentTopInset - layout.safeInsets.bottom) + if case .regular = layout.metrics.widthClass { + defaultContentSize.width = min(defaultContentSize.width, 400.0) + } defaultContentSize.height = min(defaultContentSize.height, 460.0) let contentSize: CGSize @@ -770,7 +773,30 @@ final class ContextControllerExtractedPresentationNode: ASDisplayNode, ContextCo isContentResizeableVertically = true } - contentRect = CGRect(origin: CGPoint(x: floor((layout.size.width - contentSize.width) * 0.5), y: floor((layout.size.height - contentSize.height) * 0.5)), size: contentSize) + if case .regular = layout.metrics.widthClass { + if let transitionInfo = source.transitionInfo(), let (sourceView, sourceRect) = transitionInfo.sourceNode() { + let sourcePoint = sourceView.convert(sourceRect.center, to: self.view) + + contentRect = CGRect(origin: CGPoint(x: sourcePoint.x - floor(contentSize.width * 0.5), y: sourcePoint.y - floor(contentSize.height * 0.5)), size: contentSize) + if contentRect.origin.x < 0.0 { + contentRect.origin.x = 0.0 + } + if contentRect.origin.y < 0.0 { + contentRect.origin.y = 0.0 + } + if contentRect.origin.x + contentRect.width > layout.size.width { + contentRect.origin.x = layout.size.width - contentRect.width + } + if contentRect.origin.y + contentRect.height > layout.size.height { + contentRect.origin.y = layout.size.height - contentRect.height + } + } else { + contentRect = CGRect(origin: CGPoint(x: floor((layout.size.width - contentSize.width) * 0.5), y: floor((layout.size.height - contentSize.height) * 0.5)), size: contentSize) + } + } else { + contentRect = CGRect(origin: CGPoint(x: floor((layout.size.width - contentSize.width) * 0.5), y: floor((layout.size.height - contentSize.height) * 0.5)), size: contentSize) + } + contentParentGlobalFrame = CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: layout.size.width, height: layout.size.height)) } else { return @@ -815,9 +841,9 @@ final class ContextControllerExtractedPresentationNode: ASDisplayNode, ContextCo let actionsStackPresentation: ContextControllerActionsStackNode.Presentation switch self.source { - case .location, .reference: + case .location, .reference, .controller: actionsStackPresentation = .inline - case .extracted, .controller: + case .extracted: actionsStackPresentation = .modal } @@ -841,7 +867,10 @@ final class ContextControllerExtractedPresentationNode: ASDisplayNode, ContextCo contentHeight = min(contentHeight, contentRect.height) contentHeight = max(contentHeight, 200.0) - contentRect = CGRect(origin: CGPoint(x: 12.0, y: floor((layout.size.height - contentHeight) * 0.5)), size: CGSize(width: layout.size.width - 12.0 * 2.0, height: contentHeight)) + if case .regular = layout.metrics.widthClass { + } else { + contentRect = CGRect(origin: CGPoint(x: contentRect.minX, y: floor(contentRect.midY - contentHeight * 0.5)), size: CGSize(width: contentRect.width, height: contentHeight)) + } } var isAnimatingOut = false diff --git a/submodules/ContextUI/Sources/ContextSourceContainer.swift b/submodules/ContextUI/Sources/ContextSourceContainer.swift index 3eb6dffbf8..a12b0cd501 100644 --- a/submodules/ContextUI/Sources/ContextSourceContainer.swift +++ b/submodules/ContextUI/Sources/ContextSourceContainer.swift @@ -570,12 +570,21 @@ final class ContextSourceContainer: ASDisplayNode { transition: .immediate ) case .controller: - self.backgroundNode.updateColor( - color: presentationData.theme.contextMenu.dimColor, - enableBlur: true, - forceKeepBlur: true, - transition: .immediate - ) + if case .regular = layout.metrics.widthClass { + self.backgroundNode.updateColor( + color: UIColor(white: 0.0, alpha: 0.4), + enableBlur: false, + forceKeepBlur: false, + transition: .immediate + ) + } else { + self.backgroundNode.updateColor( + color: presentationData.theme.contextMenu.dimColor, + enableBlur: true, + forceKeepBlur: true, + transition: .immediate + ) + } } } diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_OutgoingChatContextResultMessageAttribute.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_OutgoingChatContextResultMessageAttribute.swift index b6117cd959..aa9d797551 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_OutgoingChatContextResultMessageAttribute.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_OutgoingChatContextResultMessageAttribute.swift @@ -5,22 +5,30 @@ public class OutgoingChatContextResultMessageAttribute: MessageAttribute { public let queryId: Int64 public let id: String public let hideVia: Bool + public let webpageUrl: String? - public init(queryId: Int64, id: String, hideVia: Bool) { + public init(queryId: Int64, id: String, hideVia: Bool, webpageUrl: String?) { self.queryId = queryId self.id = id self.hideVia = hideVia + self.webpageUrl = webpageUrl } required public init(decoder: PostboxDecoder) { self.queryId = decoder.decodeInt64ForKey("q", orElse: 0) self.id = decoder.decodeStringForKey("i", orElse: "") self.hideVia = decoder.decodeBoolForKey("v", orElse: false) + self.webpageUrl = decoder.decodeOptionalStringForKey("wurl") } public func encode(_ encoder: PostboxEncoder) { encoder.encodeInt64(self.queryId, forKey: "q") encoder.encodeString(self.id, forKey: "i") encoder.encodeBool(self.hideVia, forKey: "v") + if let webpageUrl = self.webpageUrl { + encoder.encodeString(webpageUrl, forKey: "wurl") + } else { + encoder.encodeNil(forKey: "wurl") + } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/OutgoingMessageWithChatContextResult.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/OutgoingMessageWithChatContextResult.swift index 5abaa52dbb..02f176275a 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/OutgoingMessageWithChatContextResult.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/OutgoingMessageWithChatContextResult.swift @@ -16,8 +16,13 @@ func _internal_outgoingMessageWithChatContextResult(to peerId: PeerId, threadId: replyToMessageId = EngineMessageReplySubject(messageId: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: MessageId.Id(clamping: threadId)), quote: nil) } + var webpageUrl: String? + if case let .webpage(_, _, url, _, _) = result.message { + webpageUrl = url + } + var attributes: [MessageAttribute] = [] - attributes.append(OutgoingChatContextResultMessageAttribute(queryId: result.queryId, id: result.id, hideVia: hideVia)) + attributes.append(OutgoingChatContextResultMessageAttribute(queryId: result.queryId, id: result.id, hideVia: hideVia, webpageUrl: webpageUrl)) if !hideVia { attributes.append(InlineBotMessageAttribute(peerId: botId, title: nil)) }