From 6c5ea185d178fa076d5df6a771f29ffd81e948de Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 16 Feb 2021 14:16:02 +0400 Subject: [PATCH] Invite Links Improvements --- .../Sources/InviteLinkEditController.swift | 2 +- .../ItemListPermanentInviteLinkItem.swift | 9 ++- .../Items/ItemListSingleLineInputItem.swift | 2 +- .../TelegramCore/Sources/Suggestions.swift | 14 +++- .../GroupLinksIcon.imageset/Contents.json | 2 +- .../{Links.pdf => Links (1).pdf} | Bin 4127 -> 4127 bytes .../TelegramUI/Sources/ChatController.swift | 4 + .../Sources/PeerInfo/PeerInfoScreen.swift | 74 +++++++++--------- 8 files changed, 65 insertions(+), 42 deletions(-) rename submodules/TelegramUI/Images.xcassets/Chat/Info/GroupLinksIcon.imageset/{Links.pdf => Links (1).pdf} (76%) diff --git a/submodules/InviteLinksUI/Sources/InviteLinkEditController.swift b/submodules/InviteLinksUI/Sources/InviteLinkEditController.swift index 2eca3cb7c9..ed8300ce7c 100644 --- a/submodules/InviteLinksUI/Sources/InviteLinkEditController.swift +++ b/submodules/InviteLinksUI/Sources/InviteLinkEditController.swift @@ -44,7 +44,7 @@ func isValidNumberOfUsers(_ number: String) -> Bool { if number.rangeOfCharacter(from: invalidAmountCharacters) != nil || number == "0" { return false } - if let _ = Int32(number) { + if let value = Int32(number), value > 0 && value < 100000 { return true } else { return false diff --git a/submodules/InviteLinksUI/Sources/ItemListPermanentInviteLinkItem.swift b/submodules/InviteLinksUI/Sources/ItemListPermanentInviteLinkItem.swift index 86392432ba..383226a612 100644 --- a/submodules/InviteLinksUI/Sources/ItemListPermanentInviteLinkItem.swift +++ b/submodules/InviteLinksUI/Sources/ItemListPermanentInviteLinkItem.swift @@ -295,9 +295,14 @@ public class ItemListPermanentInviteLinkItemNode: ListViewItemNode, ItemListItem let titleColor: UIColor titleColor = item.presentationData.theme.list.itemInputField.primaryColor + let alignCentrally = !(item.invite?.link.contains("joinchat") ?? true) + + let addressFont = Font.regular(!alignCentrally && params.width == 320 ? floor(item.presentationData.fontSize.itemListBaseFontSize * 15.0 / 17.0) : item.presentationData.fontSize.itemListBaseFontSize) let titleFont = Font.regular(item.presentationData.fontSize.itemListBaseFontSize) - let (addressLayout, addressApply) = makeAddressLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: item.invite.flatMap({ $0.link.replacingOccurrences(of: "https://", with: "") }) ?? "", font: titleFont, textColor: titleColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .middle, constrainedSize: CGSize(width: params.width - leftInset - rightInset - 90.0, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets())) + let constrainedWidth = alignCentrally ? params.width - leftInset - rightInset - 90.0 : params.width - leftInset - rightInset - 60.0 + + let (addressLayout, addressApply) = makeAddressLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: item.invite.flatMap({ $0.link.replacingOccurrences(of: "https://", with: "") }) ?? "", font: addressFont, textColor: titleColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .middle, constrainedSize: CGSize(width: constrainedWidth, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets())) let subtitle: String let subtitleColor: UIColor @@ -424,7 +429,7 @@ public class ItemListPermanentInviteLinkItemNode: ListViewItemNode, ItemListItem strongSelf.fieldNode.frame = fieldFrame strongSelf.fieldButtonNode.frame = fieldFrame - strongSelf.addressNode.frame = CGRect(origin: CGPoint(x: fieldFrame.minX + floorToScreenPixels((fieldFrame.width - addressLayout.size.width) / 2.0), y: fieldFrame.minY + floorToScreenPixels((fieldFrame.height - addressLayout.size.height) / 2.0) + 1.0), size: addressLayout.size) + strongSelf.addressNode.frame = CGRect(origin: CGPoint(x: fieldFrame.minX + (alignCentrally ? floorToScreenPixels((fieldFrame.width - addressLayout.size.width) / 2.0) : 14.0), y: fieldFrame.minY + floorToScreenPixels((fieldFrame.height - addressLayout.size.height) / 2.0) + 1.0), size: addressLayout.size) strongSelf.addressButtonNode.frame = CGRect(origin: CGPoint(x: params.width - rightInset - 38.0 - 14.0, y: verticalInset), size: CGSize(width: 52.0, height: 52.0)) strongSelf.extractedContainerNode.frame = strongSelf.addressButtonNode.bounds diff --git a/submodules/ItemListUI/Sources/Items/ItemListSingleLineInputItem.swift b/submodules/ItemListUI/Sources/Items/ItemListSingleLineInputItem.swift index 1814269c33..4cfb5d278c 100644 --- a/submodules/ItemListUI/Sources/Items/ItemListSingleLineInputItem.swift +++ b/submodules/ItemListUI/Sources/Items/ItemListSingleLineInputItem.swift @@ -343,7 +343,7 @@ public class ItemListSingleLineInputItemNode: ListViewItemNode, UITextFieldDeleg strongSelf.textNode.textField.text = item.text } - strongSelf.textNode.frame = CGRect(origin: CGPoint(x: leftInset + titleLayout.size.width + item.spacing, y: 1.0), size: CGSize(width: max(1.0, params.width - (leftInset + rightInset + titleLayout.size.width + item.spacing)), height: layout.contentSize.height - 2.0)) + strongSelf.textNode.frame = CGRect(origin: CGPoint(x: leftInset + titleLayout.size.width + item.spacing, y: 0.0), size: CGSize(width: max(1.0, params.width - (leftInset + rightInset + titleLayout.size.width + item.spacing)), height: layout.contentSize.height - 2.0)) switch item.alignment { case .default: diff --git a/submodules/TelegramCore/Sources/Suggestions.swift b/submodules/TelegramCore/Sources/Suggestions.swift index a81f8110a6..aaa642eba5 100644 --- a/submodules/TelegramCore/Sources/Suggestions.swift +++ b/submodules/TelegramCore/Sources/Suggestions.swift @@ -65,6 +65,18 @@ public func dismissPeerSpecificServerProvidedSuggestion(account: Account, peerId |> `catch` { _ -> Signal in return .single(.boolFalse) } - |> ignoreValues + |> mapToSignal { a -> Signal in + return account.postbox.transaction { transaction in + transaction.updatePeerCachedData(peerIds: [peerId]) { (_, current) -> CachedPeerData? in + var updated = current + if let cachedData = current as? CachedChannelData { + var pendingSuggestions = cachedData.pendingSuggestions + pendingSuggestions.removeAll(where: { $0 == suggestion.rawValue }) + updated = cachedData.withUpdatedPendingSuggestions(pendingSuggestions) + } + return updated + } + } |> ignoreValues + } } } diff --git a/submodules/TelegramUI/Images.xcassets/Chat/Info/GroupLinksIcon.imageset/Contents.json b/submodules/TelegramUI/Images.xcassets/Chat/Info/GroupLinksIcon.imageset/Contents.json index 2abcba3c88..7f7f04afa3 100644 --- a/submodules/TelegramUI/Images.xcassets/Chat/Info/GroupLinksIcon.imageset/Contents.json +++ b/submodules/TelegramUI/Images.xcassets/Chat/Info/GroupLinksIcon.imageset/Contents.json @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "Links.pdf", + "filename" : "Links (1).pdf", "idiom" : "universal" } ], diff --git a/submodules/TelegramUI/Images.xcassets/Chat/Info/GroupLinksIcon.imageset/Links.pdf b/submodules/TelegramUI/Images.xcassets/Chat/Info/GroupLinksIcon.imageset/Links (1).pdf similarity index 76% rename from submodules/TelegramUI/Images.xcassets/Chat/Info/GroupLinksIcon.imageset/Links.pdf rename to submodules/TelegramUI/Images.xcassets/Chat/Info/GroupLinksIcon.imageset/Links (1).pdf index 96d08e6b7cda88f423ade2bec653fa4efb7dbe85..17af517eff0276045e72804ead2c64d7a8b98dd3 100644 GIT binary patch delta 795 zcmbQQFkfMUL%pGbogG(kNl|KIE>{KP(#gJg(uO>(->q1$v##k9Svh}e`CZnyCk)IY znTDDI6%${7&$M~uvnli9p>Gk7JZj|UuQ0D#WS+J0dd}WJzb{^g3_ULzMtYiTnx>Vk zCbrZ}aFU$2Y1$;AsnPn%le$!SxjlQ+_D1F^$eQI* zY@N*OlhZavPMg-RBDK08mtjtfWz^#(EUL#lS9w;IC-p6xX2i64jYzc{XIAok7H`Au zZEIhhWWOS-pSbigFSD%P#Nf&{gN=3^zIx9;Hl7JT{>zrR=ldG!#5|WX=bdt5KW}sKWc|};=MMd0nAUvi{H?u~@|wrE_g?rc{)_dill_a=U(ap1 z(`mSU+00_z&Uf6gJ)0ILe>@<*H$izz-|=t%o$hb{_iTpo-sJ!0f9mFKj>~TpOx_h+ z$gj|Fp7pZ~>)R=hU(C3!7#+FOS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 10d61715f4..b6e1f972ea 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -7069,6 +7069,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return } + if !strongSelf.traceVisibility() || strongSelf.navigationController?.topViewController != strongSelf { + return + } + if values.contains(.convertToGigagroup) && !strongSelf.displayedConvertToGigagroupSuggestion { strongSelf.displayedConvertToGigagroupSuggestion = true diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index 282230b8d5..389f78cf0c 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -1264,9 +1264,9 @@ private func editingItems(data: PeerInfoScreenData?, context: AccountContext, pr } case .group: let ItemUsername = 101 - let ItemLinkedChannel = 102 - let ItemPreHistory = 103 - let ItemInviteLinks = 104 + let ItemInviteLinks = 102 + let ItemLinkedChannel = 103 + let ItemPreHistory = 104 let ItemStickerPack = 105 let ItemPermissions = 106 let ItemMembers = 107 @@ -1320,25 +1320,6 @@ private func editingItems(data: PeerInfoScreenData?, context: AccountContext, pr interaction.editingOpenPublicLinkSetup() })) } - - if cachedData.flags.contains(.canChangeUsername) { - if let linkedDiscussionPeer = data.linkedDiscussionPeer { - let peerTitle: String - if let addressName = linkedDiscussionPeer.addressName, !addressName.isEmpty { - peerTitle = "@\(addressName)" - } else { - peerTitle = linkedDiscussionPeer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) - } - items[.peerPublicSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemLinkedChannel, label: .text(peerTitle), text: presentationData.strings.Group_LinkedChannel, icon: UIImage(bundleImageName: "Chat/Info/GroupLinkedChannelIcon"), action: { - interaction.editingOpenDiscussionGroupSetup() - })) - } - } - if !isPublic, case .known(nil) = cachedData.linkedDiscussionPeerId { - items[.peerPublicSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemPreHistory, label: .text(cachedData.flags.contains(.preHistoryEnabled) ? presentationData.strings.GroupInfo_GroupHistoryVisible : presentationData.strings.GroupInfo_GroupHistoryHidden), text: presentationData.strings.GroupInfo_GroupHistoryShort, icon: UIImage(bundleImageName: "Chat/Info/GroupDiscussionIcon"), action: { - interaction.editingOpenPreHistorySetup() - })) - } } } @@ -1350,10 +1331,31 @@ private func editingItems(data: PeerInfoScreenData?, context: AccountContext, pr invitesText = "" } - items[.peerSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemInviteLinks, label: .text(invitesText), text: presentationData.strings.GroupInfo_InviteLinks, icon: UIImage(bundleImageName: "Chat/Info/GroupLinksIcon"), action: { + items[.peerPublicSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemInviteLinks, label: .text(invitesText), text: presentationData.strings.GroupInfo_InviteLinks, icon: UIImage(bundleImageName: "Chat/Info/GroupLinksIcon"), action: { interaction.editingOpenInviteLinksSetup() })) } + + if (isCreator || (channel.adminRights != nil && channel.hasPermission(.pinMessages))) && cachedData.peerGeoLocation != nil { + if cachedData.flags.contains(.canChangeUsername) { + if let linkedDiscussionPeer = data.linkedDiscussionPeer { + let peerTitle: String + if let addressName = linkedDiscussionPeer.addressName, !addressName.isEmpty { + peerTitle = "@\(addressName)" + } else { + peerTitle = linkedDiscussionPeer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) + } + items[.peerPublicSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemLinkedChannel, label: .text(peerTitle), text: presentationData.strings.Group_LinkedChannel, icon: UIImage(bundleImageName: "Chat/Info/GroupLinkedChannelIcon"), action: { + interaction.editingOpenDiscussionGroupSetup() + })) + } + } + if !isPublic, case .known(nil) = cachedData.linkedDiscussionPeerId { + items[.peerPublicSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemPreHistory, label: .text(cachedData.flags.contains(.preHistoryEnabled) ? presentationData.strings.GroupInfo_GroupHistoryVisible : presentationData.strings.GroupInfo_GroupHistoryHidden), text: presentationData.strings.GroupInfo_GroupHistoryShort, icon: UIImage(bundleImageName: "Chat/Info/GroupDiscussionIcon"), action: { + interaction.editingOpenPreHistorySetup() + })) + } + } if cachedData.flags.contains(.canSetStickerSet) && canEditPeerInfo(context: context, peer: channel) { items[.peerSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemStickerPack, label: .text(cachedData.stickerPack?.title ?? presentationData.strings.GroupInfo_SharedMediaNone), text: presentationData.strings.Stickers_GroupStickers, icon: UIImage(bundleImageName: "Settings/MenuIcons/Stickers"), action: { @@ -1418,6 +1420,19 @@ private func editingItems(data: PeerInfoScreenData?, context: AccountContext, pr })) } } + + if (group.addressName?.isEmpty ?? true) { + let invitesText: String + if let count = data.invitations?.count, count > 0 { + invitesText = "\(count)" + } else { + invitesText = "" + } + + items[.peerPublicSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemInviteLinks, label: .text(invitesText), text: presentationData.strings.GroupInfo_InviteLinks, icon: UIImage(bundleImageName: "Chat/Info/GroupLinksIcon"), action: { + interaction.editingOpenInviteLinksSetup() + })) + } items[.peerPublicSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemPreHistory, label: .text(presentationData.strings.GroupInfo_GroupHistoryHidden), text: presentationData.strings.GroupInfo_GroupHistoryShort, icon: UIImage(bundleImageName: "Chat/Info/GroupDiscussionIcon"), action: { interaction.editingOpenPreHistorySetup() @@ -1452,19 +1467,6 @@ private func editingItems(data: PeerInfoScreenData?, context: AccountContext, pr activePermissionCount = count } - if (group.addressName?.isEmpty ?? true) { - 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, icon: UIImage(bundleImageName: "Chat/Info/GroupLinksIcon"), action: { - interaction.editingOpenInviteLinksSetup() - })) - } - items[.peerSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemPermissions, label: .text(activePermissionCount.flatMap({ "\($0)/\(allGroupPermissionList.count)" }) ?? ""), text: presentationData.strings.GroupInfo_Permissions, icon: UIImage(bundleImageName: "Settings/MenuIcons/SetPasscode"), action: { interaction.openPermissions() }))