mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-15 13:35:19 +00:00
Various fixes
This commit is contained in:
parent
90bba2d84a
commit
f62efe1ed6
@ -441,7 +441,7 @@ final class AddressBarContentComponent: Component {
|
||||
textField.addTarget(self, action: #selector(self.textFieldChanged(_:)), for: .editingChanged)
|
||||
}
|
||||
|
||||
let address = getDisplayUrl(self.component?.url ?? "")
|
||||
let address = getDisplayUrl(self.component?.url ?? "", trim: false)
|
||||
if textField.text != address {
|
||||
textField.text = address
|
||||
self.clearIconView.isHidden = address.isEmpty
|
||||
|
@ -1390,6 +1390,16 @@ public class BrowserScreen: ViewController, MinimizableController {
|
||||
]
|
||||
|
||||
public init(context: AccountContext, subject: Subject, openPreviousOnClose: Bool = false) {
|
||||
var subject = subject
|
||||
if case let .webPage(url) = subject, let parsedUrl = URL(string: url) {
|
||||
if parsedUrl.host?.hasSuffix(".ton") == true {
|
||||
var urlComponents = URLComponents(string: url)
|
||||
urlComponents?.scheme = "tonsite"
|
||||
if let updatedUrl = urlComponents?.url?.absoluteString {
|
||||
subject = .webPage(url: updatedUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
self.context = context
|
||||
self.subject = subject
|
||||
self.openPreviousOnClose = openPreviousOnClose
|
||||
|
@ -111,7 +111,7 @@ func getPrimaryUrl(message: Message) -> String? {
|
||||
|
||||
private let asciiChars = CharacterSet(charactersIn: "a".unicodeScalars.first! ... "z".unicodeScalars.first!)
|
||||
|
||||
func getDisplayUrl(_ url: String, hostOnly: Bool = false) -> String {
|
||||
func getDisplayUrl(_ url: String, hostOnly: Bool = false, trim: Bool = true) -> String {
|
||||
if hostOnly {
|
||||
var title = url
|
||||
if let parsedUrl = URL(string: url) {
|
||||
@ -143,10 +143,12 @@ func getDisplayUrl(_ url: String, hostOnly: Bool = false) -> String {
|
||||
}
|
||||
}
|
||||
}
|
||||
address = address.replacingOccurrences(of: "https://www.", with: "")
|
||||
address = address.replacingOccurrences(of: "https://", with: "")
|
||||
address = address.replacingOccurrences(of: "tonsite://", with: "")
|
||||
address = address.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
|
||||
if trim {
|
||||
address = address.replacingOccurrences(of: "https://www.", with: "")
|
||||
address = address.replacingOccurrences(of: "https://", with: "")
|
||||
address = address.replacingOccurrences(of: "tonsite://", with: "")
|
||||
address = address.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
|
||||
}
|
||||
return address
|
||||
}
|
||||
}
|
||||
|
@ -433,7 +433,7 @@ public func chatTextLinkEditController(sharedContext: SharedAccountContext, upda
|
||||
return
|
||||
}
|
||||
let updatedLink = explicitUrl(contentNode.link)
|
||||
if !updatedLink.isEmpty && isValidUrl(updatedLink, validSchemes: ["http": true, "https": true, "tg": false, "ton": false]) {
|
||||
if !updatedLink.isEmpty && isValidUrl(updatedLink, validSchemes: ["http": true, "https": true, "tg": false, "ton": false, "tonsite": true]) {
|
||||
dismissImpl?(true)
|
||||
apply(updatedLink)
|
||||
} else if allowEmpty && contentNode.link.isEmpty {
|
||||
|
@ -381,15 +381,15 @@ func openChatMessageImpl(_ params: OpenChatMessageParams) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func makeInstantPageControllerImpl(context: AccountContext, message: Message, sourcePeerType: MediaAutoDownloadPeerType?, navigationController: NavigationController) -> ViewController? {
|
||||
func makeInstantPageControllerImpl(context: AccountContext, message: Message, sourcePeerType: MediaAutoDownloadPeerType?) -> ViewController? {
|
||||
guard let (webpage, anchor) = instantPageAndAnchor(message: message) else {
|
||||
return nil
|
||||
}
|
||||
let sourceLocation = InstantPageSourceLocation(userLocation: .peer(message.id.peerId), peerType: sourcePeerType ?? .channel)
|
||||
return makeInstantPageControllerImpl(context: context, webPage: webpage, anchor: anchor, sourceLocation: sourceLocation, navigationController: navigationController)
|
||||
return makeInstantPageControllerImpl(context: context, webPage: webpage, anchor: anchor, sourceLocation: sourceLocation)
|
||||
}
|
||||
|
||||
func makeInstantPageControllerImpl(context: AccountContext, webPage: TelegramMediaWebpage, anchor: String?, sourceLocation: InstantPageSourceLocation, navigationController: NavigationController) -> ViewController {
|
||||
func makeInstantPageControllerImpl(context: AccountContext, webPage: TelegramMediaWebpage, anchor: String?, sourceLocation: InstantPageSourceLocation) -> ViewController {
|
||||
return BrowserScreen(context: context, subject: .instantPage(webPage: webPage, anchor: anchor, sourceLocation: sourceLocation))
|
||||
}
|
||||
|
||||
|
@ -1846,12 +1846,12 @@ public final class SharedAccountContextImpl: SharedAccountContext {
|
||||
})
|
||||
}
|
||||
|
||||
public func makeInstantPageController(context: AccountContext, message: Message, sourcePeerType: MediaAutoDownloadPeerType?, navigationController: NavigationController) -> ViewController? {
|
||||
return makeInstantPageControllerImpl(context: context, message: message, sourcePeerType: sourcePeerType, navigationController: navigationController)
|
||||
public func makeInstantPageController(context: AccountContext, message: Message, sourcePeerType: MediaAutoDownloadPeerType?) -> ViewController? {
|
||||
return makeInstantPageControllerImpl(context: context, message: message, sourcePeerType: sourcePeerType)
|
||||
}
|
||||
|
||||
public func makeInstantPageController(context: AccountContext, webPage: TelegramMediaWebpage, anchor: String?, sourceLocation: InstantPageSourceLocation, navigationController: NavigationController) -> ViewController {
|
||||
return makeInstantPageControllerImpl(context: context, webPage: webPage, anchor: anchor, sourceLocation: sourceLocation, navigationController: navigationController)
|
||||
public func makeInstantPageController(context: AccountContext, webPage: TelegramMediaWebpage, anchor: String?, sourceLocation: InstantPageSourceLocation) -> ViewController {
|
||||
return makeInstantPageControllerImpl(context: context, webPage: webPage, anchor: anchor, sourceLocation: sourceLocation)
|
||||
}
|
||||
|
||||
public func openChatWallpaper(context: AccountContext, message: Message, present: @escaping (ViewController, Any?) -> Void) {
|
||||
|
@ -39,8 +39,12 @@ public func isValidUrl(_ url: String, validSchemes: [String: Bool] = ["http": tr
|
||||
|
||||
public func explicitUrl(_ url: String) -> String {
|
||||
var url = url
|
||||
if !url.hasPrefix("http") && !url.hasPrefix("https") && url.range(of: "://") == nil {
|
||||
url = "https://\(url)"
|
||||
if !url.lowercased().hasPrefix("http:") && !url.lowercased().hasPrefix("https:") && !url.lowercased().hasPrefix("tonsite:") && url.range(of: "://") == nil {
|
||||
if let parsedUrl = URL(string: "http://\(url)"), parsedUrl.host?.hasSuffix(".ton") == true {
|
||||
url = "tonsite://\(url)"
|
||||
} else {
|
||||
url = "https://\(url)"
|
||||
}
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user