Various fixes

This commit is contained in:
Ilya Laktyushin 2023-02-21 20:07:36 +04:00
parent 1e6c6d6091
commit f8ab3d037e
13 changed files with 107 additions and 59 deletions

View File

@ -623,6 +623,9 @@ public protocol ChatController: ViewController {
func hintPlayNextOutgoingGift()
var isSendButtonVisible: Bool { get }
var isSelectingMessagesUpdated: ((Bool) -> Void)? { get set }
func cancelSelectingMessages()
}
public protocol ChatMessagePreviewItemNode: AnyObject {

View File

@ -968,7 +968,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
strongSelf.setInlineChatList(location: .forum(peerId: channel.id))
}
} else {
if let threadId = threadId {
if case let .channel(channel) = peer, channel.flags.contains(.isForum), let threadId {
let _ = strongSelf.context.sharedContext.navigateToForumThread(context: strongSelf.context, peerId: peer.id, threadId: threadId, messageId: nil, navigationController: navigationController, activateInput: nil, keepStack: .never).start()
strongSelf.chatListDisplayNode.clearHighlightAnimated(true)
} else {
@ -1069,7 +1069,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
if case .chatList(.root) = strongSelf.location {
navigationAnimationOptions = .removeOnMasterDetails
}
if let threadId = threadId {
if case let .channel(channel) = actualPeer, channel.flags.contains(.isForum), let threadId {
let _ = strongSelf.context.sharedContext.navigateToForumThread(context: strongSelf.context, peerId: peer.id, threadId: threadId, messageId: messageId, navigationController: navigationController, activateInput: nil, keepStack: .never).start()
} else {
strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(actualPeer), subject: .message(id: .id(messageId), highlight: true, timecode: nil), purposefulAction: {
@ -1102,7 +1102,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
if case .chatList(.root) = strongSelf.location {
navigationAnimationOptions = .removeOnMasterDetails
}
if let threadId = threadId {
if case let .channel(channel) = peer, channel.flags.contains(.isForum), let threadId {
let _ = strongSelf.context.sharedContext.navigateToForumThread(context: strongSelf.context, peerId: peer.id, threadId: threadId, messageId: nil, navigationController: navigationController, activateInput: nil, keepStack: .never).start()
} else {
strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(peer), purposefulAction: { [weak self] in

View File

@ -492,7 +492,7 @@ open class GridNode: GridNodeScroller, UIScrollViewDelegate {
let effectiveWidth = gridLayout.size.width - itemInsets.left - itemInsets.right
let itemsInRow = Int(effectiveWidth / defaultItemSize.width)
let itemsInRow = max(1, Int(effectiveWidth / defaultItemSize.width))
let itemsInRowWidth = CGFloat(itemsInRow) * defaultItemSize.width
let remainingWidth = max(0.0, effectiveWidth - itemsInRowWidth)

View File

@ -713,6 +713,8 @@ private final class FeaturedStickersScreenNode: ViewControllerTracingNode {
itemSize.width -= 60.0
insets.left += 30.0
insets.right += 30.0
} else {
itemSize.width -= layout.safeInsets.left + layout.safeInsets.right
}
self.gridNode.transaction(GridNodeTransaction(deleteItems: [], insertItems: [], updateItems: [], scrollToItem: nil, updateLayout: GridNodeUpdateLayout(layout: GridNodeLayout(size: layout.size, insets: UIEdgeInsets(top: insets.top, left: insets.left + layout.safeInsets.left, bottom: insets.bottom + layout.safeInsets.bottom, right: insets.right + layout.safeInsets.right), preloadSize: 300.0, type: .fixed(itemSize: itemSize, fillWidth: nil, lineSpacing: 0.0, itemSpacing: nil)), transition: transition), itemTransition: .immediate, stationaryItems: .none, updateFirstIndexInSectionOffset: nil), completion: { _ in })

View File

@ -152,7 +152,7 @@ public final class HashtagSearchController: TelegramBaseController {
}
override public func loadDisplayNode() {
self.displayNode = HashtagSearchControllerNode(context: self.context, peer: self.peer, query: self.query, navigationBar: self.navigationBar, navigationController: self.navigationController as? NavigationController)
self.displayNode = HashtagSearchControllerNode(context: self.context, controller: self, peer: self.peer, query: self.query, navigationBar: self.navigationBar, navigationController: self.navigationController as? NavigationController)
if let chatController = self.controllerNode.chatController {
chatController.parentController = self
}

View File

@ -9,6 +9,9 @@ import SegmentedControlNode
import ChatListSearchItemHeader
final class HashtagSearchControllerNode: ASDisplayNode {
private let context: AccountContext
private weak var controller: HashtagSearchController?
private let navigationBar: NavigationBar?
private let segmentedControlNode: SegmentedControlNode
@ -16,15 +19,16 @@ final class HashtagSearchControllerNode: ASDisplayNode {
let chatController: ChatController?
private let context: AccountContext
private let query: String
private var containerLayout: (ContainerViewLayout, CGFloat)?
private var enqueuedTransitions: [(ChatListSearchContainerTransition, Bool)] = []
private var hasValidLayout = false
init(context: AccountContext, peer: EnginePeer?, query: String, navigationBar: NavigationBar?, navigationController: NavigationController?) {
init(context: AccountContext, controller: HashtagSearchController, peer: EnginePeer?, query: String, navigationBar: NavigationBar?, navigationController: NavigationController?) {
self.context = context
self.controller = controller
self.query = query
self.navigationBar = navigationBar
@ -74,6 +78,17 @@ final class HashtagSearchControllerNode: ASDisplayNode {
}
}
}
self.chatController?.isSelectingMessagesUpdated = { [weak self] isSelecting in
if let strongSelf = self {
let button: UIBarButtonItem? = isSelecting ? UIBarButtonItem(title: presentationData.strings.Common_Cancel, style: .done, target: self, action: #selector(strongSelf.cancelPressed)) : nil
strongSelf.controller?.navigationItem.setRightBarButton(button, animated: true)
}
}
}
@objc private func cancelPressed() {
self.chatController?.cancelSelectingMessages()
}
func updateThemeAndStrings(theme: PresentationTheme, strings: PresentationStrings) {

View File

@ -1803,6 +1803,15 @@ public func channelVisibilityController(context: AccountContext, updatedPresenta
var footerItem: ItemListControllerFooterItem?
var isGroup = false
if let peer = peer as? TelegramChannel {
if case .group = peer.info {
isGroup = true
}
} else if let _ = peer as? TelegramGroup {
isGroup = true
}
var rightNavigationButton: ItemListNavigationButton?
if case .revokeNames = mode {
let count = Int32(publicChannelsToRevoke?.count ?? 0)
@ -1993,7 +2002,13 @@ public func channelVisibilityController(context: AccountContext, updatedPresenta
_ = (ApplicationSpecificNotice.getSetPublicChannelLink(accountManager: context.sharedContext.accountManager) |> deliverOnMainQueue).start(next: { showAlert in
if showAlert {
presentControllerImpl?(textAlertController(context: context, updatedPresentationData: updatedPresentationData, title: nil, text: presentationData.strings.Group_Edit_PrivatePublicLinkAlert, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: invokeAction)]), nil)
let text: String
if isGroup {
text = presentationData.strings.Group_Edit_PrivatePublicLinkAlert
} else {
text = presentationData.strings.Channel_Edit_PrivatePublicLinkAlert
}
presentControllerImpl?(textAlertController(context: context, updatedPresentationData: updatedPresentationData, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: invokeAction)]), nil)
} else {
invokeAction()
}
@ -2014,15 +2029,6 @@ public func channelVisibilityController(context: AccountContext, updatedPresenta
rightNavigationButton = ItemListNavigationButton(content: .none, style: .activity, enabled: true, action: {})
}
var isGroup = false
if let peer = peer as? TelegramChannel {
if case .group = peer.info {
isGroup = true
}
} else if let _ = peer as? TelegramGroup {
isGroup = true
}
let leftNavigationButton: ItemListNavigationButton?
switch mode {
case .initialSetup:

View File

@ -13,6 +13,9 @@ import AccountContext
public func autodownloadDataSizeString(_ size: Int64, decimalSeparator: String = ".") -> String {
if size >= 1024 * 1024 * 1024 {
var remainder = (size % (1024 * 1024 * 1024)) / (1024 * 1024 * 102)
if remainder == 10 {
remainder = 9
}
while remainder != 0 && remainder % 10 == 0 {
remainder /= 10
}
@ -24,6 +27,9 @@ public func autodownloadDataSizeString(_ size: Int64, decimalSeparator: String =
}
} else if size >= 1024 * 1024 {
var remainder = (size % (1024 * 1024)) / (1024 * 102)
if remainder == 10 {
remainder = 9
}
while remainder != 0 && remainder % 10 == 0 {
remainder /= 10
}

View File

@ -245,10 +245,11 @@ func cachedStickerPack(transaction: Transaction, reference: StickerPackReference
}
}
case let .name(shortName):
let shortName = shortName.lowercased()
for namespace in namespaces {
for info in transaction.getItemCollectionsInfos(namespace: namespace) {
if let info = info.1 as? StickerPackCollectionInfo {
if info.shortName == shortName {
if info.shortName.lowercased() == shortName {
let items = transaction.getItemCollectionItems(collectionId: info.id)
if !items.isEmpty {
return (info, items.compactMap { $0 as? StickerPackItem }, true)

View File

@ -513,6 +513,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
var updatedClosedPinnedMessageId: ((MessageId) -> Void)?
var requestedUnpinAllMessages: ((Int, MessageId) -> Void)?
public var isSelectingMessagesUpdated: ((Bool) -> Void)?
private let scrolledToMessageId = ValuePromise<ScrolledToMessageId?>(nil, ignoreRepeated: true)
private var scrolledToMessageIdValue: ScrolledToMessageId? = nil {
didSet {
@ -11455,6 +11457,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
self.recordingActivityPromise.set(recordingActivityValue)
}
if (self.presentationInterfaceState.interfaceState.selectionState == nil) != (updatedChatPresentationInterfaceState.interfaceState.selectionState == nil) {
self.isSelectingMessagesUpdated?(updatedChatPresentationInterfaceState.interfaceState.selectionState != nil)
}
self.presentationInterfaceState = updatedChatPresentationInterfaceState
self.updateSlowmodeStatus()
@ -11678,6 +11684,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}), in: .current)
}
public func cancelSelectingMessages() {
self.navigationButtonAction(.cancelMessageSelection)
}
private func navigationButtonAction(_ action: ChatNavigationButtonAction) {
switch action {
case .spacer, .toggleInfoPanel:

View File

@ -2654,7 +2654,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
context: self.context,
currentInputData: inputMediaNodeData,
updatedInputData: self.inputMediaNodeDataPromise.get(),
defaultToEmojiTab: !self.chatPresentationInterfaceState.interfaceState.effectiveInputState.inputText.string.isEmpty || self.openStickersBeginWithEmoji,
defaultToEmojiTab: !self.chatPresentationInterfaceState.interfaceState.effectiveInputState.inputText.string.isEmpty || self.chatPresentationInterfaceState.interfaceState.forwardMessageIds != nil || self.openStickersBeginWithEmoji,
controllerInteraction: self.controllerInteraction,
interfaceInteraction: self.interfaceInteraction,
chatPeerId: peerId

View File

@ -354,14 +354,14 @@ func inputTextPanelStateForChatPresentationInterfaceState(_ chatPresentationInte
let isTextEmpty = chatPresentationInterfaceState.interfaceState.composeInputState.inputText.length == 0
if chatPresentationInterfaceState.interfaceState.forwardMessageIds == nil {
if isTextEmpty && chatPresentationInterfaceState.hasScheduledMessages {
let hasForward = chatPresentationInterfaceState.interfaceState.forwardMessageIds != nil
if isTextEmpty && chatPresentationInterfaceState.hasScheduledMessages && !hasForward {
accessoryItems.append(.scheduledMessages)
}
var stickersEnabled = true
let stickersAreEmoji = !isTextEmpty
var stickersAreEmoji = !isTextEmpty
if let peer = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramChannel {
if isTextEmpty, case .broadcast = peer.info, canSendMessagesToPeer(peer) {
@ -375,15 +375,18 @@ func inputTextPanelStateForChatPresentationInterfaceState(_ chatPresentationInte
stickersEnabled = false
}
}
if isTextEmpty && chatPresentationInterfaceState.hasBots && chatPresentationInterfaceState.hasBotCommands {
if isTextEmpty && chatPresentationInterfaceState.hasBots && chatPresentationInterfaceState.hasBotCommands && !hasForward {
accessoryItems.append(.commands)
}
if !canSendTextMessages {
if stickersEnabled && !stickersAreEmoji {
if stickersEnabled && !stickersAreEmoji && !hasForward {
accessoryItems.append(.input(isEnabled: true, inputMode: .stickers))
}
} else {
stickersAreEmoji = stickersAreEmoji || hasForward
if stickersEnabled {
accessoryItems.append(.input(isEnabled: true, inputMode: stickersAreEmoji ? .emoji : .stickers))
} else {
@ -394,7 +397,7 @@ func inputTextPanelStateForChatPresentationInterfaceState(_ chatPresentationInte
if isTextEmpty, let message = chatPresentationInterfaceState.keyboardButtonsMessage, let _ = message.visibleButtonKeyboardMarkup, chatPresentationInterfaceState.interfaceState.messageActionsState.dismissedButtonKeyboardMessageId != message.id {
accessoryItems.append(.botInput(isEnabled: true, inputMode: .bot))
}
}
return ChatTextInputPanelState(accessoryItems: accessoryItems, contextPlaceholder: contextPlaceholder, mediaRecordingState: chatPresentationInterfaceState.inputTextPanelState.mediaRecordingState)
}
}

View File

@ -162,10 +162,12 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur
}
dismissInput()
navigationController?.pushViewController(controller)
case let .gameStart(peerId, game):
case let .gameStart(botPeerId, game):
let controller = context.sharedContext.makePeerSelectionController(PeerSelectionControllerParams(context: context, filter: [.onlyManageable, .excludeDisabled, .excludeRecent, .doNotSearchMessages], hasContactSelector: false, title: presentationData.strings.Bot_AddToChat_Title, selectForumThreads: true))
controller.peerSelected = { [weak controller] peer, _ in
let peerId = peer.id
let _ = peer.id
let _ = botPeerId
let _ = game
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
let text: String
if let peer = peer as? TelegramUser {