Various fixes

This commit is contained in:
Ilya Laktyushin 2026-04-30 12:43:12 +02:00
parent f34fdef432
commit 29ecff3728
4 changed files with 50 additions and 15 deletions

View file

@ -2589,6 +2589,10 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
if case .user = itemPeer.chatMainPeer {
isUser = true
}
var isGuestChatAuthor = false
if case let .user(user) = messages.last?.author, let botInfo = user.botInfo, botInfo.flags.contains(.isGuestChat) {
isGuestChatAuthor = true
}
var peerText: String?
if case .savedMessagesChats = item.chatListLocation {
@ -2606,14 +2610,14 @@ public class ChatListItemNode: ItemListRevealOptionsItemNode {
if let message = messages.last, let forwardInfo = message.forwardInfo, let author = forwardInfo.author {
peerText = EnginePeer(author).compactDisplayTitle
}
} else if !isUser {
} else if !isUser || isGuestChatAuthor {
if case let .channel(peer) = peer, case .broadcast = peer.info {
} else if !displayAsMessage {
if let forwardInfo = message.forwardInfo, forwardInfo.flags.contains(.isImported), let authorSignature = forwardInfo.authorSignature {
peerText = authorSignature
} else {
peerText = author.id == account.peerId ? item.presentationData.strings.DialogList_You : EnginePeer(author).displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder)
authorIsCurrentChat = author.id == peer.id
authorIsCurrentChat = !isGuestChatAuthor && author.id == peer.id
}
}
}

View file

@ -254,16 +254,19 @@ private final class QuickShareToastScreenComponent: Component {
let contentSize = self.content.update(
transition: transition,
component: AnyComponent(MultilineTextComponent(text: .markdown(
text: tooltipText,
attributes: MarkdownAttributes(
body: MarkdownAttributeSet(font: Font.regular(14.0), textColor: .white),
bold: MarkdownAttributeSet(font: Font.semibold(14.0), textColor: environment.theme.list.itemAccentColor.withMultiplied(hue: 0.933, saturation: 0.61, brightness: 1.0)),
link: MarkdownAttributeSet(font: Font.regular(14.0), textColor: .white),
linkAttribute: { _ in return nil })
))),
component: AnyComponent(MultilineTextComponent(
text: .markdown(
text: tooltipText,
attributes: MarkdownAttributes(
body: MarkdownAttributeSet(font: Font.regular(14.0), textColor: .white),
bold: MarkdownAttributeSet(font: Font.semibold(14.0), textColor: environment.theme.list.itemAccentColor.withMultiplied(hue: 0.933, saturation: 0.61, brightness: 1.0)),
link: MarkdownAttributeSet(font: Font.regular(14.0), textColor: .white),
linkAttribute: { _ in return nil })
),
maximumNumberOfLines: 2
)),
environment: {},
containerSize: CGSize(width: availableContentSize.width - contentInsets.left - contentInsets.right - spacing - iconSize.width - actionButtonSize.width - 16.0 - 4.0, height: availableContentSize.height)
containerSize: CGSize(width: availableContentSize.width - contentInsets.left - contentInsets.right - spacing - iconSize.width - actionButtonSize.width - 16.0 - 8.0, height: availableContentSize.height)
)
var contentHeight: CGFloat = 0.0
@ -313,7 +316,7 @@ private final class QuickShareToastScreenComponent: Component {
self.backgroundView.updateColor(color: UIColor(white: 0.0, alpha: 0.7), transition: transition.containedViewLayoutTransition)
self.backgroundView.update(size: backgroundFrame.size, cornerRadius: 14.0, transition: transition.containedViewLayoutTransition)
self.backgroundView.update(size: backgroundFrame.size, cornerRadius: backgroundFrame.height * 0.5, transition: transition.containedViewLayoutTransition)
transition.setFrame(view: self.backgroundView, frame: backgroundFrame)
transition.setFrame(view: self.contentView, frame: CGRect(origin: .zero, size: backgroundFrame.size))

View file

@ -516,7 +516,12 @@ public final class WebAppController: ViewController, AttachmentContainable {
return
}
#endif*/
self.webView?.bindTrustedOrigin(from: url)
if !"".isEmpty {
self.webView?.bindTrustedOrigin(from: url)
} else {
self.webView?.setupEventProxySource()
}
self.webView?.load(URLRequest(url: url))
}

View file

@ -43,7 +43,19 @@ private func jsStringLiteral(_ value: String) -> String {
return "\"\""
}
private func eventProxySource(trustedOrigin: String) -> String {
private func eventProxySource() -> String {
return """
(function() {
var TelegramWebviewProxyProto = function() {};
TelegramWebviewProxyProto.prototype.postEvent = function(eventName, eventData) {
window.webkit.messageHandlers.performAction.postMessage({'eventName': eventName, 'eventData': eventData});
};
window.TelegramWebviewProxy = new TelegramWebviewProxyProto();
})();
"""
}
private func securedEventProxySource(trustedOrigin: String) -> String {
return """
(function() {
if (window.location.origin !== \(jsStringLiteral(trustedOrigin))) {
@ -202,6 +214,7 @@ final class WebAppWebView: WKWebView {
print()
}
var useSecuredEventProxy = true
func bindTrustedOrigin(from url: URL) {
guard self.trustedOrigin == nil else {
return
@ -212,7 +225,14 @@ final class WebAppWebView: WKWebView {
self.trustedOrigin = origin
let eventProxyScript = WKUserScript(source: eventProxySource(trustedOrigin: origin), injectionTime: .atDocumentStart, forMainFrameOnly: true)
let eventProxyScript = WKUserScript(source: securedEventProxySource(trustedOrigin: origin), injectionTime: .atDocumentStart, forMainFrameOnly: true)
self.configuration.userContentController.addUserScript(eventProxyScript)
}
func setupEventProxySource() {
self.useSecuredEventProxy = false
let eventProxyScript = WKUserScript(source: eventProxySource(), injectionTime: .atDocumentStart, forMainFrameOnly: true)
self.configuration.userContentController.addUserScript(eventProxyScript)
}
@ -220,6 +240,9 @@ final class WebAppWebView: WKWebView {
guard message.frameInfo.isMainFrame else {
return false
}
if !self.useSecuredEventProxy {
return true
}
guard let trustedOrigin = self.trustedOrigin else {
return false
}