diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift index 10cf078b53..d702b6ad2a 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift @@ -4,7 +4,7 @@ import SwiftSignalKit import TelegramApi import MtProtoKit -func _internal_updateInvitationRequest(account: Account, peerId: PeerId, userId: PeerId, approve: Bool) -> Signal { +private func _internal_updateInvitationRequest(account: Account, peerId: PeerId, userId: PeerId, approve: Bool) -> Signal { return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId), let user = transaction.getPeer(userId), let inputPeer = apiInputPeer(peer), let inputUser = apiInputUser(user) { var flags: Int32 = 0 @@ -719,6 +719,7 @@ private final class PeerInvitationImportersContextImpl { private let link: String? private let disposable = MetaDisposable() private let updateDisposable = MetaDisposable() + private let actionDisposables = DisposableSet() private var isLoadingMore: Bool = false private var hasLoadedOnce: Bool = false private var canLoadMore: Bool = true @@ -739,9 +740,9 @@ private final class PeerInvitationImportersContextImpl { self.count = count self.isLoadingMore = true - self.disposable.set((account.postbox.transaction { transaction -> (peers: [PeerInvitationImportersState.Importer], canLoadMore: Bool)? in + self.disposable.set((account.postbox.transaction { transaction -> (peers: [PeerInvitationImportersState.Importer], count: Int32, canLoadMore: Bool)? in let cachedResult = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedPeerInvitationImporters, key: CachedPeerInvitationImporters.key(peerId: peerId, link: invite?.link ?? "requests")))?.get(CachedPeerInvitationImporters.self) - if let cachedResult = cachedResult, Int(cachedResult.count) == count { + if let cachedResult = cachedResult, (Int(cachedResult.count) == count || invite == nil) { var result: [PeerInvitationImportersState.Importer] = [] for peerId in cachedResult.peerIds { if let peer = transaction.getPeer(peerId), let date = cachedResult.dates[peerId] { @@ -750,18 +751,19 @@ private final class PeerInvitationImportersContextImpl { return nil } } - return (result, Int(cachedResult.count) > result.count) + return (result, cachedResult.count, Int(cachedResult.count) > result.count || invite == nil) } else { return nil } } - |> deliverOn(self.queue)).start(next: { [weak self] cachedPeersAndCanLoadMore in + |> deliverOn(self.queue)).start(next: { [weak self] cachedPeersCountAndCanLoadMore in guard let strongSelf = self else { return } strongSelf.isLoadingMore = false - if let (cachedPeers, canLoadMore) = cachedPeersAndCanLoadMore { + if let (cachedPeers, cachedCount, canLoadMore) = cachedPeersCountAndCanLoadMore { strongSelf.results = cachedPeers + strongSelf.count = cachedCount strongSelf.hasLoadedOnce = true strongSelf.canLoadMore = canLoadMore strongSelf.loadedFromCache = true @@ -775,6 +777,7 @@ private final class PeerInvitationImportersContextImpl { deinit { self.disposable.dispose() self.updateDisposable.dispose() + self.actionDisposables.dispose() } func loadMore() { @@ -884,7 +887,9 @@ private final class PeerInvitationImportersContextImpl { self.updateState() } - func remove(_ peerId: EnginePeer.Id) { + func update(_ peerId: EnginePeer.Id, action: PeerInvitationImportersContext.UpdateAction) { + self.actionDisposables.add(_internal_updateInvitationRequest(account: self.account, peerId: self.peerId, userId: peerId, approve: action == .approve).start()) + var results = self.results results.removeAll(where: { $0.peer.peerId == peerId}) self.results = results @@ -914,6 +919,11 @@ private final class PeerInvitationImportersContextImpl { } public final class PeerInvitationImportersContext { + public enum UpdateAction { + case approve + case deny + } + private let queue: Queue = Queue() private let impl: QueueLocalObject @@ -942,9 +952,9 @@ public final class PeerInvitationImportersContext { } } - public func remove(_ peerId: EnginePeer.Id) { + public func update(_ peerId: EnginePeer.Id, action: UpdateAction) { self.impl.with { impl in - impl.remove(peerId) + impl.update(peerId, action: action) } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinLink.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinLink.swift index 1e2c594e3a..6ee6178feb 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinLink.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinLink.swift @@ -22,7 +22,6 @@ func apiUpdatesGroups(_ updates: Api.Updates) -> [Api.Chat] { } public enum ExternalJoiningChatState { - public struct InviteFlags : Equatable { public let isChannel: Bool public let isBroadcast: Bool diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift index 8623f813b7..a9bc529b64 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift @@ -450,10 +450,6 @@ public extension TelegramEngine { return PeerExportedInvitationsContext(account: self.account, peerId: peerId, adminId: adminId, revoked: revoked, forceUpdate: forceUpdate) } - public func updateInvitationRequest(peerId: PeerId, userId: PeerId, approve: Bool) -> Signal { - return _internal_updateInvitationRequest(account: self.account, peerId: peerId, userId: userId, approve: approve) - } - public func revokePersistentPeerExportedInvitation(peerId: PeerId) -> Signal { return _internal_revokePersistentPeerExportedInvitation(account: self.account, peerId: peerId) }