From 17390d9067e151690076d8dfd3e5ba315a5e2785 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 9 Nov 2022 15:10:56 +0400 Subject: [PATCH] Various fixes --- .../Telegram-iOS/en.lproj/Localizable.strings | 4 +- .../ChatListUI/Sources/ChatContextMenus.swift | 13 ++- .../Sources/ChatListController.swift | 50 +++++--- .../Sources/ChatListSearchContainerNode.swift | 46 +++++--- .../Sources/Node/ChatListNode.swift | 6 +- .../Items/ItemListActivityTextItem.swift | 3 +- .../Sources/ChannelVisibilityController.swift | 2 +- .../Sources/UsernameSetupController.swift | 2 +- .../SyncCore/SyncCore_TelegramMediaFile.swift | 8 +- .../Sources/PeerInfo/PeerInfoScreen.swift | 107 ++++++++++-------- 10 files changed, 144 insertions(+), 97 deletions(-) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index b02c43c5f8..458a410e7c 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -8269,8 +8269,8 @@ Sorry for the inconvenience."; "EmojiSearch.SearchTopicIconsPlaceholder" = "Search Topic Icons"; "EmojiSearch.SearchTopicIconsEmptyResult" = "No emoji found"; -"Username.UsernamePurchaseAvailable" = "Sorry, this username is occupied by someone. But it's available for purchase on [fragment.com]()."; -"Channel.Username.UsernamePurchaseAvailable" = "Sorry, this link is occupied by someone. But it's available for purchase on [fragment.com]()."; +"Username.UsernamePurchaseAvailable" = "**This username is already taken.** However, it is being resold via auction. [Learn more...]()"; +"Channel.Username.UsernamePurchaseAvailable" = "**This username is already taken.** However, it is being resold via auction. [Learn more...]()"; "DownloadList.IncreaseSpeed" = "Increase Speed"; "Conversation.IncreaseSpeed" = "Increase Speed"; diff --git a/submodules/ChatListUI/Sources/ChatContextMenus.swift b/submodules/ChatListUI/Sources/ChatContextMenus.swift index 8d0fbc5c01..37988cf4f6 100644 --- a/submodules/ChatListUI/Sources/ChatContextMenus.swift +++ b/submodules/ChatListUI/Sources/ChatContextMenus.swift @@ -761,12 +761,13 @@ func chatForumTopicMenuItems(context: AccountContext, peerId: PeerId, threadId: }))) } -// items.append(.separator) -// items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_Select, textColor: .primary, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Select"), color: theme.contextMenu.primaryColor) }, action: { _, f in -// f(.default) -// -// -// }))) + if canOpenClose { + items.append(.separator) + items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_Select, textColor: .primary, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Select"), color: theme.contextMenu.primaryColor) }, action: { _, f in + f(.default) + chatListController?.selectPeerThread(peerId: peerId, threadId: threadId) + }))) + } return .single(items) } diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 380be7e9bb..2a72d85445 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -527,21 +527,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController navigationController.replaceController(strongSelf, with: chatController, animated: true) } } - - if let channel = peerView.peers[peerView.peerId] as? TelegramChannel { - switch channel.participationStatus { - case .member: - strongSelf.setToolbar(nil, transition: .animated(duration: 0.4, curve: .spring)) - default: - let actionTitle: String - if channel.flags.contains(.requestToJoin) { - actionTitle = strongSelf.presentationData.strings.Group_ApplyToJoin - } else { - actionTitle = strongSelf.presentationData.strings.Channel_JoinChannel - } - strongSelf.setToolbar(Toolbar(leftAction: nil, rightAction: nil, middleAction: ToolbarAction(title: actionTitle, isEnabled: true)), transition: .animated(duration: 0.4, curve: .spring)) - } - } }) } } @@ -1781,11 +1766,20 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController } } + let peerView: Signal + if case let .forum(peerId) = location { + peerView = context.account.viewTracker.peerView(peerId) + |> map(Optional.init) + } else { + peerView = .single(nil) + } + let previousToolbarValue = Atomic(value: nil) self.stateDisposable.set(combineLatest(queue: .mainQueue(), self.presentationDataValue.get(), - peerIdsAndOptions - ).start(next: { [weak self] presentationData, peerIdsAndOptions in + peerIdsAndOptions, + peerView + ).start(next: { [weak self] presentationData, peerIdsAndOptions, peerView in guard let strongSelf = self else { return } @@ -1838,6 +1832,19 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController } toolbar = Toolbar(leftAction: leftAction, rightAction: ToolbarAction(title: presentationData.strings.Common_Delete, isEnabled: options.delete), middleAction: middleAction) } + } else if let peerView = peerView, let channel = peerView.peers[peerView.peerId] as? TelegramChannel { + switch channel.participationStatus { + case .member: + strongSelf.setToolbar(nil, transition: .animated(duration: 0.4, curve: .spring)) + default: + let actionTitle: String + if channel.flags.contains(.requestToJoin) { + actionTitle = strongSelf.presentationData.strings.Group_ApplyToJoin + } else { + actionTitle = strongSelf.presentationData.strings.Channel_JoinChannel + } + strongSelf.setToolbar(Toolbar(leftAction: nil, rightAction: nil, middleAction: ToolbarAction(title: actionTitle, isEnabled: true)), transition: .animated(duration: 0.4, curve: .spring)) + } } var transition: ContainedViewLayoutTransition = .immediate let previousToolbar = previousToolbarValue.swap(toolbar) @@ -3823,6 +3830,15 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController self.present(actionSheet, in: .window(.root)) } + func selectPeerThread(peerId: EnginePeer.Id, threadId: Int64) { + self.chatListDisplayNode.containerNode.updateState({ state in + var state = state + state.selectedThreadIds.insert(threadId) + return state + }) + self.chatListDisplayNode.containerNode.didBeginSelectingChats?() + } + private func commitDeletePeerThread(peerId: EnginePeer.Id, threadId: Int64, completion: @escaping () -> Void) { self.forEachController({ controller in if let controller = controller as? UndoOverlayController { diff --git a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift index 7a54d41732..7e5420b660 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift @@ -1427,29 +1427,41 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo strongSelf.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .immediate) } } else { - let _ = (ChatInterfaceState.update(engine: strongSelf.context.engine, peerId: peerId, threadId: nil, { currentState in + let _ = (ChatInterfaceState.update(engine: strongSelf.context.engine, peerId: peerId, threadId: threadId, { currentState in return currentState.withUpdatedForwardMessageIds(Array(messageIds)) }) - |> deliverOnMainQueue).start(completed: { + |> deliverOnMainQueue).start(completed: { [weak self] in if let strongSelf = self { - let controller = strongSelf.context.sharedContext.makeChatController(context: strongSelf.context, chatLocation: .peer(id: peerId), subject: nil, botStart: nil, mode: .standard(previewing: false)) - controller.purposefulAction = { [weak self] in - self?.cancel?() - } - - if let navigationController = strongSelf.navigationController, let peerSelectionControllerIndex = navigationController.viewControllers.firstIndex(where: { $0 is PeerSelectionController }) { - var viewControllers = navigationController.viewControllers - viewControllers.insert(controller, at: peerSelectionControllerIndex) - navigationController.setViewControllers(viewControllers, animated: false) - Queue.mainQueue().after(0.2) { - peerSelectionController?.dismiss() + let proceed: (ChatController) -> Void = { chatController in + chatController.purposefulAction = { [weak self] in + self?.cancel?() } - } else { - strongSelf.navigationController?.pushViewController(controller, animated: false, completion: { - if let peerSelectionController = peerSelectionController { - peerSelectionController.dismiss() + if let navigationController = strongSelf.navigationController { + var viewControllers = navigationController.viewControllers + if threadId != nil { + viewControllers.insert(chatController, at: viewControllers.count - 2) + } else { + viewControllers.insert(chatController, at: viewControllers.count - 1) } + navigationController.setViewControllers(viewControllers, animated: false) + + strongSelf.activeActionDisposable.set((chatController.ready.get() + |> filter { $0 } + |> take(1) + |> deliverOnMainQueue).start(next: { [weak navigationController] _ in + viewControllers.removeAll(where: { $0 is PeerSelectionController }) + navigationController?.setViewControllers(viewControllers, animated: true) + })) + } + } + + if let threadId = threadId { + let _ = (strongSelf.context.sharedContext.chatControllerForForumThread(context: strongSelf.context, peerId: peerId, threadId: threadId) + |> deliverOnMainQueue).start(next: { chatController in + proceed(chatController) }) + } else { + proceed(strongSelf.context.sharedContext.makeChatController(context: strongSelf.context, chatLocation: .peer(id: peerId), subject: nil, botStart: nil, mode: .standard(previewing: false))) } strongSelf.updateState { state in diff --git a/submodules/ChatListUI/Sources/Node/ChatListNode.swift b/submodules/ChatListUI/Sources/Node/ChatListNode.swift index 0ab3d0eb17..59c304aff3 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListNode.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListNode.swift @@ -1959,9 +1959,9 @@ public final class ChatListNode: ListView { } self.view.addGestureRecognizer(selectionRecognizer) - if case .forum = location { - self.isSelectionGestureEnabled = false - } +// if case .forum = location { +// self.isSelectionGestureEnabled = false +// } } deinit { diff --git a/submodules/ItemListUI/Sources/Items/ItemListActivityTextItem.swift b/submodules/ItemListUI/Sources/Items/ItemListActivityTextItem.swift index 414679cc4a..04bec4fa28 100644 --- a/submodules/ItemListUI/Sources/Items/ItemListActivityTextItem.swift +++ b/submodules/ItemListUI/Sources/Items/ItemListActivityTextItem.swift @@ -109,7 +109,6 @@ public class ItemListActivityTextItemNode: ListViewItemNode { let verticalInset: CGFloat = 7.0 let titleFont = Font.regular(item.presentationData.fontSize.itemListBaseHeaderFontSize) - let titleBoldFont = Font.semibold(item.presentationData.fontSize.itemListBaseHeaderFontSize) var activityWidth: CGFloat = 0.0 if item.displayActivity { @@ -128,7 +127,7 @@ public class ItemListActivityTextItemNode: ListViewItemNode { textColor = UIColor(rgb: 0xef8c00) } - let attributedString = parseMarkdownIntoAttributedString(item.text, attributes: MarkdownAttributes(body: MarkdownAttributeSet(font: titleFont, textColor: textColor), bold: MarkdownAttributeSet(font: titleBoldFont, textColor: textColor), link: MarkdownAttributeSet(font: titleFont, textColor: item.presentationData.theme.list.itemAccentColor), linkAttribute: { contents in + let attributedString = parseMarkdownIntoAttributedString(item.text, attributes: MarkdownAttributes(body: MarkdownAttributeSet(font: titleFont, textColor: textColor), bold: MarkdownAttributeSet(font: titleFont, textColor: item.presentationData.theme.list.freeTextErrorColor), link: MarkdownAttributeSet(font: titleFont, textColor: item.presentationData.theme.list.itemAccentColor), linkAttribute: { contents in return (TelegramTextAttributes.URL, contents) })) diff --git a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift index dab8cc8e02..cdf7a66d5f 100644 --- a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift @@ -688,7 +688,7 @@ private enum ChannelVisibilityEntry: ItemListNodeEntry { case .taken: textColor = .destructive case .purchaseAvailable: - textColor = .warning + textColor = .generic } case .checking: textColor = .generic diff --git a/submodules/SettingsUI/Sources/UsernameSetupController.swift b/submodules/SettingsUI/Sources/UsernameSetupController.swift index f4c2ff96e3..9e2d695bc0 100644 --- a/submodules/SettingsUI/Sources/UsernameSetupController.swift +++ b/submodules/SettingsUI/Sources/UsernameSetupController.swift @@ -219,7 +219,7 @@ private enum UsernameSetupEntry: ItemListNodeEntry { case .available: textColor = .constructive case .purchaseAvailable: - textColor = .warning + textColor = .generic case .invalid, .taken: textColor = .destructive } diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaFile.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaFile.swift index 1963939bc2..ca35456751 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaFile.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramMediaFile.swift @@ -683,12 +683,16 @@ public final class TelegramMediaFile: Media, Equatable, Codable { } public var isMusic: Bool { + var hasNonVoiceAudio = false + var hasVideo = false for attribute in self.attributes { if case .Audio(false, _, _, _, _) = attribute { - return true + hasNonVoiceAudio = true + } else if case .Video = attribute { + hasVideo = true } } - return false + return hasNonVoiceAudio && !hasVideo } public var isVoice: Bool { diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index d08f36a4af..7061429725 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -2147,29 +2147,40 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate items.append(.action(ContextMenuActionItem(text: strongSelf.presentationData.strings.SharedMedia_ViewInChat, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/GoToMessage"), color: theme.contextMenu.primaryColor) }, action: { c, _ in c.dismiss(completion: { if let strongSelf = self, let currentPeer = strongSelf.data?.peer, let navigationController = strongSelf.controller?.navigationController as? NavigationController { - let currentPeerId = strongSelf.peerId - strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(EnginePeer(currentPeer)), subject: .message(id: .id(message.id), highlight: true, timecode: nil), keepStack: .always, useExisting: false, purposefulAction: { - var viewControllers = navigationController.viewControllers - var indexesToRemove = Set() - var keptCurrentChatController = false - var index: Int = viewControllers.count - 1 - for controller in viewControllers.reversed() { - if let controller = controller as? ChatController, case let .peer(peerId) = controller.chatLocation { - if peerId == currentPeerId && !keptCurrentChatController { - keptCurrentChatController = true - } else { + if let channel = currentPeer as? TelegramChannel, channel.flags.contains(.isForum), let threadId = message.threadId { + let _ = strongSelf.context.sharedContext.navigateToForumThread(context: strongSelf.context, peerId: currentPeer.id, threadId: threadId, messageId: message.id, navigationController: navigationController, activateInput: nil, keepStack: .default).start() + } else { + let targetLocation: NavigateToChatControllerParams.Location + if case let .replyThread(message) = strongSelf.chatLocation { + targetLocation = .replyThread(message) + } else { + targetLocation = .peer(EnginePeer(currentPeer)) + } + + let currentPeerId = strongSelf.peerId + strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: targetLocation, subject: .message(id: .id(message.id), highlight: true, timecode: nil), keepStack: .always, useExisting: false, purposefulAction: { + var viewControllers = navigationController.viewControllers + var indexesToRemove = Set() + var keptCurrentChatController = false + var index: Int = viewControllers.count - 1 + for controller in viewControllers.reversed() { + if let controller = controller as? ChatController, case let .peer(peerId) = controller.chatLocation { + if peerId == currentPeerId && !keptCurrentChatController { + keptCurrentChatController = true + } else { + indexesToRemove.insert(index) + } + } else if controller is PeerInfoScreen { indexesToRemove.insert(index) } - } else if controller is PeerInfoScreen { - indexesToRemove.insert(index) + index -= 1 } - index -= 1 - } - for i in indexesToRemove.sorted().reversed() { - viewControllers.remove(at: i) - } - navigationController.setViewControllers(viewControllers, animated: false) - })) + for i in indexesToRemove.sorted().reversed() { + viewControllers.remove(at: i) + } + navigationController.setViewControllers(viewControllers, animated: false) + })) + } } }) }))) @@ -2298,36 +2309,40 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate items.append(.action(ContextMenuActionItem(text: strings.SharedMedia_ViewInChat, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/GoToMessage"), color: theme.contextMenu.primaryColor) }, action: { c, f in c.dismiss(completion: { if let strongSelf = self, let currentPeer = strongSelf.data?.peer, let navigationController = strongSelf.controller?.navigationController as? NavigationController { - let targetLocation: NavigateToChatControllerParams.Location - if case let .replyThread(message) = strongSelf.chatLocation { - targetLocation = .replyThread(message) + if let channel = currentPeer as? TelegramChannel, channel.flags.contains(.isForum), let threadId = message.threadId { + let _ = strongSelf.context.sharedContext.navigateToForumThread(context: strongSelf.context, peerId: currentPeer.id, threadId: threadId, messageId: message.id, navigationController: navigationController, activateInput: nil, keepStack: .default).start() } else { - targetLocation = .peer(EnginePeer(currentPeer)) - } - - let currentPeerId = strongSelf.peerId - strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: targetLocation, subject: .message(id: .id(message.id), highlight: true, timecode: nil), keepStack: .always, useExisting: false, purposefulAction: { - var viewControllers = navigationController.viewControllers - var indexesToRemove = Set() - var keptCurrentChatController = false - var index: Int = viewControllers.count - 1 - for controller in viewControllers.reversed() { - if let controller = controller as? ChatController, case let .peer(peerId) = controller.chatLocation { - if peerId == currentPeerId && !keptCurrentChatController { - keptCurrentChatController = true - } else { + let targetLocation: NavigateToChatControllerParams.Location + if case let .replyThread(message) = strongSelf.chatLocation { + targetLocation = .replyThread(message) + } else { + targetLocation = .peer(EnginePeer(currentPeer)) + } + + let currentPeerId = strongSelf.peerId + strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: targetLocation, subject: .message(id: .id(message.id), highlight: true, timecode: nil), keepStack: .always, useExisting: false, purposefulAction: { + var viewControllers = navigationController.viewControllers + var indexesToRemove = Set() + var keptCurrentChatController = false + var index: Int = viewControllers.count - 1 + for controller in viewControllers.reversed() { + if let controller = controller as? ChatController, case let .peer(peerId) = controller.chatLocation { + if peerId == currentPeerId && !keptCurrentChatController { + keptCurrentChatController = true + } else { + indexesToRemove.insert(index) + } + } else if controller is PeerInfoScreen { indexesToRemove.insert(index) } - } else if controller is PeerInfoScreen { - indexesToRemove.insert(index) + index -= 1 } - index -= 1 - } - for i in indexesToRemove.sorted().reversed() { - viewControllers.remove(at: i) - } - navigationController.setViewControllers(viewControllers, animated: false) - })) + for i in indexesToRemove.sorted().reversed() { + viewControllers.remove(at: i) + } + navigationController.setViewControllers(viewControllers, animated: false) + })) + } } }) })))