mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-30 03:44:18 +00:00
Merge branch 'master' of https://github.com/peter-iakovlev/TelegramCoreDev into feature/secureid
This commit is contained in:
commit
4b8e908bc0
@ -454,6 +454,8 @@
|
||||
D0AB0B9A1D666520002C78E7 /* ManagedSynchronizePeerReadStates.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AB0B991D666520002C78E7 /* ManagedSynchronizePeerReadStates.swift */; };
|
||||
D0AD02E31FFFA14800C1DCFF /* PeerLiveLocationsContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AD02E21FFFA14800C1DCFF /* PeerLiveLocationsContext.swift */; };
|
||||
D0AD02E41FFFA14800C1DCFF /* PeerLiveLocationsContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AD02E21FFFA14800C1DCFF /* PeerLiveLocationsContext.swift */; };
|
||||
D0ADF911212B00DD00310BBC /* SecureIdConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0ADF910212B00DD00310BBC /* SecureIdConfiguration.swift */; };
|
||||
D0ADF912212B00DD00310BBC /* SecureIdConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0ADF910212B00DD00310BBC /* SecureIdConfiguration.swift */; };
|
||||
D0AF32221FAC95C20097362B /* StandaloneUploadedMedia.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AF32211FAC95C20097362B /* StandaloneUploadedMedia.swift */; };
|
||||
D0AF32231FAC95C20097362B /* StandaloneUploadedMedia.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AF32211FAC95C20097362B /* StandaloneUploadedMedia.swift */; };
|
||||
D0AF32311FACEDEC0097362B /* CoreSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AF32301FACEDEC0097362B /* CoreSettings.swift */; };
|
||||
@ -996,6 +998,7 @@
|
||||
D0AB0B991D666520002C78E7 /* ManagedSynchronizePeerReadStates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedSynchronizePeerReadStates.swift; sourceTree = "<group>"; };
|
||||
D0AC49491D7097A400AA55DA /* SSignalKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SSignalKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D0AD02E21FFFA14800C1DCFF /* PeerLiveLocationsContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PeerLiveLocationsContext.swift; sourceTree = "<group>"; };
|
||||
D0ADF910212B00DD00310BBC /* SecureIdConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureIdConfiguration.swift; sourceTree = "<group>"; };
|
||||
D0AF32211FAC95C20097362B /* StandaloneUploadedMedia.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StandaloneUploadedMedia.swift; sourceTree = "<group>"; };
|
||||
D0AF32301FACEDEC0097362B /* CoreSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreSettings.swift; sourceTree = "<group>"; };
|
||||
D0AF32341FAE8C6B0097362B /* MultipeerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultipeerManager.swift; sourceTree = "<group>"; };
|
||||
@ -1769,6 +1772,7 @@
|
||||
children = (
|
||||
D0CA3F82207391450042D2B6 /* Utils */,
|
||||
D0BE303C2061A29100FBE6D8 /* RequestSecureIdForm.swift */,
|
||||
D0ADF910212B00DD00310BBC /* SecureIdConfiguration.swift */,
|
||||
D0BE304A20627D9800FBE6D8 /* AccessSecureId.swift */,
|
||||
D0BE303920619EE800FBE6D8 /* SecureIdForm.swift */,
|
||||
D093D805206539D000BC3599 /* SaveSecureIdValue.swift */,
|
||||
@ -2172,6 +2176,7 @@
|
||||
D0FA0ABD1E76C908005BB9B7 /* TwoStepVerification.swift in Sources */,
|
||||
D02ABC7E1E3109F000CAE539 /* CloudChatRemoveMessagesOperation.swift in Sources */,
|
||||
D0E412E1206AB24700BEE4A2 /* SecureFileMediaResource.swift in Sources */,
|
||||
D0ADF911212B00DD00310BBC /* SecureIdConfiguration.swift in Sources */,
|
||||
D0448CA51E29215A005A61A7 /* MediaResourceApiUtils.swift in Sources */,
|
||||
D0C26D661FE022DB004ABF18 /* SynchronizeGroupedPeersOperation.swift in Sources */,
|
||||
D03C53771DAFF20F004C17B3 /* MultipartUpload.swift in Sources */,
|
||||
@ -2699,6 +2704,7 @@
|
||||
D0F7B1E41E045C7B007EB8A5 /* InstantPage.swift in Sources */,
|
||||
D03E5E0D1E55E02D0029569A /* LoggedOutAccountAttribute.swift in Sources */,
|
||||
D0B418AD1D7E0597004562A4 /* Serialization.swift in Sources */,
|
||||
D0ADF912212B00DD00310BBC /* SecureIdConfiguration.swift in Sources */,
|
||||
C28725431EF967E700613564 /* NotificationInfoMessageAttribute.swift in Sources */,
|
||||
D054648C2073854A002ECC1E /* SecureIdPersonalDetailsValue.swift in Sources */,
|
||||
D0F8C3A12017AF2700236FC5 /* GlobalTelegramCoreConfiguration.swift in Sources */,
|
||||
|
||||
@ -255,6 +255,7 @@ private var declaredEncodables: Void = {
|
||||
declareEncodable(CachedStickerPack.self, f: { CachedStickerPack(decoder: $0) })
|
||||
declareEncodable(LoggingSettings.self, f: { LoggingSettings(decoder: $0) })
|
||||
declareEncodable(CachedLocalizationInfos.self, f: { CachedLocalizationInfos(decoder: $0) })
|
||||
declareEncodable(CachedSecureIdConfiguration.self, f: { CachedSecureIdConfiguration(decoder: $0) })
|
||||
declareEncodable(SynchronizeGroupedPeersOperation.self, f: { SynchronizeGroupedPeersOperation(decoder: $0) })
|
||||
declareEncodable(ContentPrivacySettings.self, f: { ContentPrivacySettings(decoder: $0) })
|
||||
declareEncodable(TelegramDeviceContactImportInfo.self, f: { TelegramDeviceContactImportInfo(decoder: $0) })
|
||||
@ -281,19 +282,21 @@ public enum AccountResult {
|
||||
case authorized(Account)
|
||||
}
|
||||
|
||||
public func accountWithId(networkArguments: NetworkInitializationArguments, id: AccountRecordId, supplementary: Bool, rootPath: String, testingEnvironment: Bool, auxiliaryMethods: AccountAuxiliaryMethods, shouldKeepAutoConnection: Bool = true) -> Signal<AccountResult, NoError> {
|
||||
let _ = declaredEncodables
|
||||
|
||||
let path = "\(rootPath)/\(accountRecordIdPathName(id))"
|
||||
|
||||
let telegramPostboxSeedConfiguration: SeedConfiguration = {
|
||||
var initializeMessageNamespacesWithHoles: [(PeerId.Namespace, MessageId.Namespace)] = []
|
||||
for peerNamespace in peerIdNamespacesWithInitialCloudMessageHoles {
|
||||
initializeMessageNamespacesWithHoles.append((peerNamespace, Namespaces.Message.Cloud))
|
||||
}
|
||||
|
||||
let seedConfiguration = SeedConfiguration(initializeChatListWithHoles: [ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: 0), namespace: Namespaces.Message.Cloud, id: 1), timestamp: 1))], initializeMessageNamespacesWithHoles: initializeMessageNamespacesWithHoles, existingMessageTags: MessageTags.all, messageTagsWithSummary: MessageTags.unseenPersonalMessage, existingGlobalMessageTags: GlobalMessageTags.all, peerNamespacesRequiringMessageTextIndex: [Namespaces.Peer.SecretChat])
|
||||
return SeedConfiguration(initializeChatListWithHoles: [ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: 0), namespace: Namespaces.Message.Cloud, id: 1), timestamp: 1))], initializeMessageNamespacesWithHoles: initializeMessageNamespacesWithHoles, existingMessageTags: MessageTags.all, messageTagsWithSummary: MessageTags.unseenPersonalMessage, existingGlobalMessageTags: GlobalMessageTags.all, peerNamespacesRequiringMessageTextIndex: [Namespaces.Peer.SecretChat])
|
||||
}()
|
||||
|
||||
public func accountWithId(networkArguments: NetworkInitializationArguments, id: AccountRecordId, supplementary: Bool, rootPath: String, testingEnvironment: Bool, auxiliaryMethods: AccountAuxiliaryMethods, shouldKeepAutoConnection: Bool = true) -> Signal<AccountResult, NoError> {
|
||||
let _ = declaredEncodables
|
||||
|
||||
let postbox = openPostbox(basePath: path + "/postbox", globalMessageIdsNamespace: Namespaces.Message.Cloud, seedConfiguration: seedConfiguration)
|
||||
let path = "\(rootPath)/\(accountRecordIdPathName(id))"
|
||||
|
||||
let postbox = openPostbox(basePath: path + "/postbox", globalMessageIdsNamespace: Namespaces.Message.Cloud, seedConfiguration: telegramPostboxSeedConfiguration)
|
||||
|
||||
return postbox |> mapToSignal { result -> Signal<AccountResult, NoError> in
|
||||
switch result {
|
||||
|
||||
@ -41,6 +41,34 @@ public func performAppGroupUpgrades(appGroupPath: String, rootPath: String) {
|
||||
}
|
||||
}
|
||||
|
||||
public final class TemporaryAccount {
|
||||
public let id: AccountRecordId
|
||||
public let basePath: String
|
||||
public let postbox: Postbox
|
||||
|
||||
init(id: AccountRecordId, basePath: String, postbox: Postbox) {
|
||||
self.id = id
|
||||
self.basePath = basePath
|
||||
self.postbox = postbox
|
||||
}
|
||||
}
|
||||
|
||||
public func temporaryAccount(manager: AccountManager, rootPath: String) -> Signal<TemporaryAccount, NoError> {
|
||||
return manager.allocatedTemporaryAccountId()
|
||||
|> mapToSignal { id -> Signal<TemporaryAccount, NoError> in
|
||||
let path = "\(rootPath)/\(accountRecordIdPathName(id))"
|
||||
return openPostbox(basePath: path + "/postbox", globalMessageIdsNamespace: Namespaces.Message.Cloud, seedConfiguration: telegramPostboxSeedConfiguration)
|
||||
|> mapToSignal { result -> Signal<TemporaryAccount, NoError> in
|
||||
switch result {
|
||||
case .upgrading:
|
||||
return .complete()
|
||||
case let .postbox(postbox):
|
||||
return .single(TemporaryAccount(id: id, basePath: path, postbox: postbox))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func currentAccount(networkArguments: NetworkInitializationArguments, supplementary: Bool, manager: AccountManager, rootPath: String, testingEnvironment: Bool, auxiliaryMethods: AccountAuxiliaryMethods) -> Signal<AccountResult?, NoError> {
|
||||
return manager.allocatedCurrentAccountId()
|
||||
|> distinctUntilChanged(isEqual: { lhs, rhs in
|
||||
@ -113,7 +141,7 @@ public func logoutFromAccount(id: AccountRecordId, accountManager: AccountManage
|
||||
if found {
|
||||
return current
|
||||
} else {
|
||||
return AccountRecord(id: current.id, attributes: current.attributes + [LoggedOutAccountAttribute()])
|
||||
return AccountRecord(id: current.id, attributes: current.attributes + [LoggedOutAccountAttribute()], temporarySessionId: nil)
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
@ -126,8 +154,18 @@ public func logoutFromAccount(id: AccountRecordId, accountManager: AccountManage
|
||||
}
|
||||
|
||||
public func managedCleanupAccounts(networkArguments: NetworkInitializationArguments, accountManager: AccountManager, rootPath: String, auxiliaryMethods: AccountAuxiliaryMethods) -> Signal<Void, NoError> {
|
||||
let currentTemporarySessionId = accountManager.temporarySessionId
|
||||
return Signal { subscriber in
|
||||
let loggedOutAccounts = Atomic<[AccountRecordId: MetaDisposable]>(value: [:])
|
||||
let _ = (accountManager.transaction { transaction -> Void in
|
||||
for record in transaction.getRecords() {
|
||||
if let temporarySessionId = record.temporarySessionId, temporarySessionId != currentTemporarySessionId {
|
||||
transaction.updateRecord(record.id, { _ in
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}
|
||||
}).start()
|
||||
let disposable = accountManager.accountRecords().start(next: { view in
|
||||
var disposeList: [(AccountRecordId, MetaDisposable)] = []
|
||||
var beginList: [(AccountRecordId, MetaDisposable)] = []
|
||||
@ -172,6 +210,9 @@ public func managedCleanupAccounts(networkArguments: NetworkInitializationArgume
|
||||
|
||||
var validPaths = Set<String>()
|
||||
for record in view.records {
|
||||
if let temporarySessionId = record.temporarySessionId, temporarySessionId != currentTemporarySessionId {
|
||||
continue
|
||||
}
|
||||
validPaths.insert("\(accountRecordIdPathName(record.id))")
|
||||
}
|
||||
|
||||
|
||||
@ -295,6 +295,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = {
|
||||
dict[548253432] = { return Api.InputPeer.parse_inputPeerChannel($0) }
|
||||
dict[568808380] = { return Api.upload.WebFile.parse_webFile($0) }
|
||||
dict[-116274796] = { return Api.Contact.parse_contact($0) }
|
||||
dict[-1078332329] = { return Api.help.PassportConfig.parse_passportConfigNotModified($0) }
|
||||
dict[-1600596305] = { return Api.help.PassportConfig.parse_passportConfig($0) }
|
||||
dict[1648543603] = { return Api.FileHash.parse_fileHash($0) }
|
||||
dict[400266251] = { return Api.BotInlineResult.parse_botInlineMediaResult($0) }
|
||||
dict[295067450] = { return Api.BotInlineResult.parse_botInlineResult($0) }
|
||||
@ -881,6 +883,8 @@ struct Api {
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.Contact:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.help.PassportConfig:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.FileHash:
|
||||
_1.serialize(buffer, boxed)
|
||||
case let _1 as Api.BotInlineResult:
|
||||
|
||||
@ -1401,6 +1401,58 @@ struct help {
|
||||
return Api.help.AppUpdate.noAppUpdate
|
||||
}
|
||||
|
||||
}
|
||||
enum PassportConfig: TypeConstructorDescription {
|
||||
case passportConfigNotModified
|
||||
case passportConfig(hash: Int32, countriesLangs: Api.DataJSON)
|
||||
|
||||
func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) {
|
||||
switch self {
|
||||
case .passportConfigNotModified:
|
||||
if boxed {
|
||||
buffer.appendInt32(-1078332329)
|
||||
}
|
||||
|
||||
break
|
||||
case .passportConfig(let hash, let countriesLangs):
|
||||
if boxed {
|
||||
buffer.appendInt32(-1600596305)
|
||||
}
|
||||
serializeInt32(hash, buffer: buffer, boxed: false)
|
||||
countriesLangs.serialize(buffer, true)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func descriptionFields() -> (String, [(String, Any)]) {
|
||||
switch self {
|
||||
case .passportConfigNotModified:
|
||||
return ("passportConfigNotModified", [])
|
||||
case .passportConfig(let hash, let countriesLangs):
|
||||
return ("passportConfig", [("hash", hash), ("countriesLangs", countriesLangs)])
|
||||
}
|
||||
}
|
||||
|
||||
static func parse_passportConfigNotModified(_ reader: BufferReader) -> PassportConfig? {
|
||||
return Api.help.PassportConfig.passportConfigNotModified
|
||||
}
|
||||
static func parse_passportConfig(_ reader: BufferReader) -> PassportConfig? {
|
||||
var _1: Int32?
|
||||
_1 = reader.readInt32()
|
||||
var _2: Api.DataJSON?
|
||||
if let signature = reader.readInt32() {
|
||||
_2 = Api.parse(reader, signature: signature) as? Api.DataJSON
|
||||
}
|
||||
let _c1 = _1 != nil
|
||||
let _c2 = _2 != nil
|
||||
if _c1 && _c2 {
|
||||
return Api.help.PassportConfig.passportConfig(hash: _1!, countriesLangs: _2!)
|
||||
}
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
enum ProxyData: TypeConstructorDescription {
|
||||
case proxyDataEmpty(expires: Int32)
|
||||
|
||||
@ -4098,6 +4098,20 @@ extension Api {
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
static func getPassportConfig(hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.help.PassportConfig>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(-966677240)
|
||||
serializeInt32(hash, buffer: buffer, boxed: false)
|
||||
return (FunctionDescription(name: "help.getPassportConfig", parameters: [("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.help.PassportConfig? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: Api.help.PassportConfig?
|
||||
if let signature = reader.readInt32() {
|
||||
result = Api.parse(reader, signature: signature) as? Api.help.PassportConfig
|
||||
}
|
||||
return result
|
||||
})
|
||||
}
|
||||
}
|
||||
struct updates {
|
||||
static func getState() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.updates.State>) {
|
||||
@ -4896,39 +4910,6 @@ extension Api {
|
||||
}
|
||||
}
|
||||
struct langpack {
|
||||
static func getLangPack(langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.LangPackDifference>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(-1699363442)
|
||||
serializeString(langCode, buffer: buffer, boxed: false)
|
||||
return (FunctionDescription(name: "langpack.getLangPack", parameters: [("langCode", langCode)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.LangPackDifference? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: Api.LangPackDifference?
|
||||
if let signature = reader.readInt32() {
|
||||
result = Api.parse(reader, signature: signature) as? Api.LangPackDifference
|
||||
}
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
static func getStrings(langCode: String, keys: [String]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.LangPackString]>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(773776152)
|
||||
serializeString(langCode, buffer: buffer, boxed: false)
|
||||
buffer.appendInt32(481674261)
|
||||
buffer.appendInt32(Int32(keys.count))
|
||||
for item in keys {
|
||||
serializeString(item, buffer: buffer, boxed: false)
|
||||
}
|
||||
return (FunctionDescription(name: "langpack.getStrings", parameters: [("langCode", langCode), ("keys", keys)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> [Api.LangPackString]? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: [Api.LangPackString]?
|
||||
if let _ = reader.readInt32() {
|
||||
result = Api.parseVector(reader, elementSignature: 0, elementType: Api.LangPackString.self)
|
||||
}
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
static func getDifference(fromVersion: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.LangPackDifference>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(187583869)
|
||||
@ -4943,11 +4924,46 @@ extension Api {
|
||||
})
|
||||
}
|
||||
|
||||
static func getLanguages() -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.LangPackLanguage]>) {
|
||||
static func getLangPack(langPack: String, langCode: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<Api.LangPackDifference>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(-2146445955)
|
||||
|
||||
return (FunctionDescription(name: "langpack.getLanguages", parameters: []), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> [Api.LangPackLanguage]? in
|
||||
buffer.appendInt32(-219008246)
|
||||
serializeString(langPack, buffer: buffer, boxed: false)
|
||||
serializeString(langCode, buffer: buffer, boxed: false)
|
||||
return (FunctionDescription(name: "langpack.getLangPack", parameters: [("langPack", langPack), ("langCode", langCode)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.LangPackDifference? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: Api.LangPackDifference?
|
||||
if let signature = reader.readInt32() {
|
||||
result = Api.parse(reader, signature: signature) as? Api.LangPackDifference
|
||||
}
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
static func getStrings(langPack: String, langCode: String, keys: [String]) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.LangPackString]>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(-269862909)
|
||||
serializeString(langPack, buffer: buffer, boxed: false)
|
||||
serializeString(langCode, buffer: buffer, boxed: false)
|
||||
buffer.appendInt32(481674261)
|
||||
buffer.appendInt32(Int32(keys.count))
|
||||
for item in keys {
|
||||
serializeString(item, buffer: buffer, boxed: false)
|
||||
}
|
||||
return (FunctionDescription(name: "langpack.getStrings", parameters: [("langPack", langPack), ("langCode", langCode), ("keys", keys)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> [Api.LangPackString]? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: [Api.LangPackString]?
|
||||
if let _ = reader.readInt32() {
|
||||
result = Api.parseVector(reader, elementSignature: 0, elementType: Api.LangPackString.self)
|
||||
}
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
static func getLanguages(langPack: String) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Api.LangPackLanguage]>) {
|
||||
let buffer = Buffer()
|
||||
buffer.appendInt32(1120311183)
|
||||
serializeString(langPack, buffer: buffer, boxed: false)
|
||||
return (FunctionDescription(name: "langpack.getLanguages", parameters: [("langPack", langPack)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> [Api.LangPackLanguage]? in
|
||||
let reader = BufferReader(buffer)
|
||||
var result: [Api.LangPackLanguage]?
|
||||
if let _ = reader.readInt32() {
|
||||
|
||||
@ -23,7 +23,7 @@ public func currentlySuggestedLocalization(network: Network, extractKeys: [Strin
|
||||
}
|
||||
|
||||
public func suggestedLocalizationInfo(network: Network, languageCode: String, extractKeys: [String]) -> Signal<SuggestedLocalizationInfo, NoError> {
|
||||
return combineLatest(network.request(Api.functions.langpack.getLanguages()), network.request(Api.functions.langpack.getStrings(langCode: languageCode, keys: extractKeys)))
|
||||
return combineLatest(network.request(Api.functions.langpack.getLanguages(langPack: "")), network.request(Api.functions.langpack.getStrings(langCode: languageCode, keys: extractKeys)))
|
||||
|> retryRequest
|
||||
|> map { languages, strings -> SuggestedLocalizationInfo in
|
||||
var entries: [LocalizationEntry] = []
|
||||
@ -76,7 +76,7 @@ public func availableLocalizations(postbox: Postbox, network: Network, allowCach
|
||||
} else {
|
||||
cached = .complete()
|
||||
}
|
||||
let remote = network.request(Api.functions.langpack.getLanguages())
|
||||
let remote = network.request(Api.functions.langpack.getLanguages(langPack: ""))
|
||||
|> retryRequest
|
||||
|> mapToSignal { languages -> Signal<[LocalizationInfo], NoError> in
|
||||
var infos: [LocalizationInfo] = []
|
||||
@ -96,7 +96,7 @@ public func availableLocalizations(postbox: Postbox, network: Network, allowCach
|
||||
}
|
||||
|
||||
public func downloadLocalization(network: Network, languageCode: String) -> Signal<Localization, NoError> {
|
||||
return network.request(Api.functions.langpack.getLangPack(langCode: languageCode))
|
||||
return network.request(Api.functions.langpack.getLangPack(langPack: "", langCode: languageCode))
|
||||
|> retryRequest
|
||||
|> map { result -> Localization in
|
||||
let version: Int32
|
||||
|
||||
@ -61,6 +61,7 @@ public struct Namespaces {
|
||||
public static let cachedAvailableLocalizations: Int8 = 3
|
||||
public static let cachedSentMediaReferences: Int8 = 4
|
||||
public static let cachedStickerQueryResults: Int8 = 5
|
||||
public static let cachedSecureIdConfiguration: Int8 = 6
|
||||
}
|
||||
|
||||
struct UnorderedItemList {
|
||||
|
||||
89
TelegramCore/SecureIdConfiguration.swift
Normal file
89
TelegramCore/SecureIdConfiguration.swift
Normal file
@ -0,0 +1,89 @@
|
||||
import Foundation
|
||||
#if os(macOS)
|
||||
import PostboxMac
|
||||
import MtProtoKitMac
|
||||
import SwiftSignalKitMac
|
||||
#else
|
||||
import Postbox
|
||||
import MtProtoKitDynamic
|
||||
import SwiftSignalKit
|
||||
#endif
|
||||
|
||||
final class CachedSecureIdConfiguration: PostboxCoding {
|
||||
let value: SecureIdConfiguration
|
||||
let hash: Int32
|
||||
|
||||
init(value: SecureIdConfiguration, hash: Int32) {
|
||||
self.value = value
|
||||
self.hash = hash
|
||||
}
|
||||
|
||||
init(decoder: PostboxDecoder) {
|
||||
self.value = decoder.decodeObjectForKey("value", decoder: { SecureIdConfiguration(decoder: $0) }) as! SecureIdConfiguration
|
||||
self.hash = decoder.decodeInt32ForKey("hash", orElse: 0)
|
||||
}
|
||||
|
||||
func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObject(self.value, forKey: "value")
|
||||
encoder.encodeInt32(self.hash, forKey: "hash")
|
||||
}
|
||||
}
|
||||
|
||||
public struct SecureIdConfiguration: PostboxCoding {
|
||||
public let nativeLanguageByCountry: [String: String]
|
||||
|
||||
fileprivate init?(jsonString: String) {
|
||||
return nil
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
let nativeLanguageByCountryData = decoder.decodeBytesForKey("nativeLanguageByCountry")!
|
||||
self.nativeLanguageByCountry = (try? JSONDecoder().decode(Dictionary<String, String>.self, from: nativeLanguageByCountryData.dataNoCopy())) ?? [:]
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
let nativeLanguageByCountryData = (try? JSONEncoder().encode(self.nativeLanguageByCountry)) ?? Data()
|
||||
encoder.encodeBytes(MemoryBuffer(data: nativeLanguageByCountryData), forKey: "nativeLanguageByCountry")
|
||||
}
|
||||
}
|
||||
|
||||
public func secureIdConfiguration(postbox: Postbox, network: Network) -> Signal<SecureIdConfiguration, NoError> {
|
||||
let cached: Signal<CachedSecureIdConfiguration?, NoError> = postbox.transaction { transaction -> CachedSecureIdConfiguration? in
|
||||
if let entry = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedSecureIdConfiguration, key: ValueBoxKey(length: 0))) as? CachedSecureIdConfiguration {
|
||||
return entry
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return cached
|
||||
|> mapToSignal { cached -> Signal<SecureIdConfiguration, NoError> in
|
||||
return network.request(Api.functions.help.getPassportConfig(hash: cached?.hash ?? 0))
|
||||
|> retryRequest
|
||||
|> mapToSignal { result -> Signal<SecureIdConfiguration, NoError> in
|
||||
let parsed: CachedSecureIdConfiguration
|
||||
switch result {
|
||||
case .passportConfigNotModified:
|
||||
if let cached = cached {
|
||||
return .single(cached.value)
|
||||
} else {
|
||||
assertionFailure()
|
||||
return .complete()
|
||||
}
|
||||
case let .passportConfig(hash, countriesLangs):
|
||||
switch countriesLangs {
|
||||
case let .dataJSON(data):
|
||||
if let value = SecureIdConfiguration(jsonString: data) {
|
||||
parsed = CachedSecureIdConfiguration(value: value, hash: hash)
|
||||
} else {
|
||||
assertionFailure()
|
||||
return .complete()
|
||||
}
|
||||
}
|
||||
}
|
||||
return postbox.transaction { transaction -> SecureIdConfiguration in
|
||||
transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedSecureIdConfiguration, key: ValueBoxKey(length: 0)), entry: parsed, collectionSpec: ItemCacheCollectionSpec(lowWaterItemCount: 1, highWaterItemCount: 1))
|
||||
return parsed.value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -549,8 +549,6 @@ extension StoreMessage {
|
||||
|
||||
storeFlags.insert(.CanBeGroupedIntoFeed)
|
||||
|
||||
assert(!tags.contains(.unseenPersonalMessage) || date > 1493596800)
|
||||
|
||||
self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: id), globallyUniqueId: nil, groupingKey: groupingId, timestamp: date, flags: storeFlags, tags: tags, globalTags: globalTags, localTags: [], forwardInfo: forwardInfo, authorId: authorId, text: messageText, attributes: attributes, media: medias)
|
||||
case .messageEmpty:
|
||||
return nil
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user