diff --git a/submodules/TelegramApi/Sources/Api30.swift b/submodules/TelegramApi/Sources/Api30.swift index 002737c88e..30b949d28c 100644 --- a/submodules/TelegramApi/Sources/Api30.swift +++ b/submodules/TelegramApi/Sources/Api30.swift @@ -2943,14 +2943,19 @@ public extension Api.functions.communities { } } public extension Api.functions.communities { - static func editExportedInvite(flags: Int32, community: Api.InputCommunity, slug: String, title: String?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + static func editExportedInvite(flags: Int32, community: Api.InputCommunity, slug: String, title: String?, peers: [Api.InputPeer]?) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(873155725) + buffer.appendInt32(655623442) serializeInt32(flags, buffer: buffer, boxed: false) community.serialize(buffer, true) serializeString(slug, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 1) != 0 {serializeString(title!, buffer: buffer, boxed: false)} - return (FunctionDescription(name: "communities.editExportedInvite", parameters: [("flags", String(describing: flags)), ("community", String(describing: community)), ("slug", String(describing: slug)), ("title", String(describing: title))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.ExportedCommunityInvite? in + if Int(flags) & Int(1 << 2) != 0 {buffer.appendInt32(481674261) + buffer.appendInt32(Int32(peers!.count)) + for item in peers! { + item.serialize(buffer, true) + }} + return (FunctionDescription(name: "communities.editExportedInvite", parameters: [("flags", String(describing: flags)), ("community", String(describing: community)), ("slug", String(describing: slug)), ("title", String(describing: title)), ("peers", String(describing: peers))]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.ExportedCommunityInvite? in let reader = BufferReader(buffer) var result: Api.ExportedCommunityInvite? if let signature = reader.readInt32() { diff --git a/submodules/TelegramCore/Sources/State/CallSessionManager.swift b/submodules/TelegramCore/Sources/State/CallSessionManager.swift index 6251ed0950..93fd01e995 100644 --- a/submodules/TelegramCore/Sources/State/CallSessionManager.swift +++ b/submodules/TelegramCore/Sources/State/CallSessionManager.swift @@ -369,6 +369,7 @@ private final class CallSessionManagerContext { private let ringingSubscribers = Bag<([CallSessionRingingState]) -> Void>() private var contexts: [CallSessionInternalId: CallSessionContext] = [:] + private var futureContextSubscribers: [CallSessionInternalId: Bag<(CallSession) -> Void>] = [:] private var contextIdByStableId: [CallSessionStableId: CallSessionInternalId] = [:] private var enqueuedSignalingData: [Int64: [Data]] = [:] @@ -443,7 +444,10 @@ private final class CallSessionManagerContext { return Signal { [weak self] subscriber in let disposable = MetaDisposable() queue.async { - if let strongSelf = self, let context = strongSelf.contexts[internalId] { + guard let strongSelf = self else { + return + } + if let context = strongSelf.contexts[internalId] { let index = context.subscribers.add { next in subscriber.putNext(next) } @@ -459,8 +463,22 @@ private final class CallSessionManagerContext { } }) } else { - subscriber.putNext(CallSession(id: internalId, stableId: nil, isOutgoing: false, type: .audio, state: .terminated(id: nil, reason: .error(.generic), options: []), isVideoPossible: true)) - subscriber.putCompletion() + if strongSelf.futureContextSubscribers[internalId] == nil { + strongSelf.futureContextSubscribers[internalId] = Bag() + } + let index = strongSelf.futureContextSubscribers[internalId]?.add({ session in + subscriber.putNext(session) + }) + if let index = index { + disposable.set(ActionDisposable { + queue.async { + guard let strongSelf = self else { + return + } + strongSelf.futureContextSubscribers[internalId]?.remove(index) + } + }) + } } } return disposable @@ -517,6 +535,11 @@ private final class CallSessionManagerContext { for subscriber in context.subscribers.copyItems() { subscriber(session) } + if let futureSubscribers = self.futureContextSubscribers[internalId] { + for subscriber in futureSubscribers.copyItems() { + subscriber(session) + } + } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift index 8a48d13169..50f3fd57b0 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/Communities.swift @@ -84,17 +84,17 @@ func _internal_exportChatFolder(account: Account, filterId: Int32, title: String } } -func _internal_getExportedChatFolderLinks(account: Account, id: Int32) -> Signal<[ExportedChatFolderLink], NoError> { +func _internal_getExportedChatFolderLinks(account: Account, id: Int32) -> Signal<[ExportedChatFolderLink]?, NoError> { return account.network.request(Api.functions.communities.getExportedInvites(community: .inputCommunityDialogFilter(filterId: id))) |> map(Optional.init) |> `catch` { _ -> Signal in return .single(nil) } - |> mapToSignal { result -> Signal<[ExportedChatFolderLink], NoError> in + |> mapToSignal { result -> Signal<[ExportedChatFolderLink]?, NoError> in guard let result = result else { - return .single([]) + return .single(nil) } - return account.postbox.transaction { transaction -> [ExportedChatFolderLink] in + return account.postbox.transaction { transaction -> [ExportedChatFolderLink]? in switch result { case let .exportedInvites(invites, chats, users): var peers: [Peer] = [] @@ -139,19 +139,38 @@ public enum EditChatFolderLinkError { case generic } -func _internal_editChatFolderLink(account: Account, filterId: Int32, link: ExportedChatFolderLink, title: String?, revoke: Bool) -> Signal { - var flags: Int32 = 0 - if revoke { - flags |= 1 << 0 +func _internal_editChatFolderLink(account: Account, filterId: Int32, link: ExportedChatFolderLink, title: String?, peerIds: [EnginePeer.Id]?, revoke: Bool) -> Signal { + return account.postbox.transaction { transaction -> Signal in + var flags: Int32 = 0 + if revoke { + flags |= 1 << 0 + } + if title != nil { + flags |= 1 << 1 + } + var peers: [Api.InputPeer]? + if let peerIds = peerIds { + flags |= 1 << 2 + peers = peerIds.compactMap(transaction.getPeer).compactMap(apiInputPeer) + } + return account.network.request(Api.functions.communities.editExportedInvite(flags: flags, community: .inputCommunityDialogFilter(filterId: filterId), slug: link.slug, title: title, peers: peers)) + |> mapError { _ -> EditChatFolderLinkError in + return .generic + } + |> map { result in + switch result { + case let .exportedCommunityInvite(flags, title, url, peers): + return ExportedChatFolderLink( + title: title, + link: url, + peerIds: peers.map(\.peerId), + isRevoked: (flags & (1 << 0)) != 0 + ) + } + } } - if title != nil { - flags |= 1 << 1 - } - return account.network.request(Api.functions.communities.editExportedInvite(flags: flags, community: .inputCommunityDialogFilter(filterId: filterId), slug: link.slug, title: title)) - |> mapError { _ -> EditChatFolderLinkError in - return .generic - } - |> ignoreValues + |> castError(EditChatFolderLinkError.self) + |> switchToLatest } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift index 75d5d0908a..3d45daad05 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift @@ -1030,12 +1030,12 @@ public extension TelegramEngine { return _internal_exportChatFolder(account: self.account, filterId: filterId, title: title, peerIds: peerIds) } - public func getExportedChatFolderLinks(id: Int32) -> Signal<[ExportedChatFolderLink], NoError> { + public func getExportedChatFolderLinks(id: Int32) -> Signal<[ExportedChatFolderLink]?, NoError> { return _internal_getExportedChatFolderLinks(account: self.account, id: id) } - public func editChatFolderLink(filterId: Int32, link: ExportedChatFolderLink, title: String?, revoke: Bool) -> Signal { - return _internal_editChatFolderLink(account: self.account, filterId: filterId, link: link, title: title, revoke: revoke) + public func editChatFolderLink(filterId: Int32, link: ExportedChatFolderLink, title: String?, peerIds: [EnginePeer.Id]?, revoke: Bool) -> Signal { + return _internal_editChatFolderLink(account: self.account, filterId: filterId, link: link, title: title, peerIds: peerIds, revoke: revoke) } public func revokeChatFolderLink(filterId: Int32, link: ExportedChatFolderLink) -> Signal {