mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-30 06:47:53 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
80 lines
4.1 KiB
Swift
80 lines
4.1 KiB
Swift
import Foundation
|
|
import SwiftSignalKit
|
|
import TelegramCore
|
|
import AccountContext
|
|
import InstantPageUI
|
|
import InstantPageCache
|
|
import UrlHandling
|
|
import TelegramUIPreferences
|
|
|
|
func faqSearchableItems(context: AccountContext, resolvedUrl: Signal<ResolvedUrl?, NoError>, suggestAccountDeletion: Bool) -> Signal<[SettingsSearchableItem], NoError> {
|
|
let strings = context.sharedContext.currentPresentationData.with { $0 }.strings
|
|
return resolvedUrl
|
|
|> map { resolvedUrl -> [SettingsSearchableItem] in
|
|
var results: [SettingsSearchableItem] = []
|
|
var nextIndex: Int32 = 2
|
|
if let resolvedUrl = resolvedUrl, case let .instantView(webPage, _) = resolvedUrl {
|
|
if case let .Loaded(content) = webPage.content, let instantPage = content.instantPage?._parse() {
|
|
var processingQuestions = false
|
|
var currentSection: String?
|
|
outer: for block in instantPage.blocks {
|
|
if !processingQuestions {
|
|
switch block {
|
|
case .blockQuote:
|
|
if results.isEmpty {
|
|
processingQuestions = true
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
} else {
|
|
switch block {
|
|
case let .paragraph(text):
|
|
if case .bold = text {
|
|
currentSection = text.plainText
|
|
} else if case .concat = text {
|
|
processingQuestions = false
|
|
}
|
|
case let .list(items, false):
|
|
if let currentSection = currentSection {
|
|
for item in items {
|
|
if case let .text(itemText, _) = item, case let .url(text, url, _) = itemText {
|
|
let (_, anchor) = extractAnchor(string: url)
|
|
guard let anchor else {
|
|
continue
|
|
}
|
|
var index = nextIndex
|
|
if suggestAccountDeletion && anchor.contains("delete-my-account") {
|
|
index = 1
|
|
} else {
|
|
nextIndex += 1
|
|
}
|
|
let item = SettingsSearchableItem(
|
|
id: "faq/\(anchor)",
|
|
title: text.plainText,
|
|
alternate: [],
|
|
icon: .faq,
|
|
breadcrumbs: [strings.SettingsSearch_FAQ, currentSection],
|
|
present: { context, _, present in
|
|
let controller = context.sharedContext.makeInstantPageController(context: context, webPage: webPage, anchor: anchor, sourceLocation: InstantPageSourceLocation(userLocation: .other, peerType: .channel))
|
|
present(.push, controller)
|
|
})
|
|
if index == 1 {
|
|
results.insert(item, at: 0)
|
|
} else {
|
|
results.append(item)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return results
|
|
}
|
|
}
|