mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Frozen account improvements
This commit is contained in:
@@ -445,9 +445,12 @@ private func _internal_requestStarsSubscriptions(account: Account, peerId: Engin
|
||||
flags |= (1 << 0)
|
||||
}
|
||||
return account.network.request(Api.functions.payments.getStarsSubscriptions(flags: flags, peer: inputPeer, offset: offset))
|
||||
|> retryRequest
|
||||
|> retryRequestIfNotFrozen
|
||||
|> castError(RequestStarsSubscriptionsError.self)
|
||||
|> mapToSignal { result -> Signal<InternalStarsStatus, RequestStarsSubscriptionsError> in
|
||||
guard let result else {
|
||||
return .single(InternalStarsStatus(balance: .zero, subscriptionsMissingBalance: nil, subscriptions: [], nextSubscriptionsOffset: nil, transactions: [], nextTransactionsOffset: nil))
|
||||
}
|
||||
return account.postbox.transaction { transaction -> InternalStarsStatus in
|
||||
switch result {
|
||||
case let .starsStatus(_, balance, subscriptions, subscriptionsNextOffset, subscriptionsMissingBalance, _, _, chats, users):
|
||||
|
||||
@@ -548,8 +548,11 @@ func _internal_adminedPublicChannels(account: Account, scope: AdminedPublicChann
|
||||
let accountPeerId = account.peerId
|
||||
|
||||
return account.network.request(Api.functions.channels.getAdminedPublicChannels(flags: flags))
|
||||
|> retryRequest
|
||||
|> retryRequestIfNotFrozen
|
||||
|> mapToSignal { result -> Signal<[TelegramAdminedPublicChannel], NoError> in
|
||||
guard let result else {
|
||||
return .single([])
|
||||
}
|
||||
return account.postbox.transaction { transaction -> [TelegramAdminedPublicChannel] in
|
||||
let chats: [Api.Chat]
|
||||
var subscriberCounts: [PeerId: Int] = [:]
|
||||
@@ -675,8 +678,11 @@ func _internal_channelsForPublicReaction(account: Account, useLocalCache: Bool)
|
||||
}
|
||||
|> mapToSignal { cachedPeers in
|
||||
let remote: Signal<[Peer], NoError> = account.network.request(Api.functions.channels.getAdminedPublicChannels(flags: 0))
|
||||
|> retryRequest
|
||||
|> retryRequestIfNotFrozen
|
||||
|> mapToSignal { result -> Signal<[Peer], NoError> in
|
||||
guard let result else {
|
||||
return .single([])
|
||||
}
|
||||
return account.postbox.transaction { transaction -> [Peer] in
|
||||
let chats: [Api.Chat]
|
||||
let parsedPeers: AccumulatedPeers
|
||||
|
||||
@@ -84,35 +84,38 @@ func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId:
|
||||
}
|
||||
}
|
||||
return network.request(Api.functions.channels.getParticipants(channel: inputChannel, filter: apiFilter, offset: offset, limit: limit, hash: hash))
|
||||
|> retryRequest
|
||||
|> mapToSignal { result -> Signal<[RenderedChannelParticipant]?, NoError> in
|
||||
return postbox.transaction { transaction -> [RenderedChannelParticipant]? in
|
||||
var items: [RenderedChannelParticipant] = []
|
||||
switch result {
|
||||
case let .channelParticipants(_, participants, chats, users):
|
||||
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
|
||||
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
|
||||
var peers: [PeerId: Peer] = [:]
|
||||
for id in parsedPeers.allIds {
|
||||
if let peer = transaction.getPeer(id) {
|
||||
peers[peer.id] = peer
|
||||
}
|
||||
|> retryRequestIfNotFrozen
|
||||
|> mapToSignal { result -> Signal<[RenderedChannelParticipant]?, NoError> in
|
||||
guard let result else {
|
||||
return .single(nil)
|
||||
}
|
||||
return postbox.transaction { transaction -> [RenderedChannelParticipant]? in
|
||||
var items: [RenderedChannelParticipant] = []
|
||||
switch result {
|
||||
case let .channelParticipants(_, participants, chats, users):
|
||||
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
|
||||
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
|
||||
var peers: [PeerId: Peer] = [:]
|
||||
for id in parsedPeers.allIds {
|
||||
if let peer = transaction.getPeer(id) {
|
||||
peers[peer.id] = peer
|
||||
}
|
||||
|
||||
for participant in CachedChannelParticipants(apiParticipants: participants).participants {
|
||||
if let peer = parsedPeers.get(participant.peerId) {
|
||||
var renderedPresences: [PeerId: PeerPresence] = [:]
|
||||
if let presence = transaction.getPeerPresence(peerId: participant.peerId) {
|
||||
renderedPresences[participant.peerId] = presence
|
||||
}
|
||||
items.append(RenderedChannelParticipant(participant: participant, peer: peer, peers: peers, presences: renderedPresences))
|
||||
}
|
||||
|
||||
for participant in CachedChannelParticipants(apiParticipants: participants).participants {
|
||||
if let peer = parsedPeers.get(participant.peerId) {
|
||||
var renderedPresences: [PeerId: PeerPresence] = [:]
|
||||
if let presence = transaction.getPeerPresence(peerId: participant.peerId) {
|
||||
renderedPresences[participant.peerId] = presence
|
||||
}
|
||||
items.append(RenderedChannelParticipant(participant: participant, peer: peer, peers: peers, presences: renderedPresences))
|
||||
}
|
||||
case .channelParticipantsNotModified:
|
||||
return nil
|
||||
}
|
||||
return items
|
||||
}
|
||||
case .channelParticipantsNotModified:
|
||||
return nil
|
||||
}
|
||||
return items
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return .single([])
|
||||
|
||||
@@ -27,8 +27,11 @@ func _internal_notificationExceptionsList(accountPeerId: PeerId, postbox: Postbo
|
||||
}
|
||||
|
||||
return network.request(Api.functions.account.getNotifyExceptions(flags: flags, peer: nil))
|
||||
|> retryRequest
|
||||
|> retryRequestIfNotFrozen
|
||||
|> mapToSignal { result -> Signal<NotificationExceptionsList, NoError> in
|
||||
guard let result else {
|
||||
return .single(NotificationExceptionsList(peers: [:], settings: [:]))
|
||||
}
|
||||
return postbox.transaction { transaction -> NotificationExceptionsList in
|
||||
switch result {
|
||||
case let .updates(updates, users, chats, _, _):
|
||||
|
||||
@@ -76,8 +76,11 @@ func fetchAndUpdateSupplementalCachedPeerData(peerId rawPeerId: PeerId, accountP
|
||||
}
|
||||
} else if let inputPeer = apiInputPeer(peer) {
|
||||
return network.request(Api.functions.messages.getPeerSettings(peer: inputPeer))
|
||||
|> retryRequest
|
||||
|> retryRequestIfNotFrozen
|
||||
|> mapToSignal { peerSettings -> Signal<Bool, NoError> in
|
||||
guard let peerSettings else {
|
||||
return .single(false)
|
||||
}
|
||||
return postbox.transaction { transaction -> Bool in
|
||||
let parsedPeers: AccumulatedPeers
|
||||
|
||||
@@ -454,8 +457,11 @@ func _internal_fetchAndUpdateCachedPeerData(accountPeerId: PeerId, peerId rawPee
|
||||
}
|
||||
} else if peerId.namespace == Namespaces.Peer.CloudGroup {
|
||||
return network.request(Api.functions.messages.getFullChat(chatId: peerId.id._internalGetInt64Value()))
|
||||
|> retryRequest
|
||||
|> retryRequestIfNotFrozen
|
||||
|> mapToSignal { result -> Signal<Bool, NoError> in
|
||||
guard let result else {
|
||||
return .single(false)
|
||||
}
|
||||
return postbox.transaction { transaction -> Bool in
|
||||
switch result {
|
||||
case let .chatFull(fullChat, chats, users):
|
||||
|
||||
@@ -78,8 +78,11 @@ public final class BlockedPeersContext {
|
||||
}
|
||||
|
||||
self.disposable.set((self.account.network.request(Api.functions.contacts.getBlocked(flags: flags, offset: Int32(self._state.peers.count), limit: limit))
|
||||
|> retryRequest
|
||||
|> retryRequestIfNotFrozen
|
||||
|> mapToSignal { result -> Signal<(peers: [RenderedPeer], canLoadMore: Bool, totalCount: Int?), NoError> in
|
||||
guard let result else {
|
||||
return .single((peers: [], canLoadMore: false, totalCount: 0))
|
||||
}
|
||||
return postbox.transaction { transaction -> (peers: [RenderedPeer], canLoadMore: Bool, totalCount: Int?) in
|
||||
switch result {
|
||||
case let .blocked(blocked, chats, users):
|
||||
|
||||
@@ -34,8 +34,11 @@ public final class ChatThemes: Codable, Equatable {
|
||||
func _internal_getChatThemes(accountManager: AccountManager<TelegramAccountManagerTypes>, network: Network, forceUpdate: Bool = false, onlyCached: Bool = false) -> Signal<[TelegramTheme], NoError> {
|
||||
let fetch: ([TelegramTheme]?, Int64?) -> Signal<[TelegramTheme], NoError> = { current, hash in
|
||||
return network.request(Api.functions.account.getChatThemes(hash: hash ?? 0))
|
||||
|> retryRequest
|
||||
|> retryRequestIfNotFrozen
|
||||
|> mapToSignal { result -> Signal<[TelegramTheme], NoError> in
|
||||
guard let result else {
|
||||
return .complete()
|
||||
}
|
||||
switch result {
|
||||
case let .themes(hash, apiThemes):
|
||||
let result = apiThemes.compactMap { TelegramTheme(apiTheme: $0) }
|
||||
|
||||
Reference in New Issue
Block a user