Various fixes

This commit is contained in:
Ilya Laktyushin 2022-05-30 17:33:06 +04:00
parent ee944a5976
commit e59a6a9238
9 changed files with 97 additions and 40 deletions

View File

@ -56,8 +56,9 @@ public final class ContactMultiselectionControllerParams {
public let filters: [ContactListFilter]
public let alwaysEnabled: Bool
public let limit: Int32?
public let reachedLimit: ((Int32) -> Void)?
public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, mode: ContactMultiselectionControllerMode, options: [ContactListAdditionalOption], filters: [ContactListFilter] = [.excludeSelf], alwaysEnabled: Bool = false, limit: Int32? = nil) {
public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, mode: ContactMultiselectionControllerMode, options: [ContactListAdditionalOption], filters: [ContactListFilter] = [.excludeSelf], alwaysEnabled: Bool = false, limit: Int32? = nil, reachedLimit: ((Int32) -> Void)? = nil) {
self.context = context
self.updatedPresentationData = updatedPresentationData
self.mode = mode
@ -65,6 +66,7 @@ public final class ContactMultiselectionControllerParams {
self.filters = filters
self.alwaysEnabled = alwaysEnabled
self.limit = limit
self.reachedLimit = reachedLimit
}
}

View File

@ -1377,7 +1377,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
guard let strongSelf = self else {
return
}
strongSelf.push(chatListFilterAddChatsController(context: strongSelf.context, filter: filter, allFilters: filters))
strongSelf.push(chatListFilterAddChatsController(context: strongSelf.context, filter: filter, allFilters: filters, limit: limits.maxFolderChatsCount, premiumLimit: premiumLimits.maxFolderChatsCount, isPremium: isPremium))
f(.dismissWithoutContent)
})
found = true

View File

@ -548,11 +548,11 @@ private enum AdditionalExcludeCategoryId: Int {
case archived
}
func chatListFilterAddChatsController(context: AccountContext, filter: ChatListFilter, allFilters: [ChatListFilter]) -> ViewController {
return internalChatListFilterAddChatsController(context: context, filter: filter, allFilters: allFilters, applyAutomatically: true, updated: { _ in })
func chatListFilterAddChatsController(context: AccountContext, filter: ChatListFilter, allFilters: [ChatListFilter], limit: Int32, premiumLimit: Int32, isPremium: Bool) -> ViewController {
return internalChatListFilterAddChatsController(context: context, filter: filter, allFilters: allFilters, applyAutomatically: true, limit: limit, premiumLimit: premiumLimit, isPremium: isPremium, updated: { _ in })
}
private func internalChatListFilterAddChatsController(context: AccountContext, filter: ChatListFilter, allFilters: [ChatListFilter], applyAutomatically: Bool, updated: @escaping (ChatListFilter) -> Void) -> ViewController {
private func internalChatListFilterAddChatsController(context: AccountContext, filter: ChatListFilter, allFilters: [ChatListFilter], applyAutomatically: Bool, limit: Int32, premiumLimit: Int32, isPremium: Bool, updated: @escaping (ChatListFilter) -> Void) -> ViewController {
guard case let .filter(_, _, _, filterData) = filter else {
return ViewController(navigationBarPresentationData: nil)
}
@ -599,8 +599,33 @@ private func internalChatListFilterAddChatsController(context: AccountContext, f
}
}
let controller = context.sharedContext.makeContactMultiselectionController(ContactMultiselectionControllerParams(context: context, mode: .chatSelection(title: presentationData.strings.ChatListFolder_IncludeChatsTitle, selectedChats: Set(filterData.includePeers.peers), additionalCategories: ContactMultiselectionControllerAdditionalCategories(categories: additionalCategories, selectedCategories: selectedCategories), chatListFilters: allFilters), options: [], filters: [], alwaysEnabled: true, limit: 100))
var pushImpl: ((ViewController) -> Void)?
let controller = context.sharedContext.makeContactMultiselectionController(ContactMultiselectionControllerParams(context: context, mode: .chatSelection(title: presentationData.strings.ChatListFolder_IncludeChatsTitle, selectedChats: Set(filterData.includePeers.peers), additionalCategories: ContactMultiselectionControllerAdditionalCategories(categories: additionalCategories, selectedCategories: selectedCategories), chatListFilters: allFilters), options: [], filters: [], alwaysEnabled: true, limit: isPremium ? premiumLimit : limit, reachedLimit: { count in
if count >= premiumLimit {
let limitController = PremiumLimitScreen(context: context, subject: .chatsPerFolder, count: min(premiumLimit, count), action: {})
pushImpl?(limitController)
return
} else if count >= limit && !isPremium {
var replaceImpl: ((ViewController) -> Void)?
let limitController = PremiumLimitScreen(context: context, subject: .chatsPerFolder, count: count, action: {
let introController = PremiumIntroScreen(context: context, source: .chatsPerFolder)
replaceImpl?(introController)
})
replaceImpl = { [weak limitController] c in
limitController?.replace(with: c)
}
pushImpl?(limitController)
return
}
}))
controller.navigationPresentation = .modal
pushImpl = { [weak controller] c in
controller?.push(c)
}
let _ = combineLatest(
queue: Queue.mainQueue(),
controller.result |> take(1),
@ -616,8 +641,8 @@ private func internalChatListFilterAddChatsController(context: AccountContext, f
return
}
let (accountPeer, limits, premiumLimits) = data
let isPremium = accountPeer?.isPremium ?? false
// let (accountPeer, limits, premiumLimits) = data
// let isPremium = accountPeer?.isPremium ?? false
var includePeers: [PeerId] = []
for peerId in peerIds {
@ -630,23 +655,23 @@ private func internalChatListFilterAddChatsController(context: AccountContext, f
}
includePeers.sort()
if includePeers.count > premiumLimits.maxFolderChatsCount {
let limitController = PremiumLimitScreen(context: context, subject: .chatsPerFolder, count: Int32(includePeers.count), action: {})
controller?.push(limitController)
return
} else if includePeers.count > limits.maxFolderChatsCount && !isPremium {
var replaceImpl: ((ViewController) -> Void)?
let limitController = PremiumLimitScreen(context: context, subject: .chatsPerFolder, count: Int32(includePeers.count), action: {
let introController = PremiumIntroScreen(context: context, source: .chatsPerFolder)
replaceImpl?(introController)
})
replaceImpl = { [weak controller] c in
controller?.replace(with: c)
}
controller?.push(limitController)
return
}
// if includePeers.count > premiumLimits.maxFolderChatsCount {
// let limitController = PremiumLimitScreen(context: context, subject: .chatsPerFolder, count: Int32(includePeers.count), action: {})
// controller?.push(limitController)
// return
// } else if includePeers.count > limits.maxFolderChatsCount && !isPremium {
// var replaceImpl: ((ViewController) -> Void)?
// let limitController = PremiumLimitScreen(context: context, subject: .chatsPerFolder, count: Int32(includePeers.count), action: {
// let introController = PremiumIntroScreen(context: context, source: .chatsPerFolder)
// replaceImpl?(introController)
// })
// replaceImpl = { [weak controller] c in
// controller?.replace(with: c)
// }
// controller?.push(limitController)
//
// return
// }
var categories: ChatListFilterPeerCategories = []
for id in additionalCategoryIds {
@ -1011,7 +1036,7 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat
let _ = (context.engine.peers.currentChatListFilters()
|> deliverOnMainQueue).start(next: { filters in
let controller = internalChatListFilterAddChatsController(context: context, filter: filter, allFilters: filters, applyAutomatically: false, updated: { filter in
let controller = internalChatListFilterAddChatsController(context: context, filter: filter, allFilters: filters, applyAutomatically: false, limit: limits.maxFolderChatsCount, premiumLimit: premiumLimits.maxFolderChatsCount, isPremium: isPremium, updated: { filter in
skipStateAnimation = true
updateState { state in
var state = state

View File

@ -705,6 +705,9 @@ public final class ChatListNode: ListView {
var isSelectionGestureEnabled = true
public var selectionLimit: Int32 = 100
public var reachedSelectionLimit: ((Int32) -> Void)?
public init(context: AccountContext, groupId: EngineChatList.Group, chatListFilter: ChatListFilter? = nil, previewing: Bool, fillPreloadItems: Bool, mode: ChatListNodeMode, theme: PresentationTheme, fontSize: PresentationFontSize, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, nameSortOrder: PresentationPersonNameOrder, nameDisplayOrder: PresentationPersonNameOrder, disableAnimations: Bool) {
self.context = context
self.groupId = groupId
@ -743,27 +746,32 @@ public final class ChatListNode: ListView {
disabledPeerSelected(peer)
}
}, togglePeerSelected: { [weak self] peer in
guard let strongSelf = self else {
return
}
var didBeginSelecting = false
var count = 0
self?.updateState { state in
strongSelf.updateState { [weak self] state in
var state = state
if state.selectedPeerIds.contains(peer.id) {
state.selectedPeerIds.remove(peer.id)
} else {
if state.selectedPeerIds.count < 100 {
if state.selectedPeerIds.count < strongSelf.selectionLimit {
if state.selectedPeerIds.isEmpty {
didBeginSelecting = true
}
state.selectedPeerIds.insert(peer.id)
state.selectedPeerMap[peer.id] = peer
} else {
self?.reachedSelectionLimit?(Int32(state.selectedPeerIds.count))
}
}
count = state.selectedPeerIds.count
return state
}
self?.selectionCountChanged?(count)
strongSelf.selectionCountChanged?(count)
if didBeginSelecting {
self?.didBeginSelectingChats?()
strongSelf.didBeginSelectingChats?()
}
}, togglePeersSelection: { [weak self] peers, selected in
self?.updateState { state in

View File

@ -566,7 +566,7 @@ public class ContactsPeerItemNode: ItemListRevealOptionsItemNode {
var currentCredibilityIconImage: UIImage?
switch item.peer {
case let .peer(peer, _):
if let peer = peer {
if let peer = peer, peer.id != item.context.account.peerId {
if peer.isScam {
currentCredibilityIconImage = PresentationResourcesChatList.scamIcon(item.presentationData.theme, strings: item.presentationData.strings, type: .regular)
} else if peer.isFake {

View File

@ -603,7 +603,9 @@ public class ItemListPeerItemNode: ItemListRevealOptionsItemNode, ItemListItemNo
var updatedLabelBadgeImage: UIImage?
var currentCredibilityIconImage: UIImage?
if item.peer.id != item.context.account.peerId {
if case .threatSelfAsSaved = item.aliasHandling, item.peer.id == item.context.account.peerId {
} else {
if item.peer.isScam {
currentCredibilityIconImage = PresentationResourcesChatList.scamIcon(item.presentationData.theme, strings: item.presentationData.strings, type: .regular)
} else if item.peer.isFake {

View File

@ -181,12 +181,19 @@ public final class StickerPreviewPeekContentNode: ASDisplayNode, PeekControllerC
}
if let dimensitons = self.item.file.dimensions {
let textSpacing: CGFloat = 50.0
var topOffset: CGFloat = 0.0
var textSpacing: CGFloat = 50.0
if size.width == 292.0 {
topOffset = 60.0
textSpacing -= 10.0
}
let textSize = self.textNode.measure(CGSize(width: 100.0, height: 100.0))
let imageSize = dimensitons.cgSize.aspectFitted(boundingSize)
self.imageNode.asyncLayout()(TransformImageArguments(corners: ImageCorners(), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: UIEdgeInsets()))()
var imageFrame = CGRect(origin: CGPoint(x: floor((size.width - imageSize.width) / 2.0), y: textSize.height + textSpacing), size: imageSize)
var imageFrame = CGRect(origin: CGPoint(x: floor((size.width - imageSize.width) / 2.0), y: textSize.height + textSpacing - topOffset), size: imageSize)
var centerOffset: CGFloat = 0.0
if self.item.file.isPremiumSticker {
let originalImageFrame = imageFrame
@ -263,14 +270,21 @@ final class PremiumStickerPackAccessoryNode: SparseNode, PeekControllerAccessory
func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) {
let sideInset: CGFloat = 16.0
var bottomOffset: CGFloat = 0.0
if size.width == 320.0 {
bottomOffset = 30.0
}
let cancelSize = self.cancelButton.measure(size)
self.cancelButton.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - cancelSize.width) / 2.0), y: size.height - cancelSize.height - 49.0), size: cancelSize)
self.cancelButton.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - cancelSize.width) / 2.0), y: size.height - cancelSize.height - 49.0 + bottomOffset), size: cancelSize)
let buttonWidth = size.width - sideInset * 2.0
let buttonHeight = self.proceedButton.updateLayout(width: buttonWidth, transition: transition)
self.proceedButton.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - buttonWidth) / 2.0), y: size.height - cancelSize.height - 49.0 - buttonHeight - 23.0), size: CGSize(width: buttonWidth, height: buttonHeight))
self.proceedButton.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - buttonWidth) / 2.0), y: size.height - cancelSize.height - 49.0 - buttonHeight - 23.0 + bottomOffset), size: CGSize(width: buttonWidth, height: buttonHeight))
let textSize = self.textNode.updateLayout(CGSize(width: size.width - sideInset * 4.0, height: CGFloat.greatestFiniteMagnitude))
self.textNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - textSize.width) / 2.0), y: size.height - cancelSize.height - 48.0 - buttonHeight - 20.0 - textSize.height - 31.0), size: textSize)
let textSideInset = size.width == 320.0 ? sideInset : sideInset * 2.0
let textSize = self.textNode.updateLayout(CGSize(width: size.width - textSideInset * 2.0, height: CGFloat.greatestFiniteMagnitude))
self.textNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - textSize.width) / 2.0), y: size.height - cancelSize.height - 48.0 - buttonHeight - 20.0 - textSize.height - 31.0 + bottomOffset), size: textSize)
}
}

View File

@ -218,7 +218,7 @@ class ContactMultiselectionControllerImpl: ViewController, ContactMultiselection
}
override func loadDisplayNode() {
self.displayNode = ContactMultiselectionControllerNode(navigationBar: self.navigationBar, context: self.context, presentationData: self.presentationData, mode: self.mode, options: self.options, filters: self.filters)
self.displayNode = ContactMultiselectionControllerNode(navigationBar: self.navigationBar, context: self.context, presentationData: self.presentationData, mode: self.mode, options: self.options, filters: self.filters, limit: self.limit, reachedSelectionLimit: self.params.reachedLimit)
switch self.contactsNode.contentNode {
case let .contacts(contactsNode):
self._listReady.set(contactsNode.ready)
@ -266,6 +266,7 @@ class ContactMultiselectionControllerImpl: ViewController, ContactMultiselection
}
}
case let .chats(chatsNode):
let reachedLimit = strongSelf.params.reachedLimit
chatsNode.updateState { initialState in
var state = initialState
if state.selectedPeerIds.contains(peer.id) {
@ -277,6 +278,7 @@ class ContactMultiselectionControllerImpl: ViewController, ContactMultiselection
}
updatedCount = state.selectedPeerIds.count
if let limit = limit, let count = updatedCount, count > limit {
reachedLimit?(Int32(count))
updatedCount = nil
removedTokenId = nil
addedToken = nil

View File

@ -66,7 +66,7 @@ final class ContactMultiselectionControllerNode: ASDisplayNode {
private var presentationData: PresentationData
init(navigationBar: NavigationBar?, context: AccountContext, presentationData: PresentationData, mode: ContactMultiselectionControllerMode, options: [ContactListAdditionalOption], filters: [ContactListFilter]) {
init(navigationBar: NavigationBar?, context: AccountContext, presentationData: PresentationData, mode: ContactMultiselectionControllerMode, options: [ContactListAdditionalOption], filters: [ContactListFilter], limit: Int32?, reachedSelectionLimit: ((Int32) -> Void)?) {
self.navigationBar = navigationBar
self.context = context
@ -89,6 +89,10 @@ final class ContactMultiselectionControllerNode: ASDisplayNode {
if case let .chatSelection(_, selectedChats, additionalCategories, chatListFilters) = mode {
placeholder = self.presentationData.strings.ChatListFilter_AddChatsTitle
let chatListNode = ChatListNode(context: context, groupId: .root, previewing: false, fillPreloadItems: false, mode: .peers(filter: [.excludeSecretChats], isSelecting: true, additionalCategories: additionalCategories?.categories ?? [], chatListFilters: chatListFilters), theme: self.presentationData.theme, fontSize: self.presentationData.listsFontSize, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, nameSortOrder: self.presentationData.nameSortOrder, nameDisplayOrder: self.presentationData.nameDisplayOrder, disableAnimations: true)
if let limit = limit {
chatListNode.selectionLimit = limit
chatListNode.reachedSelectionLimit = reachedSelectionLimit
}
chatListNode.accessibilityPageScrolledString = { row, count in
return presentationData.strings.VoiceOver_ScrollStatus(row, count).string
}