mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Autremove fixes
Failable postbox intializers for use in extensions
This commit is contained in:
parent
af2e1cf5d4
commit
bc5d79e8de
@ -105,7 +105,7 @@ class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchForMessag
|
||||
let appVersion = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "unknown"
|
||||
|
||||
initializeAccountManagement()
|
||||
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata")
|
||||
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata", isTemporary: true)
|
||||
self.accountManager = accountManager
|
||||
|
||||
let deviceSpecificEncryptionParameters = BuildConfig.deviceSpecificEncryptionParameters(rootPath, baseAppBundleId: baseAppBundleId)
|
||||
@ -820,6 +820,9 @@ class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchForMessag
|
||||
|
||||
return INObjectSection<Friend>(title: accountTitle, items: items)
|
||||
})
|
||||
|> `catch` { _ -> Signal<INObjectSection<Friend>, NoError> in
|
||||
return .single(INObjectSection<Friend>(title: nil, items: []))
|
||||
}
|
||||
|> castError(Error.self))
|
||||
}
|
||||
|
||||
@ -895,7 +898,7 @@ class AvatarsIntentHandler: NSObject, SelectAvatarFriendsIntentHandling {
|
||||
let appVersion = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? "unknown"
|
||||
|
||||
initializeAccountManagement()
|
||||
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata")
|
||||
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata", isTemporary: true)
|
||||
self.accountManager = accountManager
|
||||
|
||||
let deviceSpecificEncryptionParameters = BuildConfig.deviceSpecificEncryptionParameters(rootPath, baseAppBundleId: baseAppBundleId)
|
||||
@ -1043,6 +1046,9 @@ class AvatarsIntentHandler: NSObject, SelectAvatarFriendsIntentHandling {
|
||||
|
||||
return INObjectSection<Friend>(title: accountTitle, items: items)
|
||||
})
|
||||
|> `catch` { _ -> Signal<INObjectSection<Friend>, NoError> in
|
||||
return .single(INObjectSection<Friend>(title: nil, items: []))
|
||||
}
|
||||
|> castError(Error.self))
|
||||
}
|
||||
|
||||
@ -1103,6 +1109,9 @@ class AvatarsIntentHandler: NSObject, SelectAvatarFriendsIntentHandling {
|
||||
|
||||
return items
|
||||
})
|
||||
|> `catch` { _ -> Signal<[Friend], NoError> in
|
||||
return .single([])
|
||||
}
|
||||
|> castError(Error.self))
|
||||
}
|
||||
|
||||
|
@ -112,13 +112,6 @@ struct Provider: IntentTimelineProvider {
|
||||
|
||||
let rootPath = rootPathForBasePath(appGroupUrl.path)
|
||||
|
||||
let dataPath = rootPath + "/widget-data"
|
||||
|
||||
guard let data = try? Data(contentsOf: URL(fileURLWithPath: dataPath)), let widgetData = try? JSONDecoder().decode(WidgetData.self, from: data), case let .peers(widgetPeers) = widgetData.content else {
|
||||
completion(Timeline(entries: [SimpleEntry(date: entryDate, contents: .recent)], policy: .atEnd))
|
||||
return
|
||||
}
|
||||
|
||||
TempBox.initializeShared(basePath: rootPath, processType: "widget", launchSpecificId: arc4random64())
|
||||
|
||||
let logsPath = rootPath + "/widget-logs"
|
||||
@ -213,7 +206,10 @@ struct Provider: IntentTimelineProvider {
|
||||
}
|
||||
|
||||
return result
|
||||
}))
|
||||
})
|
||||
|> `catch` { _ -> Signal<[ParsedPeer], NoError> in
|
||||
return .single([])
|
||||
})
|
||||
}
|
||||
|
||||
let _ = combineLatest(friendsByAccount).start(next: { allPeers in
|
||||
@ -269,13 +265,6 @@ struct AvatarsProvider: IntentTimelineProvider {
|
||||
|
||||
let rootPath = rootPathForBasePath(appGroupUrl.path)
|
||||
|
||||
let dataPath = rootPath + "/widget-data"
|
||||
|
||||
guard let data = try? Data(contentsOf: URL(fileURLWithPath: dataPath)), let widgetData = try? JSONDecoder().decode(WidgetData.self, from: data), case let .peers(widgetPeers) = widgetData.content else {
|
||||
completion(Timeline(entries: [SimpleEntry(date: entryDate, contents: .recent)], policy: .atEnd))
|
||||
return
|
||||
}
|
||||
|
||||
TempBox.initializeShared(basePath: rootPath, processType: "widget", launchSpecificId: arc4random64())
|
||||
|
||||
let logsPath = rootPath + "/widget-logs"
|
||||
@ -370,7 +359,10 @@ struct AvatarsProvider: IntentTimelineProvider {
|
||||
}
|
||||
|
||||
return result
|
||||
}))
|
||||
})
|
||||
|> `catch` { _ -> Signal<[ParsedPeer], NoError> in
|
||||
return .single([])
|
||||
})
|
||||
}
|
||||
|
||||
let _ = combineLatest(friendsByAccount).start(next: { allPeers in
|
||||
@ -1006,39 +998,7 @@ private let presentationData: WidgetPresentationData = {
|
||||
func getWidgetData(contents: SimpleEntry.Contents) -> PeersWidgetData {
|
||||
switch contents {
|
||||
case .recent:
|
||||
let appBundleIdentifier = Bundle.main.bundleIdentifier!
|
||||
guard let lastDotRange = appBundleIdentifier.range(of: ".", options: [.backwards]) else {
|
||||
return .empty
|
||||
}
|
||||
let baseAppBundleId = String(appBundleIdentifier[..<lastDotRange.lowerBound])
|
||||
|
||||
let appGroupName = "group.\(baseAppBundleId)"
|
||||
let maybeAppGroupUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupName)
|
||||
|
||||
guard let appGroupUrl = maybeAppGroupUrl else {
|
||||
return .empty
|
||||
}
|
||||
|
||||
let rootPath = rootPathForBasePath(appGroupUrl.path)
|
||||
|
||||
/*if let data = try? Data(contentsOf: URL(fileURLWithPath: appLockStatePath(rootPath: rootPath))), let state = try? JSONDecoder().decode(LockState.self, from: data) {
|
||||
if state.isManuallyLocked || state.autolockTimeout != nil {
|
||||
return .empty
|
||||
}
|
||||
}*/
|
||||
|
||||
let dataPath = rootPath + "/widget-data"
|
||||
|
||||
if let data = try? Data(contentsOf: URL(fileURLWithPath: dataPath)), let widgetData = try? JSONDecoder().decode(WidgetData.self, from: data) {
|
||||
switch widgetData.content {
|
||||
case let .peers(peers):
|
||||
return .peers(ParsedPeers(accountId: widgetData.accountId, peers: peers))
|
||||
case .empty:
|
||||
return .empty
|
||||
}
|
||||
} else {
|
||||
return .empty
|
||||
}
|
||||
return .empty
|
||||
case let .peers(peers):
|
||||
return .peers(peers)
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ final class AccountManagerImpl {
|
||||
private var noticeEntryViews = Bag<(MutableNoticeEntryView, ValuePipe<NoticeEntryView>)>()
|
||||
private var accessChallengeDataViews = Bag<(MutableAccessChallengeDataView, ValuePipe<AccessChallengeDataView>)>()
|
||||
|
||||
fileprivate init(queue: Queue, basePath: String, temporarySessionId: Int64) {
|
||||
fileprivate init?(queue: Queue, basePath: String, isTemporary: Bool, temporarySessionId: Int64) {
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
self.queue = queue
|
||||
@ -61,8 +61,14 @@ final class AccountManagerImpl {
|
||||
self.atomicStatePath = "\(basePath)/atomic-state"
|
||||
self.temporarySessionId = temporarySessionId
|
||||
let _ = try? FileManager.default.createDirectory(atPath: basePath, withIntermediateDirectories: true, attributes: nil)
|
||||
self.guardValueBox = SqliteValueBox(basePath: basePath + "/guard_db", queue: queue, encryptionParameters: nil, upgradeProgress: { _ in })
|
||||
self.valueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, encryptionParameters: nil, upgradeProgress: { _ in })
|
||||
guard let guardValueBox = SqliteValueBox(basePath: basePath + "/guard_db", queue: queue, isTemporary: isTemporary, encryptionParameters: nil, upgradeProgress: { _ in }) else {
|
||||
return nil
|
||||
}
|
||||
self.guardValueBox = guardValueBox
|
||||
guard let valueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, isTemporary: isTemporary, encryptionParameters: nil, upgradeProgress: { _ in }) else {
|
||||
return nil
|
||||
}
|
||||
self.valueBox = valueBox
|
||||
|
||||
self.legacyMetadataTable = AccountManagerMetadataTable(valueBox: self.valueBox, table: AccountManagerMetadataTable.tableSpec(0))
|
||||
self.legacyRecordTable = AccountManagerRecordTable(valueBox: self.valueBox, table: AccountManagerRecordTable.tableSpec(1))
|
||||
@ -451,7 +457,7 @@ public final class AccountManager {
|
||||
private let impl: QueueLocalObject<AccountManagerImpl>
|
||||
public let temporarySessionId: Int64
|
||||
|
||||
public init(basePath: String) {
|
||||
public init(basePath: String, isTemporary: Bool) {
|
||||
self.queue = sharedQueue
|
||||
self.basePath = basePath
|
||||
var temporarySessionId: Int64 = 0
|
||||
@ -459,7 +465,11 @@ public final class AccountManager {
|
||||
self.temporarySessionId = temporarySessionId
|
||||
let queue = self.queue
|
||||
self.impl = QueueLocalObject(queue: queue, generate: {
|
||||
return AccountManagerImpl(queue: queue, basePath: basePath, temporarySessionId: temporarySessionId)
|
||||
if let value = AccountManagerImpl(queue: queue, basePath: basePath, isTemporary: isTemporary, temporarySessionId: temporarySessionId) {
|
||||
return value
|
||||
} else {
|
||||
preconditionFailure()
|
||||
}
|
||||
})
|
||||
self.mediaBox = MediaBox(basePath: basePath + "/media")
|
||||
}
|
||||
|
@ -1096,6 +1096,7 @@ public final class Transaction {
|
||||
public enum PostboxResult {
|
||||
case upgrading(Float)
|
||||
case postbox(Postbox)
|
||||
case error
|
||||
}
|
||||
|
||||
func debugSaveState(basePath:String, name: String) {
|
||||
@ -1137,9 +1138,12 @@ public func openPostbox(basePath: String, seedConfiguration: SeedConfiguration,
|
||||
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
var valueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, encryptionParameters: encryptionParameters, upgradeProgress: { progress in
|
||||
guard var valueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, isTemporary: isTemporary, encryptionParameters: encryptionParameters, upgradeProgress: { progress in
|
||||
subscriber.putNext(.upgrading(progress))
|
||||
})
|
||||
}) else {
|
||||
subscriber.putNext(.error)
|
||||
return
|
||||
}
|
||||
|
||||
loop: while true {
|
||||
let metadataTable = MetadataTable(valueBox: valueBox, table: MetadataTable.tableSpec(0))
|
||||
@ -1150,16 +1154,20 @@ public func openPostbox(basePath: String, seedConfiguration: SeedConfiguration,
|
||||
if let userVersion = userVersion {
|
||||
if userVersion != currentUserVersion {
|
||||
if isTemporary {
|
||||
subscriber.putNext(.upgrading(0.0))
|
||||
subscriber.putNext(.error)
|
||||
return
|
||||
} else {
|
||||
if userVersion > currentUserVersion {
|
||||
postboxLog("Version \(userVersion) is newer than supported")
|
||||
assertionFailure("Version \(userVersion) is newer than supported")
|
||||
valueBox.drop()
|
||||
valueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, encryptionParameters: encryptionParameters, upgradeProgress: { progress in
|
||||
guard let updatedValueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, isTemporary: isTemporary, encryptionParameters: encryptionParameters, upgradeProgress: { progress in
|
||||
subscriber.putNext(.upgrading(progress))
|
||||
})
|
||||
}) else {
|
||||
subscriber.putNext(.error)
|
||||
return
|
||||
}
|
||||
valueBox = updatedValueBox
|
||||
} else {
|
||||
if let operation = registeredUpgrades()[userVersion] {
|
||||
switch operation {
|
||||
@ -1177,9 +1185,13 @@ public func openPostbox(basePath: String, seedConfiguration: SeedConfiguration,
|
||||
valueBox.internalClose()
|
||||
let _ = try? FileManager.default.removeItem(atPath: basePath + "/db")
|
||||
let _ = try? FileManager.default.moveItem(atPath: updatedPath, toPath: basePath + "/db")
|
||||
valueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, encryptionParameters: encryptionParameters, upgradeProgress: { progress in
|
||||
guard let updatedValueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, isTemporary: isTemporary, encryptionParameters: encryptionParameters, upgradeProgress: { progress in
|
||||
subscriber.putNext(.upgrading(progress))
|
||||
})
|
||||
}) else {
|
||||
subscriber.putNext(.error)
|
||||
return
|
||||
}
|
||||
valueBox = updatedValueBox
|
||||
}
|
||||
}
|
||||
continue loop
|
||||
@ -1187,9 +1199,13 @@ public func openPostbox(basePath: String, seedConfiguration: SeedConfiguration,
|
||||
assertionFailure("Couldn't find any upgrade for \(userVersion)")
|
||||
postboxLog("Couldn't find any upgrade for \(userVersion)")
|
||||
valueBox.drop()
|
||||
valueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, encryptionParameters: encryptionParameters, upgradeProgress: { progress in
|
||||
guard let updatedValueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, isTemporary: isTemporary, encryptionParameters: encryptionParameters, upgradeProgress: { progress in
|
||||
subscriber.putNext(.upgrading(progress))
|
||||
})
|
||||
}) else {
|
||||
subscriber.putNext(.error)
|
||||
return
|
||||
}
|
||||
valueBox = updatedValueBox
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +155,7 @@ public final class SqliteValueBox: ValueBox {
|
||||
private let lock = NSRecursiveLock()
|
||||
|
||||
fileprivate let basePath: String
|
||||
private let isTemporary: Bool
|
||||
private let inMemory: Bool
|
||||
private let encryptionParameters: ValueBoxEncryptionParameters?
|
||||
private let databasePath: String
|
||||
@ -193,13 +194,18 @@ public final class SqliteValueBox: ValueBox {
|
||||
|
||||
private let queue: Queue
|
||||
|
||||
public init(basePath: String, queue: Queue, encryptionParameters: ValueBoxEncryptionParameters?, upgradeProgress: (Float) -> Void, inMemory: Bool = false) {
|
||||
public init?(basePath: String, queue: Queue, isTemporary: Bool, encryptionParameters: ValueBoxEncryptionParameters?, upgradeProgress: (Float) -> Void, inMemory: Bool = false) {
|
||||
self.basePath = basePath
|
||||
self.isTemporary = isTemporary
|
||||
self.inMemory = inMemory
|
||||
self.encryptionParameters = encryptionParameters
|
||||
self.databasePath = basePath + "/db_sqlite"
|
||||
self.queue = queue
|
||||
self.database = self.openDatabase(encryptionParameters: encryptionParameters, upgradeProgress: upgradeProgress)
|
||||
if let database = self.openDatabase(encryptionParameters: encryptionParameters, isTemporary: isTemporary, upgradeProgress: upgradeProgress) {
|
||||
self.database = database
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
@ -212,7 +218,7 @@ public final class SqliteValueBox: ValueBox {
|
||||
self.database = nil
|
||||
}
|
||||
|
||||
private func openDatabase(encryptionParameters: ValueBoxEncryptionParameters?, upgradeProgress: (Float) -> Void) -> Database {
|
||||
private func openDatabase(encryptionParameters: ValueBoxEncryptionParameters?, isTemporary: Bool, upgradeProgress: (Float) -> Void) -> Database? {
|
||||
precondition(self.queue.isCurrent())
|
||||
|
||||
checkpoints.set(nil)
|
||||
@ -297,6 +303,9 @@ public final class SqliteValueBox: ValueBox {
|
||||
assert(resultCode)
|
||||
|
||||
if self.isEncrypted(database) {
|
||||
if isTemporary {
|
||||
return nil
|
||||
}
|
||||
postboxLog("Encryption key is invalid")
|
||||
|
||||
for fileName in dabaseFileNames {
|
||||
@ -2060,7 +2069,7 @@ public final class SqliteValueBox: ValueBox {
|
||||
let _ = try? FileManager.default.removeItem(atPath: self.basePath + "/\(fileName)")
|
||||
}
|
||||
|
||||
self.database = self.openDatabase(encryptionParameters: self.encryptionParameters, upgradeProgress: { _ in })
|
||||
self.database = self.openDatabase(encryptionParameters: self.encryptionParameters, isTemporary: self.isTemporary, upgradeProgress: { _ in })
|
||||
|
||||
tables.removeAll()
|
||||
}
|
||||
|
@ -69,19 +69,26 @@ public let telegramPostboxSeedConfiguration: SeedConfiguration = {
|
||||
}, additionalChatListIndexNamespace: Namespaces.Message.Cloud, messageNamespacesRequiringGroupStatsValidation: [Namespaces.Message.Cloud], defaultMessageNamespaceReadStates: [Namespaces.Message.Local: .idBased(maxIncomingReadId: 0, maxOutgoingReadId: 0, maxKnownId: 0, count: 0, markedUnread: false)], chatMessagesNamespaces: Set([Namespaces.Message.Cloud, Namespaces.Message.Local, Namespaces.Message.SecretIncoming]), globalNotificationSettingsPreferencesKey: PreferencesKeys.globalNotifications, defaultGlobalNotificationSettings: GlobalNotificationSettings.defaultSettings)
|
||||
}()
|
||||
|
||||
public func accountTransaction<T>(rootPath: String, id: AccountRecordId, encryptionParameters: ValueBoxEncryptionParameters, transaction: @escaping (Postbox, Transaction) -> T) -> Signal<T, NoError> {
|
||||
public enum AccountTransactionError {
|
||||
case couldNotOpen
|
||||
}
|
||||
|
||||
public func accountTransaction<T>(rootPath: String, id: AccountRecordId, encryptionParameters: ValueBoxEncryptionParameters, transaction: @escaping (Postbox, Transaction) -> T) -> Signal<T, AccountTransactionError> {
|
||||
let path = "\(rootPath)/\(accountRecordIdPathName(id))"
|
||||
let postbox = openPostbox(basePath: path + "/postbox", seedConfiguration: telegramPostboxSeedConfiguration, encryptionParameters: encryptionParameters, timestampForAbsoluteTimeBasedOperations: Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970), isTemporary: true)
|
||||
return postbox
|
||||
|> mapToSignal { value -> Signal<T, NoError> in
|
||||
|> castError(AccountTransactionError.self)
|
||||
|> mapToSignal { value -> Signal<T, AccountTransactionError> in
|
||||
switch value {
|
||||
case let .postbox(postbox):
|
||||
return postbox.transaction { t in
|
||||
transaction(postbox, t)
|
||||
}
|
||||
default:
|
||||
return .complete()
|
||||
case let .postbox(postbox):
|
||||
return postbox.transaction { t in
|
||||
transaction(postbox, t)
|
||||
}
|
||||
|> castError(AccountTransactionError.self)
|
||||
case .error:
|
||||
return .fail(.couldNotOpen)
|
||||
default:
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,6 +176,8 @@ public func accountPreferenceEntries(rootPath: String, id: AccountRecordId, keys
|
||||
}
|
||||
return .result(path, result)
|
||||
}
|
||||
case .error:
|
||||
return .single(.progress(0.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -197,6 +199,8 @@ public func accountNoticeEntries(rootPath: String, id: AccountRecordId, encrypti
|
||||
return postbox.transaction { transaction -> AccountNoticeEntriesResult in
|
||||
return .result(path, transaction.getAllNoticeEntries())
|
||||
}
|
||||
case .error:
|
||||
return .single(.progress(0.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -218,6 +222,8 @@ public func accountLegacyAccessChallengeData(rootPath: String, id: AccountRecord
|
||||
return postbox.transaction { transaction -> LegacyAccessChallengeDataResult in
|
||||
return .result(transaction.legacyGetAccessChallengeData())
|
||||
}
|
||||
case .error:
|
||||
return .single(.progress(0.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -232,6 +238,8 @@ public func accountWithId(accountManager: AccountManager, networkArguments: Netw
|
||||
switch result {
|
||||
case let .upgrading(progress):
|
||||
return .single(.upgrading(progress))
|
||||
case .error:
|
||||
return .single(.upgrading(0.0))
|
||||
case let .postbox(postbox):
|
||||
return accountManager.transaction { transaction -> (LocalizationSettings?, ProxySettings?) in
|
||||
return (transaction.getSharedData(SharedDataKeys.localizationSettings) as? LocalizationSettings, transaction.getSharedData(SharedDataKeys.proxySettings) as? ProxySettings)
|
||||
|
@ -219,6 +219,8 @@ public func temporaryAccount(manager: AccountManager, rootPath: String, encrypti
|
||||
switch result {
|
||||
case .upgrading:
|
||||
return .complete()
|
||||
case .error:
|
||||
return .complete()
|
||||
case let .postbox(postbox):
|
||||
return .single(TemporaryAccount(id: id, basePath: path, postbox: postbox))
|
||||
}
|
||||
|
@ -665,7 +665,7 @@ final class SharedApplicationContext {
|
||||
})
|
||||
|
||||
let accountManagerSignal = Signal<AccountManager, NoError> { subscriber in
|
||||
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata")
|
||||
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata", isTemporary: false)
|
||||
return (upgradedAccounts(accountManager: accountManager, rootPath: rootPath, encryptionParameters: encryptionParameters)
|
||||
|> deliverOnMainQueue).start(next: { progress in
|
||||
if self.dataImportSplash == nil {
|
||||
|
@ -4991,6 +4991,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
return interfaceState.withUpdatedEffectiveInputState(updatedState)
|
||||
}.updatedInputMode({ _ in updatedMode })
|
||||
})
|
||||
|
||||
if !strongSelf.presentationInterfaceState.interfaceState.effectiveInputState.inputText.string.isEmpty {
|
||||
strongSelf.silentPostTooltipController?.dismiss()
|
||||
}
|
||||
}
|
||||
}, updateInputModeAndDismissedButtonKeyboardMessageId: { [weak self] f in
|
||||
if let strongSelf = self {
|
||||
@ -5619,6 +5623,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
let intervalText = timeIntervalString(strings: strongSelf.presentationData.strings, value: currentAutoremoveTimeout)
|
||||
let text: String = "Messages in this chat are automatically\ndeleted \(intervalText) after they have been sent."
|
||||
|
||||
strongSelf.mediaRecordingModeTooltipController?.dismiss()
|
||||
|
||||
if let tooltipController = strongSelf.silentPostTooltipController {
|
||||
tooltipController.updateContent(.text(text), animated: true, extendTimer: true)
|
||||
} else {
|
||||
@ -11466,6 +11472,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
text = self.presentationData.strings.Conversation_HoldForVideo
|
||||
}
|
||||
|
||||
self.silentPostTooltipController?.dismiss()
|
||||
|
||||
if let tooltipController = self.mediaRecordingModeTooltipController {
|
||||
tooltipController.updateContent(.text(text), animated: true, extendTimer: true)
|
||||
} else if let rect = rect {
|
||||
@ -12023,7 +12031,6 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
strongSelf.updateChatPresentationInterfaceState(animated: false, interactive: false, { $0.updatedInterfaceState({ $0.withoutSelectionState() }) })
|
||||
|
||||
var isOn: Bool = true
|
||||
var title: String?
|
||||
var text: String?
|
||||
if let myValue = value.value {
|
||||
text = strongSelf.presentationData.strings.Conversation_AutoremoveChanged("\(timeIntervalString(strings: strongSelf.presentationData.strings, value: myValue))").0
|
||||
@ -12032,7 +12039,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
text = "Auto-Delete is now off."
|
||||
}
|
||||
if let text = text {
|
||||
strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .autoDelete(isOn: isOn, title: title, text: text), elevatedLayout: false, action: { _ in return false }), in: .current)
|
||||
strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .autoDelete(isOn: isOn, title: nil, text: text), elevatedLayout: false, action: { _ in return false }), in: .current)
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -12112,3 +12119,29 @@ private final class ContextControllerContentSourceImpl: ContextControllerContent
|
||||
func animatedIn() {
|
||||
}
|
||||
}
|
||||
|
||||
extension Peer {
|
||||
func canSetupAutoremoveTimeout(accountPeerId: PeerId) -> Bool {
|
||||
if let _ = self as? TelegramSecretChat {
|
||||
return false
|
||||
} else if let group = self as? TelegramGroup {
|
||||
if case .creator = group.role {
|
||||
return true
|
||||
} else if case let .admin(rights, _) = group.role {
|
||||
if rights.flags.contains(.canDeleteMessages) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
} else if let user = self as? TelegramUser {
|
||||
if user.id != accountPeerId && user.botInfo == nil {
|
||||
return true
|
||||
}
|
||||
} else if let channel = self as? TelegramChannel {
|
||||
if channel.hasPermission(.deleteAllMessages) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import StickerPackPreviewUI
|
||||
import JoinLinkPreviewUI
|
||||
import LanguageLinkPreviewUI
|
||||
import PeerInfoUI
|
||||
import UndoUI
|
||||
|
||||
private final class ChatRecentActionsListOpaqueState {
|
||||
let entries: [ChatRecentActionsEntry]
|
||||
@ -150,6 +151,10 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode {
|
||||
strongSelf.presentController(StickerPackScreen(context: strongSelf.context, mainStickerPack: new, stickerPacks: [new], parentNavigationController: strongSelf.getNavigationController()), nil)
|
||||
return true
|
||||
}
|
||||
case .changeHistoryTTL:
|
||||
if strongSelf.peer.canSetupAutoremoveTimeout(accountPeerId: strongSelf.context.account.peerId) {
|
||||
strongSelf.presentAutoremoveSetup()
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
@ -866,4 +871,29 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode {
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
private func presentAutoremoveSetup() {
|
||||
let peer = self.peer
|
||||
|
||||
let controller = peerAutoremoveSetupScreen(context: self.context, peerId: peer.id, completion: { [weak self] updatedValue in
|
||||
if case let .updated(value) = updatedValue {
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
|
||||
var isOn: Bool = true
|
||||
var text: String?
|
||||
if let myValue = value.value {
|
||||
text = strongSelf.presentationData.strings.Conversation_AutoremoveChanged("\(timeIntervalString(strings: strongSelf.presentationData.strings, value: myValue))").0
|
||||
} else {
|
||||
isOn = false
|
||||
text = "Auto-Delete is now off."
|
||||
}
|
||||
if let text = text {
|
||||
strongSelf.presentController(UndoOverlayController(presentationData: strongSelf.presentationData, content: .autoDelete(isOn: isOn, title: nil, text: text), elevatedLayout: false, action: { _ in return false }), nil)
|
||||
}
|
||||
}
|
||||
})
|
||||
self.pushController(controller)
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ public final class NotificationViewControllerImpl {
|
||||
|
||||
if sharedAccountContext == nil {
|
||||
initializeAccountManagement()
|
||||
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata")
|
||||
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata", isTemporary: true)
|
||||
|
||||
var initialPresentationDataAndSettings: InitialPresentationDataAndSettings?
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
|
@ -202,7 +202,7 @@ public class ShareRootControllerImpl {
|
||||
|
||||
let internalContext: InternalContext
|
||||
|
||||
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata")
|
||||
let accountManager = AccountManager(basePath: rootPath + "/accounts-metadata", isTemporary: true)
|
||||
|
||||
if let globalInternalContext = globalInternalContext {
|
||||
internalContext = globalInternalContext
|
||||
|
@ -298,6 +298,9 @@ public func upgradedAccounts(accountManager: AccountManager, rootPath: String, e
|
||||
})
|
||||
})
|
||||
|> ignoreValues
|
||||
|> `catch` { _ -> Signal<Never, NoError> in
|
||||
return .complete()
|
||||
}
|
||||
importSignal = importSignal |> then(importInfoAccounttSignal)
|
||||
}
|
||||
return importSignal
|
||||
|
Loading…
x
Reference in New Issue
Block a user