mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Refactoring
This commit is contained in:
@@ -3,14 +3,11 @@ import Postbox
|
||||
import TelegramApi
|
||||
import SwiftSignalKit
|
||||
|
||||
|
||||
public enum RecentPeers {
|
||||
case peers([Peer])
|
||||
case disabled
|
||||
}
|
||||
|
||||
private let collectionSpec = ItemCacheCollectionSpec(lowWaterItemCount: 1, highWaterItemCount: 1)
|
||||
|
||||
private func cachedRecentPeersEntryId() -> ItemCacheEntryId {
|
||||
return ItemCacheEntryId(collectionId: 101, key: CachedRecentPeers.cacheKey())
|
||||
}
|
||||
@@ -82,13 +79,13 @@ func _internal_managedUpdatedRecentPeers(accountPeerId: PeerId, postbox: Postbox
|
||||
updatePeerPresences(transaction: transaction, accountPeerId: accountPeerId, peerPresences: peerPresences)
|
||||
|
||||
if let entry = CodableEntry(CachedRecentPeers(enabled: true, ids: peers.map { $0.id })) {
|
||||
transaction.putItemCacheEntry(id: cachedRecentPeersEntryId(), entry: entry, collectionSpec: collectionSpec)
|
||||
transaction.putItemCacheEntry(id: cachedRecentPeersEntryId(), entry: entry)
|
||||
}
|
||||
case .topPeersNotModified:
|
||||
break
|
||||
case .topPeersDisabled:
|
||||
if let entry = CodableEntry(CachedRecentPeers(enabled: false, ids: [])) {
|
||||
transaction.putItemCacheEntry(id: cachedRecentPeersEntryId(), entry: entry, collectionSpec: collectionSpec)
|
||||
transaction.putItemCacheEntry(id: cachedRecentPeersEntryId(), entry: entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,7 +106,7 @@ func _internal_removeRecentPeer(account: Account, peerId: PeerId) -> Signal<Void
|
||||
var updatedIds = entry.ids
|
||||
updatedIds.remove(at: index)
|
||||
if let entry = CodableEntry(CachedRecentPeers(enabled: entry.enabled, ids: updatedIds)) {
|
||||
transaction.putItemCacheEntry(id: cachedRecentPeersEntryId(), entry: entry, collectionSpec: collectionSpec)
|
||||
transaction.putItemCacheEntry(id: cachedRecentPeersEntryId(), entry: entry)
|
||||
}
|
||||
}
|
||||
if let peer = transaction.getPeer(peerId), let apiPeer = apiInputPeer(peer) {
|
||||
@@ -145,12 +142,12 @@ func _internal_updateRecentPeersEnabled(postbox: Postbox, network: Network, enab
|
||||
return postbox.transaction { transaction -> Void in
|
||||
if !enabled {
|
||||
if let entry = CodableEntry(CachedRecentPeers(enabled: false, ids: [])) {
|
||||
transaction.putItemCacheEntry(id: cachedRecentPeersEntryId(), entry: entry, collectionSpec: collectionSpec)
|
||||
transaction.putItemCacheEntry(id: cachedRecentPeersEntryId(), entry: entry)
|
||||
}
|
||||
} else {
|
||||
let entry = transaction.retrieveItemCacheEntry(id: cachedRecentPeersEntryId())?.get(CachedRecentPeers.self)
|
||||
if let codableEntry = CodableEntry(CachedRecentPeers(enabled: true, ids: entry?.ids ?? [])) {
|
||||
transaction.putItemCacheEntry(id: cachedRecentPeersEntryId(), entry: codableEntry, collectionSpec: collectionSpec)
|
||||
transaction.putItemCacheEntry(id: cachedRecentPeersEntryId(), entry: codableEntry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user