From 176eaa451fd5598501c1218862451bcd512a2c26 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 19 Jan 2021 12:45:47 +0300 Subject: [PATCH] Invite Links Fixes --- .../Sources/ChannelVisibilityController.swift | 16 +++++++++ .../Sources/PeerInfo/PeerInfoData.swift | 36 +++++++++++++------ .../Sources/PeerInfo/PeerInfoScreen.swift | 11 ++++++ 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift index 9aafcea03a..f9813a785d 100644 --- a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift @@ -595,9 +595,25 @@ private func channelVisibilityControllerEntries(presentationData: PresentationDa } else { entries.append(.publicLinkInfo(presentationData.theme, presentationData.strings.Group_Username_CreatePublicLinkHelp)) } + + switch mode { + case .initialSetup: + break + case .generic, .privateLink: + entries.append(.privateLinkManage(presentationData.theme, presentationData.strings.InviteLink_Manage)) + entries.append(.privateLinkManageInfo(presentationData.theme, presentationData.strings.InviteLink_CreateInfo)) + } + } else { entries.append(.publicLinkInfo(presentationData.theme, presentationData.strings.Channel_Username_CreatePublicLinkHelp)) } + switch mode { + case .initialSetup: + break + case .generic, .privateLink: + entries.append(.privateLinkManage(presentationData.theme, presentationData.strings.InviteLink_Manage)) + entries.append(.privateLinkManageInfo(presentationData.theme, presentationData.strings.InviteLink_CreateInfo)) + } } case .privateChannel: let invite = (view.cachedData as? CachedChannelData)?.exportedInvitation diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoData.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoData.swift index c577f430d7..bc3b669911 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoData.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoData.swift @@ -615,7 +615,7 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen case .channel: let status = context.account.viewTracker.peerView(peerId, updateData: false) |> map { peerView -> PeerInfoStatusData? in - guard let channel = peerView.peers[peerId] as? TelegramChannel else { + guard let _ = peerView.peers[peerId] as? TelegramChannel else { return PeerInfoStatusData(text: strings.Channel_Status, isActivity: false) } if let cachedChannelData = peerView.cachedData as? CachedChannelData, let memberCount = cachedChannelData.participantsSummary.memberCount, memberCount != 0 { @@ -654,12 +654,18 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen discussionPeer = peer } - if let channel = peerViewMainPeer(peerView) as? TelegramChannel, let cachedData = peerView.cachedData as? CachedChannelData, channel.flags.contains(.isCreator) || ((channel.adminRights != nil && channel.hasPermission(.pinMessages)) && cachedData.flags.contains(.canChangeUsername)), currentInvitationsContext == nil { - let invitationsContext = PeerExportedInvitationsContext(account: context.account, peerId: peerId, revoked: false, forceUpdate: true) - invitationsContextPromise.set(.single(invitationsContext)) - invitationsStatePromise.set(invitationsContext.state |> map(Optional.init)) + if currentInvitationsContext == nil { + var canManageInvitations = false + if let channel = peerViewMainPeer(peerView) as? TelegramChannel, let cachedData = peerView.cachedData as? CachedChannelData, channel.flags.contains(.isCreator) || ((channel.adminRights != nil && channel.hasPermission(.pinMessages)) && cachedData.flags.contains(.canChangeUsername)) { + canManageInvitations = true + } + if canManageInvitations { + let invitationsContext = PeerExportedInvitationsContext(account: context.account, peerId: peerId, revoked: false, forceUpdate: true) + invitationsContextPromise.set(.single(invitationsContext)) + invitationsStatePromise.set(invitationsContext.state |> map(Optional.init)) + } } - + return PeerInfoScreenData( peer: peerView.peers[peerId], cachedData: peerView.cachedData, @@ -805,12 +811,20 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen } } - if let group = peerViewMainPeer(peerView) as? TelegramGroup, case .creator = group.role, currentInvitationsContext == nil { - let invitationsContext = PeerExportedInvitationsContext(account: context.account, peerId: peerId, revoked: false, forceUpdate: true) - invitationsContextPromise.set(.single(invitationsContext)) - invitationsStatePromise.set(invitationsContext.state |> map(Optional.init)) + if currentInvitationsContext == nil { + var canManageInvitations = false + if let group = peerViewMainPeer(peerView) as? TelegramGroup, case .creator = group.role { + canManageInvitations = true + } else if let channel = peerViewMainPeer(peerView) as? TelegramChannel, let cachedData = peerView.cachedData as? CachedChannelData, channel.flags.contains(.isCreator) || ((channel.adminRights != nil && channel.hasPermission(.pinMessages)) && cachedData.flags.contains(.canChangeUsername)) { + canManageInvitations = true + } + if canManageInvitations { + let invitationsContext = PeerExportedInvitationsContext(account: context.account, peerId: peerId, revoked: false, forceUpdate: true) + invitationsContextPromise.set(.single(invitationsContext)) + invitationsStatePromise.set(invitationsContext.state |> map(Optional.init)) + } } - + return PeerInfoScreenData( peer: peerView.peers[groupId], cachedData: peerView.cachedData, diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index 633fff9cc6..073a5feeda 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -1185,6 +1185,17 @@ private func editingItems(data: PeerInfoScreenData?, context: AccountContext, pr discussionGroupTitle = "..." } + let invitesText: String + if let count = data.invitations?.count, count > 0 { + invitesText = "\(count)" + } else { + invitesText = "" + } + + items[.peerSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemInviteLinks, label: .text(invitesText), text: presentationData.strings.GroupInfo_InviteLinks, action: { + interaction.editingOpenInviteLinksSetup() + })) + items[.peerSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemDiscussionGroup, label: .text(discussionGroupTitle), text: presentationData.strings.Channel_DiscussionGroup, action: { interaction.editingOpenDiscussionGroupSetup() }))