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,6 +3,11 @@ import Postbox
|
||||
import TelegramApi
|
||||
import MtProtoKit
|
||||
|
||||
public enum TelegramEngineAuthorizationState {
|
||||
case unauthorized(UnauthorizedAccountState)
|
||||
case authorized
|
||||
}
|
||||
|
||||
public extension TelegramEngineUnauthorized {
|
||||
final class Auth {
|
||||
private let account: UnauthorizedAccount
|
||||
@@ -43,6 +48,19 @@ public extension TelegramEngineUnauthorized {
|
||||
return _internal_uploadedPeerVideo(postbox: self.account.postbox, network: self.account.network, messageMediaPreuploadManager: nil, resource: resource)
|
||||
}
|
||||
|
||||
public func state() -> Signal<TelegramEngineAuthorizationState?, NoError> {
|
||||
return self.account.postbox.stateView()
|
||||
|> map { view -> TelegramEngineAuthorizationState? in
|
||||
if let state = view.state as? UnauthorizedAccountState {
|
||||
return .unauthorized(state)
|
||||
} else if let _ = view.state as? AuthorizedAccountState {
|
||||
return .authorized
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func setState(state: UnauthorizedAccountState) -> Signal<Never, NoError> {
|
||||
return self.account.postbox.transaction { transaction -> Void in
|
||||
transaction.setState(state)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import SwiftSignalKit
|
||||
import Postbox
|
||||
|
||||
public extension TelegramEngine.EngineData.Item {
|
||||
enum ChatList {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,9 @@ public final class EngineTotalReadCounters {
|
||||
}
|
||||
|
||||
public struct EnginePeerReadCounters: Equatable {
|
||||
private let state: CombinedPeerReadState
|
||||
private let state: CombinedPeerReadState?
|
||||
|
||||
public init(state: CombinedPeerReadState) {
|
||||
public init(state: CombinedPeerReadState?) {
|
||||
self.state = state
|
||||
}
|
||||
|
||||
@@ -25,24 +25,38 @@ public struct EnginePeerReadCounters: Equatable {
|
||||
}
|
||||
|
||||
public var count: Int32 {
|
||||
return self.state.count
|
||||
guard let state = self.state else {
|
||||
return 0
|
||||
}
|
||||
return state.count
|
||||
}
|
||||
|
||||
public var markedUnread: Bool {
|
||||
return self.state.markedUnread
|
||||
guard let state = self.state else {
|
||||
return false
|
||||
}
|
||||
return state.markedUnread
|
||||
}
|
||||
|
||||
|
||||
public var isUnread: Bool {
|
||||
return self.state.isUnread
|
||||
guard let state = self.state else {
|
||||
return false
|
||||
}
|
||||
return state.isUnread
|
||||
}
|
||||
|
||||
public func isOutgoingMessageIndexRead(_ index: EngineMessage.Index) -> Bool {
|
||||
return self.state.isOutgoingMessageIndexRead(index)
|
||||
guard let state = self.state else {
|
||||
return false
|
||||
}
|
||||
return state.isOutgoingMessageIndexRead(index)
|
||||
}
|
||||
|
||||
public func isIncomingMessageIndexRead(_ index: EngineMessage.Index) -> Bool {
|
||||
return self.state.isIncomingMessageIndexRead(index)
|
||||
guard let state = self.state else {
|
||||
return false
|
||||
}
|
||||
return state.isIncomingMessageIndexRead(index)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,8 +142,8 @@ public extension TelegramEngine.EngineData.Item {
|
||||
}
|
||||
}
|
||||
|
||||
public struct ReadState: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem {
|
||||
public typealias Result = CombinedPeerReadState?
|
||||
public struct PeerReadCounters: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem {
|
||||
public typealias Result = EnginePeerReadCounters
|
||||
|
||||
fileprivate let id: EnginePeer.Id
|
||||
public var mapKey: EnginePeer.Id {
|
||||
@@ -149,7 +163,7 @@ public extension TelegramEngine.EngineData.Item {
|
||||
preconditionFailure()
|
||||
}
|
||||
|
||||
return view.state
|
||||
return EnginePeerReadCounters(state: view.state)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import SwiftSignalKit
|
||||
import Postbox
|
||||
|
||||
public extension TelegramEngine.EngineData.Item {
|
||||
enum OrderedLists {
|
||||
public struct ListItems: TelegramEngineDataItem, PostboxViewDataItem {
|
||||
public typealias Result = [OrderedItemListEntry]
|
||||
|
||||
private let collectionId: Int32
|
||||
|
||||
public init(collectionId: Int32) {
|
||||
self.collectionId = collectionId
|
||||
}
|
||||
|
||||
var key: PostboxViewKey {
|
||||
return .orderedItemList(id: self.collectionId)
|
||||
}
|
||||
|
||||
func extract(view: PostboxView) -> Result {
|
||||
guard let view = view as? OrderedItemListView else {
|
||||
preconditionFailure()
|
||||
}
|
||||
return view.items
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user