api_id refactor

This commit is contained in:
Kylmakalle
2026-02-09 22:17:57 +02:00
parent 09fd6c7be4
commit 55c5def428
5 changed files with 116 additions and 11 deletions

View File

@@ -0,0 +1,9 @@
filegroup(
name = "SGRecentSessionApiId",
srcs = glob([
"Sources/**/*.swift",
]),
visibility = [
"//visibility:public",
],
)

View File

@@ -0,0 +1,16 @@
import Foundation
import BuildConfig
import TelegramCore
public enum SGRecentSessionApiId {
public static func string(for session: RecentAccountSession) -> String? {
guard !session.isCurrent, let baseAppBundleId = Bundle.main.bundleIdentifier else {
return nil
}
let buildConfig = BuildConfig(baseAppBundleId: baseAppBundleId)
guard buildConfig.apiId != session.apiId else {
return nil
}
return String(session.apiId)
}
}

View File

@@ -0,0 +1,70 @@
import UIKit
import Display
import ComponentFlow
import TelegramPresentationData
import MultilineTextComponent
import ListActionItemComponent
import UndoUI
func sgRecentSessionApiIdItem(
apiIdString: String,
theme: PresentationTheme,
presentationData: PresentationData,
strings: PresentationStrings,
controller: RecentSessionScreen?
) -> AnyComponentWithIdentity<Empty> {
let sgApiIdTextAttribute = NSAttributedString.Key(rawValue: "SGRecentSessionApiIdAttribute")
let sgApiIdText = NSMutableAttributedString(
string: apiIdString,
font: Font.regular(presentationData.listsFontSize.itemListBaseFontSize),
textColor: theme.list.itemSecondaryTextColor
)
sgApiIdText.addAttribute(sgApiIdTextAttribute, value: true, range: NSRange(location: 0, length: sgApiIdText.length))
return AnyComponentWithIdentity(id: "api_id", component: AnyComponent(
ListActionItemComponent(
theme: theme,
style: .glass,
title: AnyComponent(MultilineTextComponent(
text: .plain(NSAttributedString(
string: "api_id",
font: Font.regular(17.0),
textColor: theme.list.itemPrimaryTextColor
)),
maximumNumberOfLines: 1
)),
accessory: .custom(ListActionItemComponent.CustomAccessory(
component: AnyComponentWithIdentity(
id: "info",
component: AnyComponent(MultilineTextComponent(
text: .plain(sgApiIdText),
maximumNumberOfLines: 1,
highlightColor: theme.list.itemAccentColor.withMultipliedAlpha(0.15),
highlightAction: { attributes in
if let _ = attributes[sgApiIdTextAttribute] {
return sgApiIdTextAttribute
}
return nil
},
longTapAction: { [weak controller] attributes, _ in
guard let _ = attributes[sgApiIdTextAttribute] else {
return
}
UIPasteboard.general.string = apiIdString
controller?.present(UndoOverlayController(
presentationData: presentationData,
content: .copy(text: strings.Conversation_TextCopied),
elevatedLayout: false,
animateInAsReplacement: false,
action: { _ in return false }
), in: .current)
}
))
),
insets: UIEdgeInsets(top: 0.0, left: 8.0, bottom: 0.0, right: 14.0),
isInteractive: true
)),
action: nil
)
))
}

View File

@@ -6,10 +6,14 @@ sgdeps = [
"//Swiftgram/SGStrings:SGStrings"
]
sgsrc = [
"//Swiftgram/SGRecentSessionApiId:SGRecentSessionApiId",
]
swift_library(
name = "SettingsUI",
module_name = "SettingsUI",
srcs = glob([
srcs = sgsrc + glob([
"Sources/**/*.swift",
]),
copts = [

View File

@@ -1,4 +1,3 @@
import BuildConfig
import Foundation
import UIKit
import Display
@@ -124,8 +123,6 @@ private final class RecentSessionSheetContent: CombinedComponent {
let clientSection = Child(ListSectionComponent.self)
let optionsSection = Child(ListSectionComponent.self)
let button = Child(ButtonComponent.self)
let baseAppBundleId = Bundle.main.bundleIdentifier!
let buildConfig = BuildConfig(baseAppBundleId: baseAppBundleId)
return { context in
let environment = context.environment[ViewControllerComponentContainer.Environment.self].value
@@ -263,14 +260,8 @@ private final class RecentSessionSheetContent: CombinedComponent {
}
var appVersion = session.appVersion
appVersion = appVersion.replacingOccurrences(of: "APPSTORE", with: "").replacingOccurrences(of: "BETA", with: "Beta").trimmingTrailingSpaces()
// MARK: Swiftgram
var apiId: String = ""
if buildConfig.apiId != session.apiId {
apiId = "\napi_id: \(session.apiId)"
}
//
applicationTitle = strings.AuthSessions_View_Application
applicationString = "\(session.appName) \(appVersion)\(apiId)" // MARK: Swiftgram
applicationString = "\(session.appName) \(appVersion)"
ipString = session.ip // MARK: Swiftgram
locationString = session.country
@@ -297,6 +288,15 @@ private final class RecentSessionSheetContent: CombinedComponent {
buttonString = strings.AuthSessions_View_Logout
}
// MARK: Swiftgram
let sgApiIdString: String?
if case let .session(session) = component.subject {
sgApiIdString = SGRecentSessionApiId.string(for: session)
} else {
sgApiIdString = nil
}
//
let titleFont = Font.bold(24.0)
let title = title.update(
@@ -364,6 +364,12 @@ private final class RecentSessionSheetContent: CombinedComponent {
)
))
)
// MARK: Swiftgram
if let sgApiIdString {
clientSectionItems.append(sgRecentSessionApiIdItem(apiIdString: sgApiIdString, theme: theme, presentationData: presentationData, strings: strings, controller: state.controller))
}
//
if let ipString {
clientSectionItems.append(