Various fixes

This commit is contained in:
Ilya Laktyushin 2020-12-19 03:16:15 +04:00
parent c4cd3c318a
commit f91cc7f744
22 changed files with 93 additions and 29 deletions

View File

@ -640,6 +640,9 @@ public final class TonContext {
#endif
public protocol ComposeController: ViewController {
}
public protocol ChatLocationContextHolder: class {
}

View File

@ -227,6 +227,7 @@ private final class AuthTransferScanScreenNode: ViewControllerTracingNode, UIScr
private let camera: Camera
private let codeDisposable = MetaDisposable()
private var torchDisposable: Disposable?
fileprivate let focusedCode = ValuePromise<CameraCode?>(ignoreRepeated: true)
private var focusedRect: CGRect?
@ -305,6 +306,13 @@ private final class AuthTransferScanScreenNode: ViewControllerTracingNode, UIScr
self.backgroundColor = self.presentationData.theme.list.plainBackgroundColor
self.torchDisposable = (self.camera.hasTorch
|> deliverOnMainQueue).start(next: { [weak self] hasTorch in
if let strongSelf = self {
strongSelf.torchButtonNode.isHidden = !hasTorch
}
})
self.addSubnode(self.previewNode)
self.addSubnode(self.fadeNode)
self.addSubnode(self.topDimNode)
@ -323,6 +331,7 @@ private final class AuthTransferScanScreenNode: ViewControllerTracingNode, UIScr
deinit {
self.codeDisposable.dispose()
self.torchDisposable?.dispose()
self.camera.stopCapture(invalidate: true)
}

View File

@ -93,6 +93,10 @@ private final class CameraContext {
self.session.commitConfiguration()
}
var hasTorch: Signal<Bool, NoError> {
return self.device.isFlashAvailable
}
func setTorchActive(_ active: Bool) {
self.device.setTorchActive(active)
}
@ -189,6 +193,21 @@ public final class Camera {
}
}
public var hasTorch: Signal<Bool, NoError> {
return Signal { subscriber in
let disposable = MetaDisposable()
self.queue.async {
if let context = self.contextRef?.takeUnretainedValue() {
disposable.set(context.hasTorch.start(next: { hasTorch in
subscriber.putNext(hasTorch)
subscriber.putCompletion()
}))
}
}
return disposable
}
}
public func attachPreviewNode(_ node: CameraPreviewNode) {
let nodeRef: Unmanaged<CameraPreviewNode> = Unmanaged.passRetained(node)
self.queue.async {

View File

@ -1799,8 +1799,20 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
}
@objc private func composePressed() {
let controller = self.context.sharedContext.makeComposeController(context: self.context)
(self.navigationController as? NavigationController)?.pushViewController(controller)
guard let navigationController = self.navigationController as? NavigationController else {
return
}
var hasComposeController = false
navigationController.viewControllers.forEach { controller in
if controller is ComposeController {
hasComposeController = true
}
}
if !hasComposeController {
let controller = self.context.sharedContext.makeComposeController(context: self.context)
navigationController.pushViewController(controller)
}
}
public override var keyShortcuts: [KeyShortcut] {

View File

@ -893,6 +893,14 @@ final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDelegate {
insets.left += layout.safeInsets.left
insets.right += layout.safeInsets.right
if isEditing {
if !layout.safeInsets.left.isZero {
insets.bottom += 34.0
} else {
insets.bottom += 49.0
}
}
transition.updateAlpha(node: self, alpha: isReorderingFilters ? 0.5 : 1.0)
self.isUserInteractionEnabled = !isReorderingFilters

View File

@ -853,7 +853,7 @@ public func channelVisibilityController(context: AccountContext, peerId: PeerId,
let revokeLinkDisposable = MetaDisposable()
actionsDisposable.add(revokeLinkDisposable)
actionsDisposable.add((context.account.viewTracker.peerView(peerId) |> filter { $0.cachedData != nil } |> take(1) |> mapToSignal { view -> Signal<Void, NoError> in
actionsDisposable.add((context.account.viewTracker.peerView(peerId) |> filter { $0.cachedData != nil } |> take(1) |> mapToSignal { view -> Signal<String?, NoError> in
return ensuredExistingPeerExportedInvitation(account: context.account, peerId: peerId)
}).start())

View File

@ -128,7 +128,7 @@ private enum BlockedPeersEntry: ItemListNodeEntry {
return ItemListPeerActionItem(presentationData: presentationData, icon: PresentationResourcesItemList.addPersonIcon(theme), title: text, sectionId: self.section, editing: false, action: {
arguments.addPeer()
})
case let .peerItem(_, theme, strings, dateTimeFormat, nameDisplayOrder, peer, editing, enabled):
case let .peerItem(_, _, strings, dateTimeFormat, nameDisplayOrder, peer, editing, enabled):
let revealOptions = ItemListPeerItemRevealOptions(options: [ItemListPeerItemRevealOption(type: .destructive, title: strings.BlockedUsers_Unblock, action: {
arguments.removePeer(peer.id)
})])
@ -219,8 +219,6 @@ public func blockedPeersController(context: AccountContext, blockedPeersContext:
let removePeerDisposable = MetaDisposable()
actionsDisposable.add(removePeerDisposable)
let peersPromise = Promise<[Peer]?>(nil)
let arguments = BlockedPeersControllerArguments(context: context, setPeerIdWithRevealedOptions: { peerId, fromPeerId in
updateState { state in
if (peerId == nil && fromPeerId == state.peerIdWithRevealedOptions) || (peerId != nil && fromPeerId == nil) {
@ -231,7 +229,7 @@ public func blockedPeersController(context: AccountContext, blockedPeersContext:
}
}, addPeer: {
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
let controller = context.sharedContext.makePeerSelectionController(PeerSelectionControllerParams(context: context, filter: [.onlyPrivateChats, .excludeSavedMessages, .removeSearchHeader, .excludeRecent], title: presentationData.strings.BlockedUsers_SelectUserTitle))
let controller = context.sharedContext.makePeerSelectionController(PeerSelectionControllerParams(context: context, filter: [.onlyPrivateChats, .excludeSavedMessages, .removeSearchHeader, .excludeRecent, .doNotSearchMessages], title: presentationData.strings.BlockedUsers_SelectUserTitle))
controller.peerSelected = { [weak controller] peerId in
guard let strongController = controller else {
return

View File

@ -15,6 +15,8 @@ private let blue = UIColor(rgb: 0x0078ff)
private let lightBlue = UIColor(rgb: 0x59c7f8)
private let green = UIColor(rgb: 0x33c659)
private let activeBlue = UIColor(rgb: 0x00a0b9)
private let purple = UIColor(rgb: 0x6b81f0)
private let pink = UIColor(rgb: 0xd75a76)
private let areaSize = CGSize(width: 440.0, height: 440.0)
private let blobSize = CGSize(width: 244.0, height: 244.0)

View File

@ -224,10 +224,11 @@ public func stringForMediaKind(_ kind: MessageContentKind, strings: Presentation
}
public func descriptionStringForMessage(contentSettings: ContentSettings, message: Message, strings: PresentationStrings, nameDisplayOrder: PresentationPersonNameOrder, accountPeerId: PeerId) -> (String, Bool) {
if !message.text.isEmpty {
let contentKind = messageContentKind(contentSettings: contentSettings, message: message, strings: strings, nameDisplayOrder: nameDisplayOrder, accountPeerId: accountPeerId)
if !message.text.isEmpty && ![.expiredImage, .expiredVideo].contains(contentKind.key) {
return (foldLineBreaks(message.text), false)
}
return stringForMediaKind(messageContentKind(contentSettings: contentSettings, message: message, strings: strings, nameDisplayOrder: nameDisplayOrder, accountPeerId: accountPeerId), strings: strings)
return stringForMediaKind(contentKind, strings: strings)
}
public func foldLineBreaks(_ text: String) -> String {

View File

@ -9778,7 +9778,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}
private func forwardMessages(messages: [Message], resetCurrent: Bool) {
var filter: ChatListNodePeersFilter = [.onlyWriteable, .includeSavedMessages, .excludeDisabled]
var filter: ChatListNodePeersFilter = [.onlyWriteable, .includeSavedMessages, .excludeDisabled, .doNotSearchMessages]
var hasPublicPolls = false
var hasPublicQuiz = false
for message in messages {

View File

@ -1528,7 +1528,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
selectionNode.updateSelected(selected, animated: false)
let selectionFrame = CGRect(origin: CGPoint(x: -offset, y: 0.0), size: CGSize(width: self.contentBounds.size.width, height: self.contentBounds.size.height))
selectionNode.frame = selectionFrame
selectionNode.updateLayout(size: selectionFrame.size)
selectionNode.updateLayout(size: selectionFrame.size, leftInset: self.safeInsets.left)
self.subnodeTransform = CATransform3DMakeTranslation(offset, 0.0, 0.0);
} else {
let selectionNode = ChatMessageSelectionNode(wallpaper: item.presentationData.theme.wallpaper, theme: item.presentationData.theme.theme, toggle: { [weak self] value in
@ -1539,7 +1539,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
let selectionFrame = CGRect(origin: CGPoint(x: -offset, y: 0.0), size: CGSize(width: self.contentBounds.size.width, height: self.contentBounds.size.height))
selectionNode.frame = selectionFrame
selectionNode.updateLayout(size: selectionFrame.size)
selectionNode.updateLayout(size: selectionFrame.size, leftInset: self.safeInsets.left)
self.addSubnode(selectionNode)
self.selectionNode = selectionNode
selectionNode.updateSelected(selected, animated: false)

View File

@ -2636,7 +2636,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode
let offset: CGFloat = params.leftInset + (incoming ? 42.0 : 0.0)
let selectionFrame = CGRect(origin: CGPoint(x: -offset, y: 0.0), size: CGSize(width: params.width, height: layout.contentSize.height))
strongSelf.selectionNode?.frame = selectionFrame
strongSelf.selectionNode?.updateLayout(size: selectionFrame.size)
strongSelf.selectionNode?.updateLayout(size: selectionFrame.size, leftInset: params.leftInset)
if let actionButtonsSizeAndApply = actionButtonsSizeAndApply {
var animated = false
@ -3446,7 +3446,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode
selectionNode.updateSelected(selected, animated: animated)
let selectionFrame = CGRect(origin: CGPoint(x: -offset, y: 0.0), size: CGSize(width: self.contentSize.width, height: self.contentSize.height))
selectionNode.frame = selectionFrame
selectionNode.updateLayout(size: selectionFrame.size)
selectionNode.updateLayout(size: selectionFrame.size, leftInset: self.safeInsets.left)
self.subnodeTransform = CATransform3DMakeTranslation(offset, 0.0, 0.0);
} else {
let selectionNode = ChatMessageSelectionNode(wallpaper: item.presentationData.theme.wallpaper, theme: item.presentationData.theme.theme, toggle: { [weak self] value in
@ -3462,7 +3462,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode
let selectionFrame = CGRect(origin: CGPoint(x: -offset, y: 0.0), size: CGSize(width: self.contentSize.width, height: self.contentSize.height))
selectionNode.frame = selectionFrame
selectionNode.updateLayout(size: selectionFrame.size)
selectionNode.updateLayout(size: selectionFrame.size, leftInset: self.safeInsets.left)
self.insertSubnode(selectionNode, belowSubnode: self.messageAccessibilityArea)
self.selectionNode = selectionNode
selectionNode.updateSelected(selected, animated: false)

View File

@ -452,7 +452,7 @@ class ChatMessageInstantVideoItemNode: ChatMessageItemView {
strongSelf.appliedItem = item
strongSelf.appliedForwardInfo = (forwardSource, forwardAuthorSignature)
let transition: ContainedViewLayoutTransition
if animation.isAnimated {
transition = .animated(duration: 0.2, curve: .spring)
@ -886,7 +886,7 @@ class ChatMessageInstantVideoItemNode: ChatMessageItemView {
if let selectionNode = self.selectionNode {
let selectionFrame = CGRect(origin: CGPoint(x: -offset, y: 0.0), size: CGSize(width: self.contentBounds.size.width, height: self.contentBounds.size.height))
selectionNode.frame = selectionFrame
selectionNode.updateLayout(size: selectionFrame.size)
selectionNode.updateLayout(size: selectionFrame.size, leftInset: self.safeInsets.left)
selectionNode.updateSelected(selected, animated: animated)
self.subnodeTransform = CATransform3DMakeTranslation(offset, 0.0, 0.0);
} else {
@ -897,7 +897,7 @@ class ChatMessageInstantVideoItemNode: ChatMessageItemView {
})
let selectionFrame = CGRect(origin: CGPoint(x: -offset, y: 0.0), size: CGSize(width: self.contentBounds.size.width, height: self.contentBounds.size.height))
selectionNode.frame = selectionFrame
selectionNode.updateLayout(size: selectionFrame.size)
selectionNode.updateLayout(size: selectionFrame.size, leftInset: self.safeInsets.left)
self.addSubnode(selectionNode)
self.selectionNode = selectionNode
selectionNode.updateSelected(selected, animated: false)

View File

@ -424,6 +424,7 @@ public final class ChatMessageItem: ListViewItem, CustomStringConvertible {
node.contentSize = layout.contentSize
node.insets = layout.insets
node.safeInsets = UIEdgeInsets(top: 0.0, left: params.leftInset, bottom: 0.0, right: params.rightInset)
node.updateSelectionState(animated: false)
node.updateHighlightedState(animated: false)
@ -493,6 +494,7 @@ public final class ChatMessageItem: ListViewItem, CustomStringConvertible {
completion(layout, { _ in
apply(animation, false)
if let nodeValue = node() as? ChatMessageItemView {
nodeValue.safeInsets = UIEdgeInsets(top: 0.0, left: params.leftInset, bottom: 0.0, right: params.rightInset)
nodeValue.updateSelectionState(animated: false)
nodeValue.updateHighlightedState(animated: false)
}

View File

@ -647,6 +647,7 @@ public class ChatMessageItemView: ListViewItemNode {
var item: ChatMessageItem?
var accessibilityData: ChatMessageAccessibilityData?
var safeInsets = UIEdgeInsets()
var awaitingAppliedReaction: (String?, () -> Void)?

View File

@ -50,8 +50,8 @@ final class ChatMessageSelectionNode: ASDisplayNode {
}
}
func updateLayout(size: CGSize) {
func updateLayout(size: CGSize, leftInset: CGFloat) {
let checkSize = CGSize(width: 32.0, height: 32.0)
self.checkNode.frame = CGRect(origin: CGPoint(x: 4.0, y: floor((size.height - checkSize.height) / 2.0)), size: checkSize)
self.checkNode.frame = CGRect(origin: CGPoint(x: 4.0 + leftInset, y: floor((size.height - checkSize.height) / 2.0)), size: checkSize)
}
}

View File

@ -673,9 +673,14 @@ class ChatMessageStickerItemNode: ChatMessageItemView {
replyInfoNode.frame = replyInfoFrame
strongSelf.replyBackgroundNode?.frame = replyBackgroundFrame ?? CGRect()
if let _ = item.controllerInteraction.selectionState, isEmoji {
replyInfoNode.alpha = 0.0
strongSelf.replyBackgroundNode?.alpha = 0.0
if isEmoji && !incoming {
if let _ = item.controllerInteraction.selectionState {
replyInfoNode.alpha = 0.0
strongSelf.replyBackgroundNode?.alpha = 0.0
} else {
replyInfoNode.alpha = 1.0
strongSelf.replyBackgroundNode?.alpha = 1.0
}
}
} else if let replyInfoNode = strongSelf.replyInfoNode {
replyInfoNode.removeFromSupernode()
@ -1007,7 +1012,7 @@ class ChatMessageStickerItemNode: ChatMessageItemView {
if let selectionNode = self.selectionNode {
let selectionFrame = CGRect(origin: CGPoint(x: -offset, y: 0.0), size: CGSize(width: self.contentBounds.size.width, height: self.contentBounds.size.height))
selectionNode.frame = selectionFrame
selectionNode.updateLayout(size: selectionFrame.size)
selectionNode.updateLayout(size: selectionFrame.size, leftInset: self.safeInsets.left)
selectionNode.updateSelected(selected, animated: animated)
self.subnodeTransform = CATransform3DMakeTranslation(offset, 0.0, 0.0);
} else {
@ -1018,7 +1023,7 @@ class ChatMessageStickerItemNode: ChatMessageItemView {
})
let selectionFrame = CGRect(origin: CGPoint(x: -offset, y: 0.0), size: CGSize(width: self.contentBounds.size.width, height: self.contentBounds.size.height))
selectionNode.frame = selectionFrame
selectionNode.updateLayout(size: selectionFrame.size)
selectionNode.updateLayout(size: selectionFrame.size, leftInset: self.safeInsets.left)
self.addSubnode(selectionNode)
self.selectionNode = selectionNode
selectionNode.updateSelected(selected, animated: false)

View File

@ -677,7 +677,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
if let previousAdditionalSideInsets = previousAdditionalSideInsets, previousAdditionalSideInsets.right != additionalSideInsets.right {
additionalOffset = (previousAdditionalSideInsets.right - additionalSideInsets.right) / 3.0
if case let .animated(duration, curve) = transition {
if case let .animated(duration, _) = transition {
transition = .animated(duration: 0.2, curve: .easeInOut)
}
}

View File

@ -15,7 +15,7 @@ import TelegramPermissionsUI
import AppBundle
import DeviceAccess
public class ComposeController: ViewController {
public class ComposeControllerImpl: ViewController, ComposeController {
private let context: AccountContext
private var contactsNode: ComposeControllerNode {

View File

@ -228,7 +228,8 @@ final class PeerSelectionControllerNode: ASDisplayNode {
if let requestOpenMessageFromSearch = self?.requestOpenMessageFromSearch {
requestOpenMessageFromSearch(peer, messageId)
}
}, addContact: nil, peerContextAction: nil, present: { _, _ in
}, addContact: nil, peerContextAction: nil, present: { [weak self] c, a in
self?.present(c, a)
}, presentInGlobalOverlay: { _, _ in
}, navigationController: nil), cancel: { [weak self] in
if let requestDeactivateSearch = self?.requestDeactivateSearch {

View File

@ -1176,7 +1176,7 @@ public final class SharedAccountContextImpl: SharedAccountContext {
}
public func makeComposeController(context: AccountContext) -> ViewController {
return ComposeController(context: context)
return ComposeControllerImpl(context: context)
}
public func makeProxySettingsController(context: AccountContext) -> ViewController {

View File

@ -48,6 +48,9 @@ public func parseInternalUrl(query: String) -> ParsedInternalUrl? {
if query.hasPrefix("s/") {
query = String(query[query.index(query.startIndex, offsetBy: 2)...])
}
if query.hasSuffix("/") {
query.removeLast()
}
if let components = URLComponents(string: "/" + query) {
var pathComponents = components.path.components(separatedBy: "/")
if !pathComponents.isEmpty {