mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Refactoring
This commit is contained in:
@@ -3,10 +3,13 @@ import Postbox
|
||||
|
||||
public extension TelegramEngine.EngineData.Item {
|
||||
enum Peer {
|
||||
public struct Peer: TelegramEngineDataItem, PostboxViewDataItem {
|
||||
public struct Peer: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem {
|
||||
public typealias Result = Optional<EnginePeer>
|
||||
|
||||
fileprivate var id: EnginePeer.Id
|
||||
public var mapKey: EnginePeer.Id {
|
||||
return self.id
|
||||
}
|
||||
|
||||
public init(id: EnginePeer.Id) {
|
||||
self.id = id
|
||||
@@ -27,10 +30,108 @@ public extension TelegramEngine.EngineData.Item {
|
||||
}
|
||||
}
|
||||
|
||||
public struct RenderedPeer: TelegramEngineDataItem, PostboxViewDataItem {
|
||||
public typealias Result = Optional<EngineRenderedPeer>
|
||||
|
||||
fileprivate var id: EnginePeer.Id
|
||||
public var mapKey: EnginePeer.Id {
|
||||
return self.id
|
||||
}
|
||||
|
||||
public init(id: EnginePeer.Id) {
|
||||
self.id = id
|
||||
}
|
||||
|
||||
var key: PostboxViewKey {
|
||||
return .peer(peerId: self.id, components: [])
|
||||
}
|
||||
|
||||
func extract(view: PostboxView) -> Result {
|
||||
guard let view = view as? PeerView else {
|
||||
preconditionFailure()
|
||||
}
|
||||
var peers: [EnginePeer.Id: EnginePeer] = [:]
|
||||
guard let peer = view.peers[self.id] else {
|
||||
return nil
|
||||
}
|
||||
peers[peer.id] = EnginePeer(peer)
|
||||
|
||||
if let secretChat = peer as? TelegramSecretChat {
|
||||
guard let mainPeer = view.peers[secretChat.regularPeerId] else {
|
||||
return nil
|
||||
}
|
||||
peers[mainPeer.id] = EnginePeer(mainPeer)
|
||||
}
|
||||
|
||||
return EngineRenderedPeer(peerId: self.id, peers: peers)
|
||||
}
|
||||
}
|
||||
|
||||
public struct Presence: TelegramEngineDataItem, PostboxViewDataItem {
|
||||
public typealias Result = Optional<EnginePeer.Presence>
|
||||
|
||||
fileprivate var id: EnginePeer.Id
|
||||
public var mapKey: EnginePeer.Id {
|
||||
return self.id
|
||||
}
|
||||
|
||||
public init(id: EnginePeer.Id) {
|
||||
self.id = id
|
||||
}
|
||||
|
||||
var key: PostboxViewKey {
|
||||
return .peer(peerId: self.id, components: [])
|
||||
}
|
||||
|
||||
func extract(view: PostboxView) -> Result {
|
||||
guard let view = view as? PeerView else {
|
||||
preconditionFailure()
|
||||
}
|
||||
var presencePeerId = self.id
|
||||
if let secretChat = view.peers[self.id] as? TelegramSecretChat {
|
||||
presencePeerId = secretChat.regularPeerId
|
||||
}
|
||||
guard let presence = view.peerPresences[presencePeerId] else {
|
||||
return nil
|
||||
}
|
||||
return EnginePeer.Presence(presence)
|
||||
}
|
||||
}
|
||||
|
||||
public struct NotificationSettings: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem {
|
||||
public typealias Result = Optional<EnginePeer.NotificationSettings>
|
||||
|
||||
fileprivate var id: EnginePeer.Id
|
||||
public var mapKey: EnginePeer.Id {
|
||||
return self.id
|
||||
}
|
||||
|
||||
public init(id: EnginePeer.Id) {
|
||||
self.id = id
|
||||
}
|
||||
|
||||
var key: PostboxViewKey {
|
||||
return .peer(peerId: self.id, components: [])
|
||||
}
|
||||
|
||||
func extract(view: PostboxView) -> Result {
|
||||
guard let view = view as? PeerView else {
|
||||
preconditionFailure()
|
||||
}
|
||||
guard let notificationSettings = view.notificationSettings as? TelegramPeerNotificationSettings else {
|
||||
return nil
|
||||
}
|
||||
return EnginePeer.NotificationSettings(notificationSettings)
|
||||
}
|
||||
}
|
||||
|
||||
public struct ParticipantCount: TelegramEngineDataItem, PostboxViewDataItem {
|
||||
public typealias Result = Optional<Int>
|
||||
|
||||
fileprivate var id: EnginePeer.Id
|
||||
public var mapKey: EnginePeer.Id {
|
||||
return self.id
|
||||
}
|
||||
|
||||
public init(id: EnginePeer.Id) {
|
||||
self.id = id
|
||||
@@ -62,6 +163,9 @@ public extension TelegramEngine.EngineData.Item {
|
||||
public typealias Result = Optional<EngineGroupCallDescription>
|
||||
|
||||
fileprivate var id: EnginePeer.Id
|
||||
public var mapKey: EnginePeer.Id {
|
||||
return self.id
|
||||
}
|
||||
|
||||
public init(id: EnginePeer.Id) {
|
||||
self.id = id
|
||||
|
||||
Reference in New Issue
Block a user