From 2ce6d8c66c1fe37850e9794a993778f5b8b7fb5c Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 28 Jun 2025 23:51:09 +0200 Subject: [PATCH] Various fixes --- .../ComposePollUI/Sources/ComposePollScreen.swift | 13 +++++++++---- .../Sources/Statistics/StarsRevenueStatistics.swift | 8 +++++--- .../Sources/ComposeTodoScreen.swift | 11 ++++++++--- .../Sources/ListComposePollOptionComponent.swift | 7 ++++--- .../Sources/ChatControllerOpenAttachmentMenu.swift | 1 + 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/submodules/ComposePollUI/Sources/ComposePollScreen.swift b/submodules/ComposePollUI/Sources/ComposePollScreen.swift index 556236bc7c..ad42d62299 100644 --- a/submodules/ComposePollUI/Sources/ComposePollScreen.swift +++ b/submodules/ComposePollUI/Sources/ComposePollScreen.swift @@ -232,7 +232,7 @@ final class ComposePollScreenComponent: Component { } private func item(at point: CGPoint) -> (AnyHashable, ComponentView)? { - if self.scrollView.isTracking || self.scrollView.isDecelerating { + if self.scrollView.isDragging || self.scrollView.isDecelerating { return nil } @@ -240,7 +240,7 @@ final class ComposePollScreenComponent: Component { for (id, itemView) in self.pollOptionsSectionContainer.itemViews { if let view = itemView.contents.view as? ListComposePollOptionComponent.View, !view.isRevealed && !view.currentText.isEmpty { let viewFrame = view.convert(view.bounds, to: self.pollOptionsSectionContainer) - let iconFrame = CGRect(origin: CGPoint(x: viewFrame.maxX - viewFrame.height, y: viewFrame.minY), size: CGSize(width: viewFrame.height, height: viewFrame.height)) + let iconFrame = CGRect(origin: CGPoint(x: viewFrame.maxX - 40.0, y: viewFrame.minY), size: CGSize(width: viewFrame.height, height: viewFrame.height)) if iconFrame.contains(localPoint) { return (id, itemView.contents) } @@ -941,6 +941,11 @@ final class ComposePollScreenComponent: Component { }) } + var canDelete = true + if i == self.pollOptions.count - 1 { + canDelete = false + } + pollOptionsSectionItems.append(AnyComponentWithIdentity(id: pollOption.id, component: AnyComponent(ListComposePollOptionComponent( externalState: pollOption.textInputState, context: component.context, @@ -1001,13 +1006,13 @@ final class ComposePollScreenComponent: Component { } self.state?.updated(transition: .spring(duration: 0.4)) }, - deleteAction: { [weak self] in + deleteAction: canDelete ? { [weak self] in guard let self else { return } self.pollOptions.removeAll(where: { $0.id == optionId }) self.state?.updated(transition: .spring(duration: 0.4)) - }, + } : nil, tag: pollOption.textFieldTag )))) diff --git a/submodules/TelegramCore/Sources/Statistics/StarsRevenueStatistics.swift b/submodules/TelegramCore/Sources/Statistics/StarsRevenueStatistics.swift index 5bc1125d60..2ffecfba96 100644 --- a/submodules/TelegramCore/Sources/Statistics/StarsRevenueStatistics.swift +++ b/submodules/TelegramCore/Sources/Statistics/StarsRevenueStatistics.swift @@ -12,9 +12,10 @@ public struct StarsRevenueStats: Equatable, Codable { case usdRate } - static func key(peerId: PeerId) -> ValueBoxKey { + static func key(peerId: PeerId, ton: Bool) -> ValueBoxKey { let key = ValueBoxKey(length: 8 + 4) key.setInt64(0, value: peerId.toInt64()) + key.setInt32(8, value: ton ? 1 : 0) return key } @@ -227,7 +228,7 @@ private final class StarsRevenueStatsContextImpl { self.load() let _ = (account.postbox.transaction { transaction -> StarsRevenueStats? in - return transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStarsRevenueStats, key: StarsRevenueStats.key(peerId: peerId)))?.get(StarsRevenueStats.self) + return transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStarsRevenueStats, key: StarsRevenueStats.key(peerId: peerId, ton: ton)))?.get(StarsRevenueStats.self) } |> deliverOnMainQueue).start(next: { [weak self] cachedResult in guard let self, let cachedResult else { @@ -259,6 +260,7 @@ private final class StarsRevenueStatsContextImpl { let account = self.account let peerId = self.peerId + let ton = self.ton let signal = requestStarsRevenueStats(postbox: self.account.postbox, network: self.account.network, peerId: self.peerId, ton: self.ton) |> mapToSignal { initial -> Signal in guard let initial else { @@ -285,7 +287,7 @@ private final class StarsRevenueStatsContextImpl { if let stats { let _ = (self.account.postbox.transaction { transaction in if let entry = CodableEntry(stats) { - transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStarsRevenueStats, key: StarsRevenueStats.key(peerId: peerId)), entry: entry) + transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStarsRevenueStats, key: StarsRevenueStats.key(peerId: peerId, ton: ton)), entry: entry) } }).start() } diff --git a/submodules/TelegramUI/Components/ComposeTodoScreen/Sources/ComposeTodoScreen.swift b/submodules/TelegramUI/Components/ComposeTodoScreen/Sources/ComposeTodoScreen.swift index cedab877c9..45e196a195 100644 --- a/submodules/TelegramUI/Components/ComposeTodoScreen/Sources/ComposeTodoScreen.swift +++ b/submodules/TelegramUI/Components/ComposeTodoScreen/Sources/ComposeTodoScreen.swift @@ -180,7 +180,7 @@ final class ComposeTodoScreenComponent: Component { } private func item(at point: CGPoint) -> (AnyHashable, ComponentView)? { - if self.scrollView.isTracking || self.scrollView.isDecelerating { + if self.scrollView.isDragging || self.scrollView.isDecelerating { return nil } @@ -188,7 +188,7 @@ final class ComposeTodoScreenComponent: Component { for (id, itemView) in self.todoItemsSectionContainer.itemViews { if let view = itemView.contents.view as? ListComposePollOptionComponent.View, !view.isRevealed && !view.currentText.isEmpty { let viewFrame = view.convert(view.bounds, to: self.todoItemsSectionContainer) - let iconFrame = CGRect(origin: CGPoint(x: viewFrame.maxX - viewFrame.height, y: viewFrame.minY), size: CGSize(width: viewFrame.height, height: viewFrame.height)) + let iconFrame = CGRect(origin: CGPoint(x: viewFrame.maxX - 40.0, y: viewFrame.minY), size: CGSize(width: viewFrame.height, height: viewFrame.height)) if iconFrame.contains(localPoint) { return (id, itemView.contents) } @@ -861,6 +861,11 @@ final class ComposeTodoScreenComponent: Component { isEnabled = false } + var canDelete = isEnabled + if i == self.todoItems.count - 1 { + canDelete = false + } + todoItemsSectionItems.append(AnyComponentWithIdentity(id: todoItem.id, component: AnyComponent(ListComposePollOptionComponent( externalState: todoItem.textInputState, context: component.context, @@ -922,7 +927,7 @@ final class ComposeTodoScreenComponent: Component { } self.state?.updated(transition: .spring(duration: 0.4)) }, - deleteAction: isEnabled ? { [weak self] in + deleteAction: canDelete ? { [weak self] in guard let self else { return } diff --git a/submodules/TelegramUI/Components/ListComposePollOptionComponent/Sources/ListComposePollOptionComponent.swift b/submodules/TelegramUI/Components/ListComposePollOptionComponent/Sources/ListComposePollOptionComponent.swift index 2828c2def0..f58ef64eeb 100644 --- a/submodules/TelegramUI/Components/ListComposePollOptionComponent/Sources/ListComposePollOptionComponent.swift +++ b/submodules/TelegramUI/Components/ListComposePollOptionComponent/Sources/ListComposePollOptionComponent.swift @@ -459,9 +459,6 @@ public final class ListComposePollOptionComponent: Component { return false } } - if gestureRecognizer == self.recognizer, let externalState = self.component?.externalState, !externalState.hasText { - return false - } return true } @@ -566,6 +563,10 @@ public final class ListComposePollOptionComponent: Component { rightInset += 34.0 } + if component.canReorder { + rightInset += 16.0 + } + let textFieldSize = self.textField.update( transition: transition, component: AnyComponent(TextFieldComponent( diff --git a/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift b/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift index 7b2614ba8f..1a108becc2 100644 --- a/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift +++ b/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift @@ -75,6 +75,7 @@ extension ChatControllerImpl { } } else if peer is TelegramSecretChat { canSendPolls = false + canSendTodos = false } else if let channel = peer as? TelegramChannel { if case .broadcast = channel.info { canSendTodos = false