diff --git a/Swiftgram/SGRecentSessionApiId/BUILD b/Swiftgram/SGRecentSessionApiId/BUILD new file mode 100644 index 0000000000..3075486616 --- /dev/null +++ b/Swiftgram/SGRecentSessionApiId/BUILD @@ -0,0 +1,9 @@ +filegroup( + name = "SGRecentSessionApiId", + srcs = glob([ + "Sources/**/*.swift", + ]), + visibility = [ + "//visibility:public", + ], +) diff --git a/Swiftgram/SGRecentSessionApiId/Sources/SGRecentSessionApiId.swift b/Swiftgram/SGRecentSessionApiId/Sources/SGRecentSessionApiId.swift new file mode 100644 index 0000000000..05bbd09e78 --- /dev/null +++ b/Swiftgram/SGRecentSessionApiId/Sources/SGRecentSessionApiId.swift @@ -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) + } +} diff --git a/Swiftgram/SGRecentSessionApiId/Sources/SGRecentSessionApiIdItem.swift b/Swiftgram/SGRecentSessionApiId/Sources/SGRecentSessionApiIdItem.swift new file mode 100644 index 0000000000..11e8688e5d --- /dev/null +++ b/Swiftgram/SGRecentSessionApiId/Sources/SGRecentSessionApiIdItem.swift @@ -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 { + 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 + ) + )) +} diff --git a/submodules/SettingsUI/BUILD b/submodules/SettingsUI/BUILD index 5228441761..2613733b42 100644 --- a/submodules/SettingsUI/BUILD +++ b/submodules/SettingsUI/BUILD @@ -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 = [ diff --git a/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift b/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift index 6c06412b3f..54522bd15f 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/RecentSessionScreen.swift @@ -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(