mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
commit
8496180c89
@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
|
||||
public struct PeerId: Hashable, CustomStringConvertible, Comparable, Codable {
|
||||
public struct Namespace: Comparable, Hashable, Codable {
|
||||
public struct Namespace: Comparable, Hashable, Codable, CustomStringConvertible {
|
||||
public static var max: Namespace {
|
||||
return Namespace(rawValue: 0x7)
|
||||
}
|
||||
@ -24,6 +24,10 @@ public struct PeerId: Hashable, CustomStringConvertible, Comparable, Codable {
|
||||
}
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
return "\(self.rawValue)"
|
||||
}
|
||||
|
||||
fileprivate init(rawValue: UInt32) {
|
||||
precondition((rawValue | 0x7) == 0x7)
|
||||
|
||||
@ -52,11 +56,11 @@ public struct PeerId: Hashable, CustomStringConvertible, Comparable, Codable {
|
||||
return Id(rawValue: 0x000000007fffffff)
|
||||
}
|
||||
|
||||
fileprivate var rawValue: UInt32
|
||||
fileprivate var rawValue: Int32
|
||||
|
||||
var predecessor: Id {
|
||||
if self.rawValue != 0 {
|
||||
return Id(rawValue: UInt64(self.rawValue - 1))
|
||||
return Id(rawValue: self.rawValue - 1)
|
||||
} else {
|
||||
return self
|
||||
}
|
||||
@ -64,24 +68,28 @@ public struct PeerId: Hashable, CustomStringConvertible, Comparable, Codable {
|
||||
|
||||
var successor: Id {
|
||||
if self.rawValue != Id.max.rawValue {
|
||||
return Id(rawValue: UInt64(self.rawValue + 1))
|
||||
return Id(rawValue: self.rawValue + 1)
|
||||
} else {
|
||||
return self
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate init(rawValue: UInt64) {
|
||||
precondition((rawValue | 0x000FFFFFFFFFFFFF) == 0x000FFFFFFFFFFFFF)
|
||||
public var description: String {
|
||||
return "\(self.rawValue)"
|
||||
}
|
||||
|
||||
self.rawValue = UInt32(rawValue)
|
||||
fileprivate init(rawValue: Int32) {
|
||||
//precondition((rawValue | 0x000FFFFFFFFFFFFF) == 0x000FFFFFFFFFFFFF)
|
||||
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
public static func _internalFromInt32Value(_ value: Int32) -> Id {
|
||||
return Id(rawValue: UInt64(UInt32(bitPattern: value)))
|
||||
return Id(rawValue: value)
|
||||
}
|
||||
|
||||
public func _internalGetInt32Value() -> Int32 {
|
||||
return Int32(clamping: self.rawValue)
|
||||
return self.rawValue
|
||||
}
|
||||
|
||||
public static func <(lhs: Id, rhs: Id) -> Bool {
|
||||
@ -137,7 +145,7 @@ public struct PeerId: Hashable, CustomStringConvertible, Comparable, Codable {
|
||||
|
||||
if legacyNamespaceBits == 0x7fffffff && idLowBits == 0 {
|
||||
self.namespace = .max
|
||||
self.id = Id(rawValue: idLowBits)
|
||||
self.id = Id(rawValue: Int32(bitPattern: UInt32(clamping: idLowBits)))
|
||||
} else {
|
||||
let namespaceBits = ((data >> 32) & 0x7)
|
||||
self.namespace = Namespace(rawValue: UInt32(namespaceBits))
|
||||
@ -145,12 +153,12 @@ public struct PeerId: Hashable, CustomStringConvertible, Comparable, Codable {
|
||||
let idHighBits = (data >> (32 + 3)) & 0xffffffff
|
||||
assert(idHighBits == 0)
|
||||
|
||||
self.id = Id(rawValue: idLowBits)
|
||||
self.id = Id(rawValue: Int32(bitPattern: UInt32(clamping: idLowBits)))
|
||||
}
|
||||
}
|
||||
|
||||
public func toInt64() -> Int64 {
|
||||
let idLowBits = self.id.rawValue & 0xffffffff
|
||||
let idLowBits = UInt32(bitPattern: self.id.rawValue)
|
||||
|
||||
let result: Int64
|
||||
if self.namespace == .max && self.id.rawValue == 0 {
|
||||
@ -166,7 +174,8 @@ public struct PeerId: Hashable, CustomStringConvertible, Comparable, Codable {
|
||||
var data: UInt64 = 0
|
||||
data |= UInt64(self.namespace.rawValue) << 32
|
||||
|
||||
let idHighBits = (self.id.rawValue >> 32) & 0x3FFFFFFF
|
||||
let idValue = UInt32(bitPattern: self.id.rawValue)
|
||||
let idHighBits = (idValue >> 32) & 0x3FFFFFFF
|
||||
assert(idHighBits == 0)
|
||||
|
||||
data |= UInt64(idLowBits)
|
||||
|
@ -1412,17 +1412,6 @@ public final class Postbox {
|
||||
self.mediaBox = MediaBox(basePath: self.basePath + "/media")
|
||||
self.valueBox = valueBox
|
||||
|
||||
/*self.pipeNotifier = PipeNotifier(basePath: basePath, notify: { [weak self] in
|
||||
//if let strongSelf = self {
|
||||
/*strongSelf.queue.async {
|
||||
if strongSelf.valueBox != nil {
|
||||
let _ = strongSelf.transaction({ _ -> Void in
|
||||
}).start()
|
||||
}
|
||||
}*/
|
||||
//}
|
||||
})*/
|
||||
|
||||
self.metadataTable = MetadataTable(valueBox: self.valueBox, table: MetadataTable.tableSpec(0))
|
||||
|
||||
self.keychainTable = KeychainTable(valueBox: self.valueBox, table: KeychainTable.tableSpec(1))
|
||||
|
@ -1123,15 +1123,17 @@ public class Account {
|
||||
self.managedOperationsDisposable.add(managedAnimatedEmojiUpdates(postbox: self.postbox, network: self.network).start())
|
||||
}
|
||||
self.managedOperationsDisposable.add(managedGreetingStickers(postbox: self.postbox, network: self.network).start())
|
||||
|
||||
let mediaBox = postbox.mediaBox
|
||||
self.storageSettingsDisposable = accountManager.sharedData(keys: [SharedDataKeys.cacheStorageSettings]).start(next: { [weak mediaBox] sharedData in
|
||||
guard let mediaBox = mediaBox else {
|
||||
return
|
||||
}
|
||||
let settings: CacheStorageSettings = sharedData.entries[SharedDataKeys.cacheStorageSettings] as? CacheStorageSettings ?? CacheStorageSettings.defaultSettings
|
||||
mediaBox.setMaxStoreTimes(general: settings.defaultCacheStorageTimeout, shortLived: 60 * 60, gigabytesLimit: settings.defaultCacheStorageLimitGigabytes)
|
||||
})
|
||||
|
||||
if !supplementary {
|
||||
let mediaBox = postbox.mediaBox
|
||||
self.storageSettingsDisposable = accountManager.sharedData(keys: [SharedDataKeys.cacheStorageSettings]).start(next: { [weak mediaBox] sharedData in
|
||||
guard let mediaBox = mediaBox else {
|
||||
return
|
||||
}
|
||||
let settings: CacheStorageSettings = sharedData.entries[SharedDataKeys.cacheStorageSettings] as? CacheStorageSettings ?? CacheStorageSettings.defaultSettings
|
||||
mediaBox.setMaxStoreTimes(general: settings.defaultCacheStorageTimeout, shortLived: 60 * 60, gigabytesLimit: settings.defaultCacheStorageLimitGigabytes)
|
||||
})
|
||||
}
|
||||
|
||||
let _ = masterNotificationsKey(masterNotificationKeyValue: self.masterNotificationKey, postbox: self.postbox, ignoreDisabled: false).start(next: { key in
|
||||
let encoder = JSONEncoder()
|
||||
|
@ -373,7 +373,8 @@ public func managedCleanupAccounts(networkArguments: NetworkInitializationArgume
|
||||
}
|
||||
for (id, attributes, disposable) in beginList {
|
||||
Logger.shared.log("managedCleanupAccounts", "cleanup \(id), current is \(String(describing: view.currentRecord?.id))")
|
||||
disposable.set(cleanupAccount(networkArguments: networkArguments, accountManager: accountManager, id: id, encryptionParameters: encryptionParameters, attributes: attributes, rootPath: rootPath, auxiliaryMethods: auxiliaryMethods).start())
|
||||
//TODO:localize
|
||||
//disposable.set(cleanupAccount(networkArguments: networkArguments, accountManager: accountManager, id: id, encryptionParameters: encryptionParameters, attributes: attributes, rootPath: rootPath, auxiliaryMethods: auxiliaryMethods).start())
|
||||
}
|
||||
|
||||
var validPaths = Set<String>()
|
||||
|
@ -79,6 +79,8 @@ func managedAutoremoveMessageOperations(network: Network, postbox: Postbox, isRe
|
||||
let signal = Signal<Void, NoError>.complete()
|
||||
|> suspendAwareDelay(delay, queue: Queue.concurrentDefaultQueue())
|
||||
|> then(postbox.transaction { transaction -> Void in
|
||||
Logger.shared.log("Autoremove", "Performing autoremove for \(entry.messageId), isRemove: \(isRemove)")
|
||||
|
||||
if let message = transaction.getMessage(entry.messageId) {
|
||||
if message.id.peerId.namespace == Namespaces.Peer.SecretChat || isRemove {
|
||||
deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [entry.messageId])
|
||||
@ -106,6 +108,8 @@ func managedAutoremoveMessageOperations(network: Network, postbox: Postbox, isRe
|
||||
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, threadId: currentMessage.threadId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: updatedMedia))
|
||||
})
|
||||
}
|
||||
} else {
|
||||
Logger.shared.log("Autoremove", "No message to autoremove for \(entry.messageId)")
|
||||
}
|
||||
})
|
||||
disposable.set(signal.start())
|
||||
|
@ -184,6 +184,7 @@ private func requestActivity(postbox: Postbox, network: Network, accountPeerId:
|
||||
return .complete()
|
||||
}
|
||||
} else if let peer = peer as? TelegramSecretChat, activity == .typingText {
|
||||
let _ = PeerId(peer.id.toInt64())
|
||||
return network.request(Api.functions.messages.setEncryptedTyping(peer: .inputEncryptedChat(chatId: peer.id.id._internalGetInt32Value(), accessHash: peer.accessHash), typing: .boolTrue))
|
||||
|> `catch` { _ -> Signal<Api.Bool, NoError> in
|
||||
return .single(.boolFalse)
|
||||
|
Loading…
x
Reference in New Issue
Block a user