mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 01:10:09 +00:00
Improve internal link recognition
This commit is contained in:
parent
7da4e1001f
commit
8fba853061
@ -2,6 +2,14 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
import TelegramCore
|
import TelegramCore
|
||||||
|
|
||||||
|
private let whitelistedHosts: Set<String> = Set([
|
||||||
|
"telegram.org",
|
||||||
|
"t.me",
|
||||||
|
"telegram.me",
|
||||||
|
"telegra.ph",
|
||||||
|
"telesco.pe"
|
||||||
|
])
|
||||||
|
|
||||||
private let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType([.link]).rawValue)
|
private let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType([.link]).rawValue)
|
||||||
private let dataAndPhoneNumberDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType([.link, .phoneNumber]).rawValue)
|
private let dataAndPhoneNumberDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType([.link, .phoneNumber]).rawValue)
|
||||||
private let phoneNumberDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType([.phoneNumber]).rawValue)
|
private let phoneNumberDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType([.phoneNumber]).rawValue)
|
||||||
@ -190,10 +198,14 @@ public func generateTextEntities(_ text: String, enabledTypes: EnabledEntityType
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if url.scheme != "tg" {
|
if url.scheme != "tg" {
|
||||||
guard let host = url.host?.lowercased() else {
|
guard var host = url.host?.lowercased() else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ["telegram.org", "www.telegram.org", "t.me", "www.t.me"].contains(host) {
|
let www = "www."
|
||||||
|
if host.hasPrefix(www) {
|
||||||
|
host.removeFirst(www.count)
|
||||||
|
}
|
||||||
|
if whitelistedHosts.contains(host) {
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,14 +3,21 @@ import Foundation
|
|||||||
private let whitelistedHosts: Set<String> = Set([
|
private let whitelistedHosts: Set<String> = Set([
|
||||||
"t.me",
|
"t.me",
|
||||||
"telegram.me",
|
"telegram.me",
|
||||||
"telegra.ph"
|
"telegra.ph",
|
||||||
|
"telesco.pe"
|
||||||
])
|
])
|
||||||
|
|
||||||
public func isConcealedUrlWhitelisted(_ url: URL) -> Bool {
|
public func isConcealedUrlWhitelisted(_ url: URL) -> Bool {
|
||||||
if let host = url.host, whitelistedHosts.contains(host) {
|
if var host = url.host?.lowercased() {
|
||||||
return true
|
let www = "www."
|
||||||
|
if host.hasPrefix(www) {
|
||||||
|
host.removeFirst(www.count)
|
||||||
|
}
|
||||||
|
if whitelistedHosts.contains(host) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let host = url.host, host == "telegram.org" {
|
if let host = url.host?.lowercased(), host == "telegram.org" {
|
||||||
let whitelistedNativePrefixes: Set<String> = Set([
|
let whitelistedNativePrefixes: Set<String> = Set([
|
||||||
"/blog/",
|
"/blog/",
|
||||||
"/tour/"
|
"/tour/"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user