diff --git a/submodules/TelegramCore/Sources/InvitationLinks.swift b/submodules/TelegramCore/Sources/InvitationLinks.swift index e47f54b59c..fe7ec29f32 100644 --- a/submodules/TelegramCore/Sources/InvitationLinks.swift +++ b/submodules/TelegramCore/Sources/InvitationLinks.swift @@ -6,6 +6,54 @@ import MtProtoKit import SyncCore + +public func revokePersistentPeerExportedInvitation(account: Account, peerId: PeerId) -> Signal { + return account.postbox.transaction { transaction -> Signal in + if let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer) { + let flags: Int32 = (1 << 2) + if let _ = peer as? TelegramChannel { + return account.network.request(Api.functions.messages.exportChatInvite(flags: flags, peer: inputPeer, expireDate: nil, usageLimit: nil)) + |> retryRequest + |> mapToSignal { result -> Signal in + return account.postbox.transaction { transaction -> ExportedInvitation? in + let invitation = ExportedInvitation(apiExportedInvite: result) + transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in + if let current = current as? CachedChannelData { + return current.withUpdatedExportedInvitation(invitation) + } else { + return CachedChannelData().withUpdatedExportedInvitation(invitation) + } + }) + return invitation + + } + } + } else if let _ = peer as? TelegramGroup { + return account.network.request(Api.functions.messages.exportChatInvite(flags: flags, peer: inputPeer, expireDate: nil, usageLimit: nil)) + |> retryRequest + |> mapToSignal { result -> Signal in + return account.postbox.transaction { transaction -> ExportedInvitation? in + let invitation = ExportedInvitation(apiExportedInvite: result) + transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, current in + if let current = current as? CachedGroupData { + return current.withUpdatedExportedInvitation(invitation) + } else { + return current + } + }) + return invitation + } + } + } else { + return .complete() + } + } else { + return .complete() + } + } |> switchToLatest +} + + public enum CreatePeerExportedInvitationError { case generic }