From 1981066669cb0c08d32bedfb469969c8f54933e7 Mon Sep 17 00:00:00 2001 From: overtake Date: Tue, 5 Oct 2021 14:52:24 +0300 Subject: [PATCH] 134 layer fixes --- .../SyncCore/SyncCore_ExportedInvitation.swift | 2 +- .../TelegramEngine/Peers/InvitationLinks.swift | 3 +++ .../Sources/TelegramEngine/Peers/JoinLink.swift | 16 +++++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_ExportedInvitation.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_ExportedInvitation.swift index f73ebf5d47..10f45a0b04 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_ExportedInvitation.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_ExportedInvitation.swift @@ -32,7 +32,7 @@ public struct ExportedInvitation: Codable, Equatable { self.link = try container.decode(String.self, forKey: "l") self.isPermanent = try container.decode(Bool.self, forKey: "permanent") - self.requestApproval = (try? container.decode(Bool.self, forKey: "requestApproval")) ?? false + self.requestApproval = try container.decodeIfPresent(Bool.self, forKey: "requestApproval") ?? false self.isRevoked = try container.decode(Bool.self, forKey: "revoked") self.adminId = PeerId(try container.decode(Int64.self, forKey: "adminId")) self.date = try container.decode(Int32.self, forKey: "date") diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift index 86ae48f477..10cf078b53 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/InvitationLinks.swift @@ -81,6 +81,9 @@ func _internal_createPeerExportedInvitation(account: Account, peerId: PeerId, ex if let _ = usageLimit { flags |= (1 << 1) } + if let _ = requestNeeded { + flags |= (1 << 3) + } return account.network.request(Api.functions.messages.exportChatInvite(flags: flags, peer: inputPeer, expireDate: expireDate, usageLimit: usageLimit)) |> mapError { _ in return CreatePeerExportedInvitationError.generic } |> map { result -> ExportedInvitation? in diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinLink.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinLink.swift index 6f6fd69ab1..62aee7aebe 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinLink.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/JoinLink.swift @@ -22,7 +22,16 @@ func apiUpdatesGroups(_ updates: Api.Updates) -> [Api.Chat] { } public enum ExternalJoiningChatState { - case invite(title: String, about: String?, photoRepresentation: TelegramMediaImageRepresentation?, participantsCount: Int32, participants: [Peer]?) + + public struct InviteFlags { + public let isChannel: Bool + public let isBroadcast: Bool + public let isPublic: Bool + public let isMegagroup: Bool + public let requestNeeded: Bool + } + + case invite(flags: InviteFlags, title: String, about: String?, photoRepresentation: TelegramMediaImageRepresentation?, participantsCount: Int32, participants: [Peer]?) case alreadyJoined(PeerId) case invalidHash case peek(PeerId, Int32) @@ -67,9 +76,10 @@ func _internal_joinLinkInformation(_ hash: String, account: Account) -> Signal mapToSignal { (result) -> Signal in if let result = result { switch result { - case let .chatInvite(_, title, about, invitePhoto, participantsCount, participants): + case let .chatInvite(flags, title, about, invitePhoto, participantsCount, participants): let photo = telegramMediaImageFromApiPhoto(invitePhoto).flatMap({ smallestImageRepresentation($0.representations) }) - return .single(.invite(title: title, about: about, photoRepresentation: photo, participantsCount: participantsCount, participants: participants?.map({TelegramUser(user: $0)}))) + let flags:ExternalJoiningChatState.InviteFlags = .init(isChannel: (flags & (1 << 0)) != 0, isBroadcast: (flags & (1 << 1)) != 0, isPublic: (flags & (1 << 2)) != 0, isMegagroup: (flags & (1 << 3)) != 0, requestNeeded: (flags & (1 << 6)) != 0) + return .single(.invite(flags: flags, title: title, about: about, photoRepresentation: photo, participantsCount: participantsCount, participants: participants?.map({TelegramUser(user: $0)}))) case let .chatInviteAlready(chat): if let peer = parseTelegramGroupOrChannel(chat: chat) { return account.postbox.transaction({ (transaction) -> ExternalJoiningChatState in