mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-29 11:25:38 +00:00
no message
This commit is contained in:
parent
3426ba2972
commit
5eeaed40c2
@ -101,7 +101,7 @@ public func ==(lhs: AuthorizedAccountState.State, rhs: AuthorizedAccountState.St
|
|||||||
public class UnauthorizedAccount {
|
public class UnauthorizedAccount {
|
||||||
public let networkArguments: NetworkInitializationArguments
|
public let networkArguments: NetworkInitializationArguments
|
||||||
public let id: AccountRecordId
|
public let id: AccountRecordId
|
||||||
public let appGroupPath: String
|
public let rootPath: String
|
||||||
public let basePath: String
|
public let basePath: String
|
||||||
public let testingEnvironment: Bool
|
public let testingEnvironment: Bool
|
||||||
public let postbox: Postbox
|
public let postbox: Postbox
|
||||||
@ -113,10 +113,10 @@ public class UnauthorizedAccount {
|
|||||||
|
|
||||||
public let shouldBeServiceTaskMaster = Promise<AccountServiceTaskMasterMode>()
|
public let shouldBeServiceTaskMaster = Promise<AccountServiceTaskMasterMode>()
|
||||||
|
|
||||||
init(networkArguments: NetworkInitializationArguments, id: AccountRecordId, appGroupPath: String, basePath: String, testingEnvironment: Bool, postbox: Postbox, network: Network, shouldKeepAutoConnection: Bool = true) {
|
init(networkArguments: NetworkInitializationArguments, id: AccountRecordId, rootPath: String, basePath: String, testingEnvironment: Bool, postbox: Postbox, network: Network, shouldKeepAutoConnection: Bool = true) {
|
||||||
self.networkArguments = networkArguments
|
self.networkArguments = networkArguments
|
||||||
self.id = id
|
self.id = id
|
||||||
self.appGroupPath = appGroupPath
|
self.rootPath = rootPath
|
||||||
self.basePath = basePath
|
self.basePath = basePath
|
||||||
self.testingEnvironment = testingEnvironment
|
self.testingEnvironment = testingEnvironment
|
||||||
self.postbox = postbox
|
self.postbox = postbox
|
||||||
@ -150,7 +150,7 @@ public class UnauthorizedAccount {
|
|||||||
} |> mapToSignal { (localizationSettings, proxySettings) -> Signal<UnauthorizedAccount, NoError> in
|
} |> mapToSignal { (localizationSettings, proxySettings) -> Signal<UnauthorizedAccount, NoError> in
|
||||||
return initializedNetwork(arguments: self.networkArguments, supplementary: false, datacenterId: Int(masterDatacenterId), keychain: keychain, basePath: self.basePath, testingEnvironment: self.testingEnvironment, languageCode: localizationSettings?.languageCode, proxySettings: proxySettings)
|
return initializedNetwork(arguments: self.networkArguments, supplementary: false, datacenterId: Int(masterDatacenterId), keychain: keychain, basePath: self.basePath, testingEnvironment: self.testingEnvironment, languageCode: localizationSettings?.languageCode, proxySettings: proxySettings)
|
||||||
|> map { network in
|
|> map { network in
|
||||||
let updated = UnauthorizedAccount(networkArguments: self.networkArguments, id: self.id, appGroupPath: self.appGroupPath, basePath: self.basePath, testingEnvironment: self.testingEnvironment, postbox: self.postbox, network: network)
|
let updated = UnauthorizedAccount(networkArguments: self.networkArguments, id: self.id, rootPath: self.rootPath, basePath: self.basePath, testingEnvironment: self.testingEnvironment, postbox: self.postbox, network: network)
|
||||||
updated.shouldBeServiceTaskMaster.set(self.shouldBeServiceTaskMaster.get())
|
updated.shouldBeServiceTaskMaster.set(self.shouldBeServiceTaskMaster.get())
|
||||||
return updated
|
return updated
|
||||||
}
|
}
|
||||||
@ -273,10 +273,10 @@ public enum AccountResult {
|
|||||||
case authorized(Account)
|
case authorized(Account)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func accountWithId(networkArguments: NetworkInitializationArguments, id: AccountRecordId, supplementary: Bool, appGroupPath: String, testingEnvironment: Bool, auxiliaryMethods: AccountAuxiliaryMethods, shouldKeepAutoConnection: Bool = true) -> Signal<AccountResult, NoError> {
|
public func accountWithId(networkArguments: NetworkInitializationArguments, id: AccountRecordId, supplementary: Bool, rootPath: String, testingEnvironment: Bool, auxiliaryMethods: AccountAuxiliaryMethods, shouldKeepAutoConnection: Bool = true) -> Signal<AccountResult, NoError> {
|
||||||
let _ = declaredEncodables
|
let _ = declaredEncodables
|
||||||
|
|
||||||
let path = "\(appGroupPath)/\(accountRecordIdPathName(id))"
|
let path = "\(rootPath)/\(accountRecordIdPathName(id))"
|
||||||
|
|
||||||
var initializeMessageNamespacesWithHoles: [(PeerId.Namespace, MessageId.Namespace)] = []
|
var initializeMessageNamespacesWithHoles: [(PeerId.Namespace, MessageId.Namespace)] = []
|
||||||
for peerNamespace in peerIdNamespacesWithInitialCloudMessageHoles {
|
for peerNamespace in peerIdNamespacesWithInitialCloudMessageHoles {
|
||||||
@ -313,7 +313,7 @@ public func accountWithId(networkArguments: NetworkInitializationArguments, id:
|
|||||||
case let unauthorizedState as UnauthorizedAccountState:
|
case let unauthorizedState as UnauthorizedAccountState:
|
||||||
return initializedNetwork(arguments: networkArguments, supplementary: supplementary, datacenterId: Int(unauthorizedState.masterDatacenterId), keychain: keychain, basePath: path, testingEnvironment: testingEnvironment, languageCode: localizationSettings?.languageCode, proxySettings: proxySettings)
|
return initializedNetwork(arguments: networkArguments, supplementary: supplementary, datacenterId: Int(unauthorizedState.masterDatacenterId), keychain: keychain, basePath: path, testingEnvironment: testingEnvironment, languageCode: localizationSettings?.languageCode, proxySettings: proxySettings)
|
||||||
|> map { network -> AccountResult in
|
|> map { network -> AccountResult in
|
||||||
return .unauthorized(UnauthorizedAccount(networkArguments: networkArguments, id: id, appGroupPath: appGroupPath, basePath: path, testingEnvironment: testingEnvironment, postbox: postbox, network: network, shouldKeepAutoConnection: shouldKeepAutoConnection))
|
return .unauthorized(UnauthorizedAccount(networkArguments: networkArguments, id: id, rootPath: rootPath, basePath: path, testingEnvironment: testingEnvironment, postbox: postbox, network: network, shouldKeepAutoConnection: shouldKeepAutoConnection))
|
||||||
}
|
}
|
||||||
case let authorizedState as AuthorizedAccountState:
|
case let authorizedState as AuthorizedAccountState:
|
||||||
return initializedNetwork(arguments: networkArguments, supplementary: supplementary, datacenterId: Int(authorizedState.masterDatacenterId), keychain: keychain, basePath: path, testingEnvironment: testingEnvironment, languageCode: localizationSettings?.languageCode, proxySettings: proxySettings)
|
return initializedNetwork(arguments: networkArguments, supplementary: supplementary, datacenterId: Int(authorizedState.masterDatacenterId), keychain: keychain, basePath: path, testingEnvironment: testingEnvironment, languageCode: localizationSettings?.languageCode, proxySettings: proxySettings)
|
||||||
@ -327,7 +327,7 @@ public func accountWithId(networkArguments: NetworkInitializationArguments, id:
|
|||||||
|
|
||||||
return initializedNetwork(arguments: networkArguments, supplementary: supplementary, datacenterId: 2, keychain: keychain, basePath: path, testingEnvironment: testingEnvironment, languageCode: localizationSettings?.languageCode, proxySettings: proxySettings)
|
return initializedNetwork(arguments: networkArguments, supplementary: supplementary, datacenterId: 2, keychain: keychain, basePath: path, testingEnvironment: testingEnvironment, languageCode: localizationSettings?.languageCode, proxySettings: proxySettings)
|
||||||
|> map { network -> AccountResult in
|
|> map { network -> AccountResult in
|
||||||
return .unauthorized(UnauthorizedAccount(networkArguments: networkArguments, id: id, appGroupPath: appGroupPath, basePath: path, testingEnvironment: testingEnvironment, postbox: postbox, network: network, shouldKeepAutoConnection: shouldKeepAutoConnection))
|
return .unauthorized(UnauthorizedAccount(networkArguments: networkArguments, id: id, rootPath: rootPath, basePath: path, testingEnvironment: testingEnvironment, postbox: postbox, network: network, shouldKeepAutoConnection: shouldKeepAutoConnection))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,34 @@ private enum AccountKind {
|
|||||||
case unauthorized
|
case unauthorized
|
||||||
}
|
}
|
||||||
|
|
||||||
public func currentAccount(networkArguments: NetworkInitializationArguments, supplementary: Bool, manager: AccountManager, appGroupPath: String, testingEnvironment: Bool, auxiliaryMethods: AccountAuxiliaryMethods) -> Signal<AccountResult?, NoError> {
|
public func rootPathForBasePath(_ appGroupPath: String) -> String {
|
||||||
|
return appGroupPath + "/telegram-data"
|
||||||
|
}
|
||||||
|
|
||||||
|
public func performAppGroupUpgrades(appGroupPath: String, rootPath: String) {
|
||||||
|
let _ = try? FileManager.default.createDirectory(at: URL(fileURLWithPath: rootPath), withIntermediateDirectories: true, attributes: nil)
|
||||||
|
|
||||||
|
do {
|
||||||
|
var resourceValues = URLResourceValues()
|
||||||
|
resourceValues.isExcludedFromBackup = true
|
||||||
|
var mutableUrl = URL(fileURLWithPath: rootPath)
|
||||||
|
try mutableUrl.setResourceValues(resourceValues)
|
||||||
|
} catch let e {
|
||||||
|
print("\(e)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let files = try? FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: appGroupPath), includingPropertiesForKeys: [], options: []) {
|
||||||
|
for url in files {
|
||||||
|
if url.lastPathComponent == "accounts-metadata" ||
|
||||||
|
url.lastPathComponent.hasSuffix("logs") ||
|
||||||
|
url.lastPathComponent.hasPrefix("account-") {
|
||||||
|
let _ = try? FileManager.default.moveItem(at: url, to: URL(fileURLWithPath: rootPath + "/" + url.lastPathComponent))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func currentAccount(networkArguments: NetworkInitializationArguments, supplementary: Bool, manager: AccountManager, rootPath: String, testingEnvironment: Bool, auxiliaryMethods: AccountAuxiliaryMethods) -> Signal<AccountResult?, NoError> {
|
||||||
return manager.allocatedCurrentAccountId()
|
return manager.allocatedCurrentAccountId()
|
||||||
|> distinctUntilChanged(isEqual: { lhs, rhs in
|
|> distinctUntilChanged(isEqual: { lhs, rhs in
|
||||||
return lhs == rhs
|
return lhs == rhs
|
||||||
@ -23,7 +50,7 @@ public func currentAccount(networkArguments: NetworkInitializationArguments, sup
|
|||||||
if let id = id {
|
if let id = id {
|
||||||
let reload = ValuePromise<Bool>(true, ignoreRepeated: false)
|
let reload = ValuePromise<Bool>(true, ignoreRepeated: false)
|
||||||
return reload.get() |> mapToSignal { _ -> Signal<AccountResult?, NoError> in
|
return reload.get() |> mapToSignal { _ -> Signal<AccountResult?, NoError> in
|
||||||
return accountWithId(networkArguments: networkArguments, id: id, supplementary: supplementary, appGroupPath: appGroupPath, testingEnvironment: testingEnvironment, auxiliaryMethods: auxiliaryMethods)
|
return accountWithId(networkArguments: networkArguments, id: id, supplementary: supplementary, rootPath: rootPath, testingEnvironment: testingEnvironment, auxiliaryMethods: auxiliaryMethods)
|
||||||
|> mapToSignal { accountResult -> Signal<AccountResult?, NoError> in
|
|> mapToSignal { accountResult -> Signal<AccountResult?, NoError> in
|
||||||
let postbox: Postbox
|
let postbox: Postbox
|
||||||
let initialKind: AccountKind
|
let initialKind: AccountKind
|
||||||
@ -98,7 +125,7 @@ public func logoutFromAccount(id: AccountRecordId, accountManager: AccountManage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func managedCleanupAccounts(networkArguments: NetworkInitializationArguments, accountManager: AccountManager, appGroupPath: String, auxiliaryMethods: AccountAuxiliaryMethods) -> Signal<Void, NoError> {
|
public func managedCleanupAccounts(networkArguments: NetworkInitializationArguments, accountManager: AccountManager, rootPath: String, auxiliaryMethods: AccountAuxiliaryMethods) -> Signal<Void, NoError> {
|
||||||
return Signal { subscriber in
|
return Signal { subscriber in
|
||||||
let loggedOutAccounts = Atomic<[AccountRecordId: MetaDisposable]>(value: [:])
|
let loggedOutAccounts = Atomic<[AccountRecordId: MetaDisposable]>(value: [:])
|
||||||
let disposable = accountManager.accountRecords().start(next: { view in
|
let disposable = accountManager.accountRecords().start(next: { view in
|
||||||
@ -114,7 +141,6 @@ public func managedCleanupAccounts(networkArguments: NetworkInitializationArgume
|
|||||||
return false
|
return false
|
||||||
}.map { $0.id })
|
}.map { $0.id })
|
||||||
|
|
||||||
|
|
||||||
var disposables = disposables
|
var disposables = disposables
|
||||||
|
|
||||||
for id in disposables.keys {
|
for id in disposables.keys {
|
||||||
@ -141,7 +167,22 @@ public func managedCleanupAccounts(networkArguments: NetworkInitializationArgume
|
|||||||
disposable.dispose()
|
disposable.dispose()
|
||||||
}
|
}
|
||||||
for (id, disposable) in beginList {
|
for (id, disposable) in beginList {
|
||||||
disposable.set(cleanupAccount(networkArguments: networkArguments, accountManager: accountManager, id: id, appGroupPath: appGroupPath, auxiliaryMethods: auxiliaryMethods).start())
|
disposable.set(cleanupAccount(networkArguments: networkArguments, accountManager: accountManager, id: id, rootPath: rootPath, auxiliaryMethods: auxiliaryMethods).start())
|
||||||
|
}
|
||||||
|
|
||||||
|
var validPaths = Set<String>()
|
||||||
|
for record in view.records {
|
||||||
|
validPaths.insert("\(accountRecordIdPathName(record.id))")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let files = try? FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: rootPath), includingPropertiesForKeys: [], options: []) {
|
||||||
|
for url in files {
|
||||||
|
if url.lastPathComponent.hasPrefix("account-") {
|
||||||
|
if !validPaths.contains(url.lastPathComponent) {
|
||||||
|
try? FileManager.default.removeItem(at: url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -151,9 +192,8 @@ public func managedCleanupAccounts(networkArguments: NetworkInitializationArgume
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func cleanupAccount(networkArguments: NetworkInitializationArguments, accountManager: AccountManager, id: AccountRecordId, rootPath: String, auxiliaryMethods: AccountAuxiliaryMethods) -> Signal<Void, NoError> {
|
||||||
private func cleanupAccount(networkArguments: NetworkInitializationArguments, accountManager: AccountManager, id: AccountRecordId, appGroupPath: String, auxiliaryMethods: AccountAuxiliaryMethods) -> Signal<Void, NoError> {
|
return accountWithId(networkArguments: networkArguments, id: id, supplementary: true, rootPath: rootPath, testingEnvironment: false, auxiliaryMethods: auxiliaryMethods)
|
||||||
return accountWithId(networkArguments: networkArguments, id: id, supplementary: true, appGroupPath: appGroupPath, testingEnvironment: false, auxiliaryMethods: auxiliaryMethods)
|
|
||||||
|> mapToSignal { account -> Signal<Void, NoError> in
|
|> mapToSignal { account -> Signal<Void, NoError> in
|
||||||
switch account {
|
switch account {
|
||||||
case .upgrading:
|
case .upgrading:
|
||||||
|
|||||||
@ -7,8 +7,13 @@ import Foundation
|
|||||||
import SwiftSignalKit
|
import SwiftSignalKit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public func applyMaxReadIndexInteractively(postbox: Postbox, network: Network, stateManager: AccountStateManager, index: MessageIndex) -> Signal<Void, NoError> {
|
public func applyMaxReadIndexInteractively(postbox: Postbox, stateManager: AccountStateManager, index: MessageIndex) -> Signal<Void, NoError> {
|
||||||
return postbox.modify { modifier -> Void in
|
return postbox.modify { modifier -> Void in
|
||||||
|
applyMaxReadIndexInteractively(modifier: modifier, stateManager: stateManager, index: index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func applyMaxReadIndexInteractively(modifier: Modifier, stateManager: AccountStateManager, index: MessageIndex) {
|
||||||
let messageIds = modifier.applyInteractiveReadMaxIndex(index)
|
let messageIds = modifier.applyInteractiveReadMaxIndex(index)
|
||||||
if index.id.peerId.namespace == Namespaces.Peer.SecretChat {
|
if index.id.peerId.namespace == Namespaces.Peer.SecretChat {
|
||||||
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
|
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
|
||||||
@ -42,7 +47,6 @@ public func applyMaxReadIndexInteractively(postbox: Postbox, network: Network, s
|
|||||||
stateManager.notifyAppliedIncomingReadMessages([index.id])
|
stateManager.notifyAppliedIncomingReadMessages([index.id])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func applyOutgoingReadMaxIndex(modifier: Modifier, index: MessageIndex, beginCountdownAt timestamp: Int32) {
|
func applyOutgoingReadMaxIndex(modifier: Modifier, index: MessageIndex, beginCountdownAt timestamp: Int32) {
|
||||||
let messageIds = modifier.applyOutgoingReadMaxIndex(index)
|
let messageIds = modifier.applyOutgoingReadMaxIndex(index)
|
||||||
|
|||||||
@ -44,39 +44,45 @@ final class CachedStickerPack: PostboxCoding {
|
|||||||
|
|
||||||
private let collectionSpec = ItemCacheCollectionSpec(lowWaterItemCount: 100, highWaterItemCount: 200)
|
private let collectionSpec = ItemCacheCollectionSpec(lowWaterItemCount: 100, highWaterItemCount: 200)
|
||||||
|
|
||||||
public func cachedStickerPack(postbox: Postbox, network: Network, reference: StickerPackReference) -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem], Bool)?, NoError> {
|
public enum CachedStickerPackResult {
|
||||||
return postbox.modify { modifier -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem], Bool)?, NoError> in
|
case none
|
||||||
|
case fetching
|
||||||
|
case result(StickerPackCollectionInfo, [ItemCollectionItem], Bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func cachedStickerPack(postbox: Postbox, network: Network, reference: StickerPackReference) -> Signal<CachedStickerPackResult, NoError> {
|
||||||
|
return postbox.modify { modifier -> Signal<CachedStickerPackResult, NoError> in
|
||||||
let namespace = Namespaces.ItemCollection.CloudStickerPacks
|
let namespace = Namespaces.ItemCollection.CloudStickerPacks
|
||||||
if case let .id(id, _) = reference, let currentInfo = modifier.getItemCollectionInfo(collectionId: ItemCollectionId(namespace: namespace, id: id)) as? StickerPackCollectionInfo {
|
if case let .id(id, _) = reference, let currentInfo = modifier.getItemCollectionInfo(collectionId: ItemCollectionId(namespace: namespace, id: id)) as? StickerPackCollectionInfo {
|
||||||
let items = modifier.getItemCollectionItems(collectionId: ItemCollectionId(namespace: namespace, id: id))
|
let items = modifier.getItemCollectionItems(collectionId: ItemCollectionId(namespace: namespace, id: id))
|
||||||
return .single((currentInfo, items, true))
|
return .single(.result(currentInfo, items, true))
|
||||||
} else {
|
} else {
|
||||||
let current: Signal<(StickerPackCollectionInfo, [ItemCollectionItem], Bool)?, NoError>
|
let current: Signal<CachedStickerPackResult, NoError>
|
||||||
var loadRemote = false
|
var loadRemote = false
|
||||||
|
|
||||||
if case let .id(id, _) = reference, let cached = modifier.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, let info = cached.info {
|
if case let .id(id, _) = reference, let cached = modifier.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, let info = cached.info {
|
||||||
current = .single((info, cached.items, false))
|
current = .single(.result(info, cached.items, false))
|
||||||
if cached.hash != info.hash {
|
if cached.hash != info.hash {
|
||||||
loadRemote = true
|
loadRemote = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
current = .single(nil)
|
current = .single(.fetching)
|
||||||
loadRemote = true
|
loadRemote = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var signal = current
|
var signal = current
|
||||||
if loadRemote {
|
if loadRemote {
|
||||||
let appliedRemote = remoteStickerPack(network: network, reference: reference)
|
let appliedRemote = remoteStickerPack(network: network, reference: reference)
|
||||||
|> mapToSignal { result -> Signal<(StickerPackCollectionInfo, [ItemCollectionItem], Bool)?, NoError> in
|
|> mapToSignal { result -> Signal<CachedStickerPackResult, NoError> in
|
||||||
return postbox.modify { modifier -> (StickerPackCollectionInfo, [ItemCollectionItem], Bool)? in
|
return postbox.modify { modifier -> CachedStickerPackResult in
|
||||||
if let result = result {
|
if let result = result {
|
||||||
modifier.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(result.0.id)), entry: CachedStickerPack(info: result.0, items: result.1.map { $0 as! StickerPackItem }, hash: result.0.hash), collectionSpec: collectionSpec)
|
modifier.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(result.0.id)), entry: CachedStickerPack(info: result.0, items: result.1.map { $0 as! StickerPackItem }, hash: result.0.hash), collectionSpec: collectionSpec)
|
||||||
|
|
||||||
let currentInfo = modifier.getItemCollectionInfo(collectionId: result.0.id) as? StickerPackCollectionInfo
|
let currentInfo = modifier.getItemCollectionInfo(collectionId: result.0.id) as? StickerPackCollectionInfo
|
||||||
|
|
||||||
return (result.0, result.1, currentInfo != nil)
|
return .result(result.0, result.1, currentInfo != nil)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return .none
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -165,6 +165,9 @@ public func collectCacheUsageStats(account: Account) -> Signal<CacheUsageStatsRe
|
|||||||
for peerId in finalMedia.keys {
|
for peerId in finalMedia.keys {
|
||||||
if let peer = modifier.getPeer(peerId) {
|
if let peer = modifier.getPeer(peerId) {
|
||||||
peers[peer.id] = peer
|
peers[peer.id] = peer
|
||||||
|
if let associatedPeerId = peer.associatedPeerId, let associatedPeer = modifier.getPeer(associatedPeerId) {
|
||||||
|
peers[associatedPeer.id] = associatedPeer
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CacheUsageStats(media: finalMedia, mediaResourceIds: finalMediaResourceIds, peers: peers, otherSize: otherSize, otherPaths: otherPaths, cacheSize: cacheSize, tempPaths: tempPaths, tempSize: tempSize)
|
return CacheUsageStats(media: finalMedia, mediaResourceIds: finalMediaResourceIds, peers: peers, otherSize: otherSize, otherPaths: otherPaths, cacheSize: cacheSize, tempPaths: tempPaths, tempSize: tempSize)
|
||||||
|
|||||||
@ -7,10 +7,12 @@ import Foundation
|
|||||||
import SwiftSignalKit
|
import SwiftSignalKit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public func installInteractiveReadMessagesAction(postbox: Postbox, peerId: PeerId) -> Disposable {
|
public func installInteractiveReadMessagesAction(postbox: Postbox, stateManager: AccountStateManager, peerId: PeerId) -> Disposable {
|
||||||
return postbox.installStoreMessageAction(peerId: peerId, { messages, modifier in
|
return postbox.installStoreMessageAction(peerId: peerId, { messages, modifier in
|
||||||
var consumeMessageIds: [MessageId] = []
|
var consumeMessageIds: [MessageId] = []
|
||||||
|
|
||||||
|
var readMessageIndexByNamespace: [MessageId.Namespace: MessageIndex] = [:]
|
||||||
|
|
||||||
for message in messages {
|
for message in messages {
|
||||||
if case let .Id(id) = message.id {
|
if case let .Id(id) = message.id {
|
||||||
var hasUnconsumedMention = false
|
var hasUnconsumedMention = false
|
||||||
@ -29,6 +31,14 @@ public func installInteractiveReadMessagesAction(postbox: Postbox, peerId: PeerI
|
|||||||
if hasUnconsumedMention && !hasUnconsumedContent {
|
if hasUnconsumedMention && !hasUnconsumedContent {
|
||||||
consumeMessageIds.append(id)
|
consumeMessageIds.append(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if message.flags.contains(.Incoming) {
|
||||||
|
let index = MessageIndex(id: id, timestamp: message.timestamp)
|
||||||
|
let current = readMessageIndexByNamespace[id.namespace]
|
||||||
|
if current == nil || current! < index {
|
||||||
|
readMessageIndexByNamespace[id.namespace] = index
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,5 +56,9 @@ public func installInteractiveReadMessagesAction(postbox: Postbox, peerId: PeerI
|
|||||||
|
|
||||||
modifier.setPendingMessageAction(type: .consumeUnseenPersonalMessage, id: id, action: ConsumePersonalMessageAction())
|
modifier.setPendingMessageAction(type: .consumeUnseenPersonalMessage, id: id, action: ConsumePersonalMessageAction())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (_, index) in readMessageIndexByNamespace {
|
||||||
|
applyMaxReadIndexInteractively(modifier: modifier, stateManager: stateManager, index: index)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,58 +89,13 @@ func remoteStickerPack(network: Network, reference: StickerPackReference) -> Sig
|
|||||||
public func loadedStickerPack(postbox: Postbox, network: Network, reference: StickerPackReference) -> Signal<LoadedStickerPack, NoError> {
|
public func loadedStickerPack(postbox: Postbox, network: Network, reference: StickerPackReference) -> Signal<LoadedStickerPack, NoError> {
|
||||||
return cachedStickerPack(postbox: postbox, network: network, reference: reference)
|
return cachedStickerPack(postbox: postbox, network: network, reference: reference)
|
||||||
|> map { result -> LoadedStickerPack in
|
|> map { result -> LoadedStickerPack in
|
||||||
if let result = result {
|
switch result {
|
||||||
return .result(info: result.0, items: result.1, installed: result.2)
|
case .none:
|
||||||
} else {
|
return .none
|
||||||
|
case .fetching:
|
||||||
return .fetching
|
return .fetching
|
||||||
|
case let .result(info, items, installed):
|
||||||
|
return .result(info: info, items: items, installed: installed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func loadedStickerPack1(account: Account, reference: StickerPackReference) -> Signal<LoadedStickerPack, NoError> {
|
|
||||||
return account.postbox.modify { modifier -> Signal<LoadedStickerPack, NoError> in
|
|
||||||
switch reference {
|
|
||||||
case let .id(id, _):
|
|
||||||
if let info = modifier.getItemCollectionInfo(collectionId: ItemCollectionId(namespace: Namespaces.ItemCollection.CloudStickerPacks, id: id)) as? StickerPackCollectionInfo {
|
|
||||||
let items = modifier.getItemCollectionItems(collectionId: info.id)
|
|
||||||
return account.postbox.combinedView(keys: [PostboxViewKey.itemCollectionInfo(id: info.id)])
|
|
||||||
|> map { view in
|
|
||||||
if let view = view.views[PostboxViewKey.itemCollectionInfo(id: info.id)] as? ItemCollectionInfoView, let info = view.info as? StickerPackCollectionInfo {
|
|
||||||
return .result(info: info, items: items, installed: true)
|
|
||||||
} else {
|
|
||||||
return .result(info: info, items: items, installed: false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if let info = modifier.getItemCollectionInfo(collectionId: ItemCollectionId(namespace: Namespaces.ItemCollection.CloudMaskPacks, id: id)) as? StickerPackCollectionInfo {
|
|
||||||
let items = modifier.getItemCollectionItems(collectionId: info.id)
|
|
||||||
return account.postbox.combinedView(keys: [PostboxViewKey.itemCollectionInfo(id: info.id)])
|
|
||||||
|> map { view in
|
|
||||||
if let view = view.views[PostboxViewKey.itemCollectionInfo(id: info.id)] as? ItemCollectionInfoView, let info = view.info as? StickerPackCollectionInfo {
|
|
||||||
return .result(info: info, items: items, installed: true)
|
|
||||||
} else {
|
|
||||||
return .result(info: info, items: items, installed: false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
let signal = remoteStickerPack(network: account.network, reference: reference) |> mapToSignal { result -> Signal<LoadedStickerPack, NoError> in
|
|
||||||
if let result = result {
|
|
||||||
return account.postbox.combinedView(keys: [PostboxViewKey.itemCollectionInfo(id: result.0.id)])
|
|
||||||
|> map { view in
|
|
||||||
if let view = view.views[PostboxViewKey.itemCollectionInfo(id: result.0.id)] as? ItemCollectionInfoView, let info = view.info as? StickerPackCollectionInfo {
|
|
||||||
return .result(info: info, items: result.1, installed: true)
|
|
||||||
} else {
|
|
||||||
return .result(info: result.0, items: result.1, installed: false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return .single(.none)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return .single(.fetching) |> then(signal)
|
|
||||||
} |> switchToLatest
|
|
||||||
}
|
|
||||||
|
|||||||
@ -27,8 +27,8 @@ public func peerSpecificStickerPack(postbox: Postbox, network: Network, peerId:
|
|||||||
if let info = info.info {
|
if let info = info.info {
|
||||||
return cachedStickerPack(postbox: postbox, network: network, reference: .id(id: info.id.id, accessHash: info.accessHash))
|
return cachedStickerPack(postbox: postbox, network: network, reference: .id(id: info.id.id, accessHash: info.accessHash))
|
||||||
|> map { result -> (StickerPackCollectionInfo, [ItemCollectionItem])? in
|
|> map { result -> (StickerPackCollectionInfo, [ItemCollectionItem])? in
|
||||||
if let result = result {
|
if case let .result(info, items, _) = result {
|
||||||
return (result.0, result.1)
|
return (info, items)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,24 @@ import Foundation
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
public extension Peer {
|
public extension Peer {
|
||||||
|
public func displayTitle(or defaultTitle: String) -> String {
|
||||||
|
switch self {
|
||||||
|
case let user as TelegramUser:
|
||||||
|
let name = user.name
|
||||||
|
if name.isEmpty {
|
||||||
|
return defaultTitle
|
||||||
|
} else {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
case let group as TelegramGroup:
|
||||||
|
return group.title
|
||||||
|
case let channel as TelegramChannel:
|
||||||
|
return channel.title
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public var displayTitle: String {
|
public var displayTitle: String {
|
||||||
switch self {
|
switch self {
|
||||||
case let user as TelegramUser:
|
case let user as TelegramUser:
|
||||||
|
|||||||
@ -675,6 +675,18 @@ public final class PendingMessageManager {
|
|||||||
if updatedState != state {
|
if updatedState != state {
|
||||||
modifier.setPeerChatState(message.id.peerId, state: updatedState)
|
modifier.setPeerChatState(message.id.peerId, state: updatedState)
|
||||||
}
|
}
|
||||||
|
} else if case .historyScreenshot = media.action {
|
||||||
|
sentAsAction = true
|
||||||
|
let updatedState = addSecretChatOutgoingOperation(modifier: modifier, peerId: message.id.peerId, operation: .screenshotMessages(layer: layer, actionGloballyUniqueId: message.globallyUniqueId!, globallyUniqueIds: []), state: state)
|
||||||
|
if updatedState != state {
|
||||||
|
modifier.setPeerChatState(message.id.peerId, state: updatedState)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if sentAsAction {
|
||||||
modifier.updateMessage(message.id, update: { currentMessage in
|
modifier.updateMessage(message.id, update: { currentMessage in
|
||||||
var flags = StoreMessageFlags(message.flags)
|
var flags = StoreMessageFlags(message.flags)
|
||||||
if !flags.contains(.Failed) {
|
if !flags.contains(.Failed) {
|
||||||
@ -686,12 +698,7 @@ public final class PendingMessageManager {
|
|||||||
}
|
}
|
||||||
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media))
|
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: currentMessage.timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: currentMessage.media))
|
||||||
})
|
})
|
||||||
}
|
} else {
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !sentAsAction {
|
|
||||||
let updatedState = addSecretChatOutgoingOperation(modifier: modifier, peerId: message.id.peerId, operation: .sendMessage(layer: layer, id: message.id, file: secretFile), state: state)
|
let updatedState = addSecretChatOutgoingOperation(modifier: modifier, peerId: message.id.peerId, operation: .sendMessage(layer: layer, id: message.id, file: secretFile), state: state)
|
||||||
if updatedState != state {
|
if updatedState != state {
|
||||||
modifier.setPeerChatState(message.id.peerId, state: updatedState)
|
modifier.setPeerChatState(message.id.peerId, state: updatedState)
|
||||||
|
|||||||
@ -396,7 +396,7 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, auxili
|
|||||||
} else if let resource = file.resource as? LocalFileReferenceMediaResource, let size = resource.size {
|
} else if let resource = file.resource as? LocalFileReferenceMediaResource, let size = resource.size {
|
||||||
hintSize = Int(size)
|
hintSize = Int(size)
|
||||||
}
|
}
|
||||||
if file.resource.headerSize != 0 {
|
if file.resource.headerSize != 0 && !file.isAnimated {
|
||||||
hintFileIsLarge = true
|
hintFileIsLarge = true
|
||||||
}
|
}
|
||||||
let upload = messageMediaPreuploadManager.upload(network: network, postbox: postbox, source: .resource(file.resource), encrypt: peerId.namespace == Namespaces.Peer.SecretChat, tag: TelegramMediaResourceFetchTag(statsCategory: statsCategoryForFileWithAttributes(file.attributes)), hintFileSize: hintSize, hintFileIsLarge: hintFileIsLarge)
|
let upload = messageMediaPreuploadManager.upload(network: network, postbox: postbox, source: .resource(file.resource), encrypt: peerId.namespace == Namespaces.Peer.SecretChat, tag: TelegramMediaResourceFetchTag(statsCategory: statsCategoryForFileWithAttributes(file.attributes)), hintFileSize: hintSize, hintFileIsLarge: hintFileIsLarge)
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import Foundation
|
|||||||
public func setSecretChatMessageAutoremoveTimeoutInteractively(account: Account, peerId: PeerId, timeout: Int32?) -> Signal<Void, NoError> {
|
public func setSecretChatMessageAutoremoveTimeoutInteractively(account: Account, peerId: PeerId, timeout: Int32?) -> Signal<Void, NoError> {
|
||||||
return account.postbox.modify { modifier -> Void in
|
return account.postbox.modify { modifier -> Void in
|
||||||
if let peer = modifier.getPeer(peerId) as? TelegramSecretChat, let state = modifier.getPeerChatState(peerId) as? SecretChatState {
|
if let peer = modifier.getPeer(peerId) as? TelegramSecretChat, let state = modifier.getPeerChatState(peerId) as? SecretChatState {
|
||||||
|
if state.messageAutoremoveTimeout != timeout {
|
||||||
let updatedPeer = peer.withUpdatedMessageAutoremoveTimeout(timeout)
|
let updatedPeer = peer.withUpdatedMessageAutoremoveTimeout(timeout)
|
||||||
let updatedState = state.withUpdatedMessageAutoremoveTimeout(timeout)
|
let updatedState = state.withUpdatedMessageAutoremoveTimeout(timeout)
|
||||||
if !updatedPeer.isEqual(peer) {
|
if !updatedPeer.isEqual(peer) {
|
||||||
@ -19,7 +20,16 @@ public func setSecretChatMessageAutoremoveTimeoutInteractively(account: Account,
|
|||||||
modifier.setPeerChatState(peerId, state: updatedState)
|
modifier.setPeerChatState(peerId, state: updatedState)
|
||||||
}
|
}
|
||||||
|
|
||||||
enqueueMessages(modifier: modifier, account: account, peerId: peerId, messages: [(true, .message(text: "", attributes: [], media: TelegramMediaAction(action: TelegramMediaActionType.messageAutoremoveTimeoutUpdated(timeout == nil ? 0 : timeout!)), replyToMessageId: nil, localGroupingKey: nil))])
|
let _ = enqueueMessages(modifier: modifier, account: account, peerId: peerId, messages: [(true, .message(text: "", attributes: [], media: TelegramMediaAction(action: TelegramMediaActionType.messageAutoremoveTimeoutUpdated(timeout == nil ? 0 : timeout!)), replyToMessageId: nil, localGroupingKey: nil))])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func addSecretChatMessageScreenshot(account: Account, peerId: PeerId) -> Signal<Void, NoError> {
|
||||||
|
return account.postbox.modify { modifier -> Void in
|
||||||
|
if let peer = modifier.getPeer(peerId) as? TelegramSecretChat, let state = modifier.getPeerChatState(peerId) as? SecretChatState {
|
||||||
|
let _ = enqueueMessages(modifier: modifier, account: account, peerId: peerId, messages: [(true, .message(text: "", attributes: [], media: TelegramMediaAction(action: TelegramMediaActionType.historyScreenshot), replyToMessageId: nil, localGroupingKey: nil))])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -451,7 +451,8 @@ static NSArray *GEO_MOBILE_COUNTRIES;
|
|||||||
|
|
||||||
- (NSDictionary *)DIGIT_MAPPINGS
|
- (NSDictionary *)DIGIT_MAPPINGS
|
||||||
{
|
{
|
||||||
if (!DIGIT_MAPPINGS) {
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
DIGIT_MAPPINGS = [NSDictionary dictionaryWithObjectsAndKeys:
|
DIGIT_MAPPINGS = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
@"0", @"0", @"1", @"1", @"2", @"2", @"3", @"3", @"4", @"4", @"5", @"5", @"6", @"6", @"7", @"7", @"8", @"8", @"9", @"9",
|
@"0", @"0", @"1", @"1", @"2", @"2", @"3", @"3", @"4", @"4", @"5", @"5", @"6", @"6", @"7", @"7", @"8", @"8", @"9", @"9",
|
||||||
// Fullwidth digit 0 to 9
|
// Fullwidth digit 0 to 9
|
||||||
@ -460,7 +461,7 @@ static NSArray *GEO_MOBILE_COUNTRIES;
|
|||||||
@"0", @"\u0660", @"1", @"\u0661", @"2", @"\u0662", @"3", @"\u0663", @"4", @"\u0664", @"5", @"\u0665", @"6", @"\u0666", @"7", @"\u0667", @"8", @"\u0668", @"9", @"\u0669",
|
@"0", @"\u0660", @"1", @"\u0661", @"2", @"\u0662", @"3", @"\u0663", @"4", @"\u0664", @"5", @"\u0665", @"6", @"\u0666", @"7", @"\u0667", @"8", @"\u0668", @"9", @"\u0669",
|
||||||
// Eastern-Arabic digit 0 to 9
|
// Eastern-Arabic digit 0 to 9
|
||||||
@"0", @"\u06F0", @"1", @"\u06F1", @"2", @"\u06F2", @"3", @"\u06F3", @"4", @"\u06F4", @"5", @"\u06F5", @"6", @"\u06F6", @"7", @"\u06F7", @"8", @"\u06F8", @"9", @"\u06F9", nil];
|
@"0", @"\u06F0", @"1", @"\u06F1", @"2", @"\u06F2", @"3", @"\u06F3", @"4", @"\u06F4", @"5", @"\u06F5", @"6", @"\u06F6", @"7", @"\u06F7", @"8", @"\u06F8", @"9", @"\u06F9", nil];
|
||||||
}
|
});
|
||||||
return DIGIT_MAPPINGS;
|
return DIGIT_MAPPINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user