diff --git a/TelegramUI/AutomaticMediaDownloadSettings.swift b/TelegramUI/AutomaticMediaDownloadSettings.swift index 6bf4e20150..1eedf4a8d8 100644 --- a/TelegramUI/AutomaticMediaDownloadSettings.swift +++ b/TelegramUI/AutomaticMediaDownloadSettings.swift @@ -102,7 +102,7 @@ public struct AutomaticMediaDownloadSettings: PreferencesEntry, Equatable { video: AutomaticMediaDownloadCategory(cellular: false, wifi: false, sizeLimit: 1 * 1024 * 1024), file: AutomaticMediaDownloadCategory(cellular: false, wifi: false, sizeLimit: 1 * 1024 * 1024), voiceMessage: AutomaticMediaDownloadCategory(cellular: true, wifi: true, sizeLimit: 1 * 1024 * 1024), - videoMessage: AutomaticMediaDownloadCategory(cellular: true, wifi: true, sizeLimit: 1 * 1024 * 1024), + videoMessage: AutomaticMediaDownloadCategory(cellular: true, wifi: true, sizeLimit: 4 * 1024 * 1024), saveDownloadedPhotos: false ) return AutomaticMediaDownloadSettings(masterEnabled: true, peers: AutomaticMediaDownloadPeers( @@ -202,10 +202,14 @@ private func categoryForPeerAndMedia(settings: AutomaticMediaDownloadSettings, p switch attribute { case let .Video(_, _, flags): if flags.contains(.instantRoundVideo) { - return (categories.videoMessage, file.size.flatMap(Int32.init)) + var category = categories.videoMessage + category.sizeLimit = max(category.sizeLimit, 4 * 1024 * 1024) + return (category, file.size.flatMap(Int32.init)) } else { if file.isAnimated { - return (categories.videoMessage, file.size.flatMap(Int32.init)) + var category = categories.videoMessage + category.sizeLimit = max(category.sizeLimit, 1 * 1024 * 1024) + return (category, file.size.flatMap(Int32.init)) } else { return (categories.video, file.size.flatMap(Int32.init)) } diff --git a/TelegramUI/CallControllerNode.swift b/TelegramUI/CallControllerNode.swift index 4e966cda17..bf8bcc13be 100644 --- a/TelegramUI/CallControllerNode.swift +++ b/TelegramUI/CallControllerNode.swift @@ -313,6 +313,8 @@ final class CallControllerNode: ASDisplayNode { self.containerNode.layer.animateScale(from: 1.0, to: 1.04, duration: 0.3, removeOnCompletion: false, completion: { _ in completion() }) + } else { + completion() } } diff --git a/TelegramUI/ChatController.swift b/TelegramUI/ChatController.swift index 9f612de345..0389ef5d9a 100644 --- a/TelegramUI/ChatController.swift +++ b/TelegramUI/ChatController.swift @@ -295,12 +295,7 @@ public final class ChatController: TelegramController, KeyShortcutResponder, UID } } - if case .stream = mode { - strongSelf.debugStreamSingleVideo(message.id) - return true - } - - return openChatMessage(account: account, message: message, standalone: false, reverseMessageGalleryOrder: false, navigationController: strongSelf.navigationController as? NavigationController, dismissInput: { + return openChatMessage(account: account, message: message, standalone: false, reverseMessageGalleryOrder: false, stream: mode == .stream, navigationController: strongSelf.navigationController as? NavigationController, dismissInput: { self?.chatDisplayNode.dismissInput() }, present: { c, a in self?.present(c, in: .window(.root), with: a, blockInteraction: true) @@ -2565,10 +2560,10 @@ public final class ChatController: TelegramController, KeyShortcutResponder, UID } else if let group = peer as? TelegramGroup { if group.flags.contains(.adminsEnabled) { switch group.role { - case .creator, .admin: - canManagePin = true - default: - canManagePin = false + case .creator, .admin: + canManagePin = true + default: + canManagePin = false } } else { canManagePin = true @@ -4194,7 +4189,11 @@ public final class ChatController: TelegramController, KeyShortcutResponder, UID } } - if case let .peer(peerId) = self.chatLocation, messageLocation.messageId.peerId == peerId { + if case let .peer(peerId) = self.chatLocation, messageLocation.messageId.peerId != peerId { + if let navigationController = self.navigationController as? NavigationController { + navigateToChatController(navigationController: navigationController, account: self.account, chatLocation: .peer(messageLocation.messageId.peerId), messageId: messageLocation.messageId) + } + } else if case let .peer(peerId) = self.chatLocation, messageLocation.messageId.peerId == peerId { if let fromIndex = fromIndex { if let _ = fromId, rememberInStack { self.historyNavigationStack.add(fromIndex) @@ -4216,36 +4215,72 @@ public final class ChatController: TelegramController, KeyShortcutResponder, UID } let historyView = chatHistoryViewForLocation(.InitialSearch(location: searchLocation, count: 50), account: self.account, chatLocation: self.chatLocation, fixedCombinedReadStates: nil, tagMask: nil, additionalData: []) let signal = historyView - |> mapToSignal { historyView -> Signal in + |> mapToSignal { historyView -> Signal<(MessageIndex?, Bool), NoError> in switch historyView { case .Loading: - return .complete() + return .single((nil, true)) case let .HistoryView(view, _, _, _, _): for entry in view.entries { if case let .MessageEntry(message, _, _, _) = entry { if message.id == messageLocation.messageId { - return .single(MessageIndex(message)) + return .single((MessageIndex(message), false)) } } } if case let .index(index) = searchLocation { - return .single(index) + return .single((index, false)) } - return .single(nil) + return .single((nil, false)) } } - |> take(1) + |> take(until: { index in + return SignalTakeAction(passthrough: true, complete: !index.1) + }) + + var cancelImpl: (() -> Void)? + let presentationData = self.presentationData + let progressSignal = Signal { [weak self] subscriber in + let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: { + cancelImpl?() + })) + self?.present(controller, in: .window(.root)) + return ActionDisposable { [weak controller] in + Queue.mainQueue().async() { + controller?.dismiss() + } + } + } + |> runOn(Queue.mainQueue()) + |> delay(0.15, queue: Queue.mainQueue()) + let progressDisposable = MetaDisposable() + var progressStarted = false self.messageIndexDisposable.set((signal + |> afterDisposed { + Queue.mainQueue().async { + progressDisposable.dispose() + } + } |> deliverOnMainQueue).start(next: { [weak self] index in - if let strongSelf = self, let index = index { + if let strongSelf = self, let index = index.0 { strongSelf.chatDisplayNode.historyNode.scrollToMessage(from: fromIndex, to: index, animated: animated, scrollPosition: scrollPosition) completion?() + } else if index.1 { + if !progressStarted { + progressStarted = true + progressDisposable.set(progressSignal.start()) + } } }, completed: { [weak self] in if let strongSelf = self { strongSelf.loadingMessage.set(false) } })) + cancelImpl = { [weak self] in + if let strongSelf = self { + strongSelf.loadingMessage.set(false) + strongSelf.messageIndexDisposable.set(nil) + } + } } } else { completion?() diff --git a/TelegramUI/ChatInterfaceStateContextMenus.swift b/TelegramUI/ChatInterfaceStateContextMenus.swift index e66585de45..580cd70f7a 100644 --- a/TelegramUI/ChatInterfaceStateContextMenus.swift +++ b/TelegramUI/ChatInterfaceStateContextMenus.swift @@ -215,14 +215,14 @@ func contextMenuForChatPresentationIntefaceState(chatPresentationInterfaceState: } else if let group = messages[0].peers[messages[0].id.peerId] as? TelegramGroup { if !isAction { if group.flags.contains(.adminsEnabled) { - canPin = true - } else { switch group.role { case .creator, .admin: canPin = true default: canPin = false } + } else { + canPin = true } } } else if let _ = messages[0].peers[messages[0].id.peerId] as? TelegramUser, chatPresentationInterfaceState.explicitelyCanPinMessages { diff --git a/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift b/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift index 07e76cc017..4f3eec2696 100644 --- a/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift +++ b/TelegramUI/ChatMessageInteractiveInstantVideoNode.swift @@ -47,6 +47,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { private var status: FileMediaResourceMediaStatus? private let playbackStatusDisposable = MetaDisposable() + private let fetchedThumbnailDisposable = MetaDisposable() private var shouldAcquireVideoContext: Bool { if case .visible = self.visibility { @@ -97,6 +98,7 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { deinit { self.fetchDisposable.dispose() self.playbackStatusDisposable.dispose() + self.fetchedThumbnailDisposable.dispose() } override func didLoad() { @@ -288,6 +290,14 @@ class ChatMessageInteractiveInstantVideoNode: ASDisplayNode { })) } + if let updatedFile = updatedFile, updatedMedia { + if let resource = updatedFile.previewRepresentations.first?.resource { + strongSelf.fetchedThumbnailDisposable.set(fetchedMediaResource(postbox: item.account.postbox, reference: FileMediaReference.message(message: MessageReference(item.message), media: updatedFile).resourceReference(resource)).start()) + } else { + strongSelf.fetchedThumbnailDisposable.set(nil) + } + } + dateAndStatusApply(false) switch layoutData { case let .unconstrained(width): diff --git a/TelegramUI/GalleryController.swift b/TelegramUI/GalleryController.swift index daa0e0ae1e..9dd78f77c1 100644 --- a/TelegramUI/GalleryController.swift +++ b/TelegramUI/GalleryController.swift @@ -132,7 +132,7 @@ func galleryItemForEntry(account: Account, presentationData: PresentationData, e if file.isVideo { let content: UniversalVideoContent if file.isAnimated { - content = NativeVideoContent(id: .message(message.id, message.stableId + 1, file.fileId), fileReference: .message(message: MessageReference(message), media: file), streamVideo: streamVideos, loopVideo: true, enableSound: false) + content = NativeVideoContent(id: .message(message.id, message.stableId + 1, file.fileId), fileReference: .message(message: MessageReference(message), media: file), streamVideo: true, loopVideo: true, enableSound: false) } else { if true || (file.mimeType == "video/mpeg4" || file.mimeType == "video/mov" || file.mimeType == "video/mp4") { content = NativeVideoContent(id: .message(message.id, message.stableId, file.fileId), fileReference: .message(message: MessageReference(message), media: file), streamVideo: streamVideos, loopVideo: loopVideos) @@ -307,7 +307,7 @@ class GalleryController: ViewController { |> mapToSignal { message -> Signal in switch source { case .peerMessagesAtId: - if !streamSingleVideo, let tags = tagsForMessage(message!) { + if let tags = tagsForMessage(message!) { let view = account.postbox.aroundMessageHistoryViewForLocation(.peer(message!.id.peerId), index: .message(MessageIndex(message!)), anchorIndex: .message(MessageIndex(message!)), count: 50, clipHoles: false, fixedCombinedReadStates: nil, topTaggedMessageIdNamespaces: [], tagMask: tags, orderStatistics: [.combinedLocation]) return view diff --git a/TelegramUI/HorizontalPeerItem.swift b/TelegramUI/HorizontalPeerItem.swift index bfe8aa812c..4d6d5efa79 100644 --- a/TelegramUI/HorizontalPeerItem.swift +++ b/TelegramUI/HorizontalPeerItem.swift @@ -124,9 +124,9 @@ final class HorizontalPeerItemNode: ListViewItemNode { let itemTheme: SelectablePeerNodeTheme switch item.mode { case .list: - itemTheme = SelectablePeerNodeTheme(textColor: item.theme.list.itemPrimaryTextColor, secretTextColor: .green, selectedTextColor: item.theme.list.itemAccentColor, checkBackgroundColor: item.theme.list.plainBackgroundColor, checkFillColor: item.theme.list.itemAccentColor, checkColor: item.theme.list.plainBackgroundColor) + itemTheme = SelectablePeerNodeTheme(textColor: item.theme.list.itemPrimaryTextColor, secretTextColor: item.theme.chatList.secretTitleColor, selectedTextColor: item.theme.list.itemAccentColor, checkBackgroundColor: item.theme.list.plainBackgroundColor, checkFillColor: item.theme.list.itemAccentColor, checkColor: item.theme.list.plainBackgroundColor) case .actionSheet: - itemTheme = SelectablePeerNodeTheme(textColor: item.theme.actionSheet.primaryTextColor, secretTextColor: .green, selectedTextColor: item.theme.actionSheet.controlAccentColor, checkBackgroundColor: item.theme.actionSheet.opaqueItemBackgroundColor, checkFillColor: item.theme.actionSheet.controlAccentColor, checkColor: item.theme.actionSheet.opaqueItemBackgroundColor) + itemTheme = SelectablePeerNodeTheme(textColor: item.theme.actionSheet.primaryTextColor, secretTextColor: item.theme.chatList.secretTitleColor, selectedTextColor: item.theme.actionSheet.controlAccentColor, checkBackgroundColor: item.theme.actionSheet.opaqueItemBackgroundColor, checkFillColor: item.theme.actionSheet.controlAccentColor, checkColor: item.theme.actionSheet.opaqueItemBackgroundColor) } let currentBadgeBackgroundImage: UIImage? let badgeAttributedString: NSAttributedString diff --git a/TelegramUI/OpenChatMessage.swift b/TelegramUI/OpenChatMessage.swift index 4f90f3b8d7..2f58c518d0 100644 --- a/TelegramUI/OpenChatMessage.swift +++ b/TelegramUI/OpenChatMessage.swift @@ -20,7 +20,7 @@ private enum ChatMessageGalleryControllerData { case chatAvatars(AvatarGalleryController, Media) } -private func chatMessageGalleryControllerData(account: Account, message: Message, navigationController: NavigationController?, standalone: Bool, reverseMessageGalleryOrder: Bool, synchronousLoad: Bool) -> ChatMessageGalleryControllerData? { +private func chatMessageGalleryControllerData(account: Account, message: Message, navigationController: NavigationController?, standalone: Bool, reverseMessageGalleryOrder: Bool, stream: Bool, synchronousLoad: Bool) -> ChatMessageGalleryControllerData? { var galleryMedia: Media? var otherMedia: Media? var instantPageMedia: (TelegramMediaWebpage, [InstantPageGalleryEntry])? @@ -118,7 +118,7 @@ private func chatMessageGalleryControllerData(account: Account, message: Message let gallery = SecretMediaPreviewController(account: account, messageId: message.id) return .secretGallery(gallery) } else { - let gallery = GalleryController(account: account, source: standalone ? .standaloneMessage(message) : .peerMessagesAtId(message.id), invertItemOrder: reverseMessageGalleryOrder, synchronousLoad: synchronousLoad, replaceRootController: { [weak navigationController] controller, ready in + let gallery = GalleryController(account: account, source: standalone ? .standaloneMessage(message) : .peerMessagesAtId(message.id), invertItemOrder: reverseMessageGalleryOrder, streamSingleVideo: stream, synchronousLoad: synchronousLoad, replaceRootController: { [weak navigationController] controller, ready in navigationController?.replaceTopController(controller, animated: false, ready: ready) }, baseNavigationController: navigationController) return .gallery(gallery) @@ -138,7 +138,7 @@ enum ChatMessagePreviewControllerData { } func chatMessagePreviewControllerData(account: Account, message: Message, standalone: Bool, reverseMessageGalleryOrder: Bool, navigationController: NavigationController?) -> ChatMessagePreviewControllerData? { - if let mediaData = chatMessageGalleryControllerData(account: account, message: message, navigationController: navigationController, standalone: standalone, reverseMessageGalleryOrder: reverseMessageGalleryOrder, synchronousLoad: true) { + if let mediaData = chatMessageGalleryControllerData(account: account, message: message, navigationController: navigationController, standalone: standalone, reverseMessageGalleryOrder: reverseMessageGalleryOrder, stream: false, synchronousLoad: true) { switch mediaData { case let .gallery(gallery): return .gallery(gallery) @@ -151,8 +151,8 @@ func chatMessagePreviewControllerData(account: Account, message: Message, standa return nil } -func openChatMessage(account: Account, message: Message, standalone: Bool, reverseMessageGalleryOrder: Bool, navigationController: NavigationController?, modal: Bool = false, dismissInput: @escaping () -> Void, present: @escaping (ViewController, Any?) -> Void, transitionNode: @escaping (MessageId, Media) -> (ASDisplayNode, () -> UIView?)?, addToTransitionSurface: @escaping (UIView) -> Void, openUrl: @escaping (String) -> Void, openPeer: @escaping (Peer, ChatControllerInteractionNavigateToPeer) -> Void, callPeer: @escaping (PeerId) -> Void, enqueueMessage: @escaping (EnqueueMessage) -> Void, sendSticker: ((FileMediaReference) -> Void)?, setupTemporaryHiddenMedia: @escaping (Signal, Int, Media) -> Void, chatAvatarHiddenMedia: @escaping (Signal, Media) -> Void) -> Bool { - if let mediaData = chatMessageGalleryControllerData(account: account, message: message, navigationController: navigationController, standalone: standalone, reverseMessageGalleryOrder: reverseMessageGalleryOrder, synchronousLoad: false) { +func openChatMessage(account: Account, message: Message, standalone: Bool, reverseMessageGalleryOrder: Bool, stream: Bool = false, navigationController: NavigationController?, modal: Bool = false, dismissInput: @escaping () -> Void, present: @escaping (ViewController, Any?) -> Void, transitionNode: @escaping (MessageId, Media) -> (ASDisplayNode, () -> UIView?)?, addToTransitionSurface: @escaping (UIView) -> Void, openUrl: @escaping (String) -> Void, openPeer: @escaping (Peer, ChatControllerInteractionNavigateToPeer) -> Void, callPeer: @escaping (PeerId) -> Void, enqueueMessage: @escaping (EnqueueMessage) -> Void, sendSticker: ((FileMediaReference) -> Void)?, setupTemporaryHiddenMedia: @escaping (Signal, Int, Media) -> Void, chatAvatarHiddenMedia: @escaping (Signal, Media) -> Void) -> Bool { + if let mediaData = chatMessageGalleryControllerData(account: account, message: message, navigationController: navigationController, standalone: standalone, reverseMessageGalleryOrder: reverseMessageGalleryOrder, stream: stream, synchronousLoad: false) { switch mediaData { case let .url(url): openUrl(url) diff --git a/TelegramUI/PhotoResources.swift b/TelegramUI/PhotoResources.swift index 432fb5f4d7..ac630ddeed 100644 --- a/TelegramUI/PhotoResources.swift +++ b/TelegramUI/PhotoResources.swift @@ -1394,8 +1394,9 @@ func internalMediaGridMessageVideo(postbox: Postbox, videoReference: FileMediaRe } telegramFastBlur(Int32(thumbnailContextSize.width), Int32(thumbnailContextSize.height), Int32(thumbnailContext.bytesPerRow), thumbnailContext.bytes) - if true || initialThumbnailContextFittingSize.width < arguments.drawingSize.width * 0.5 { - let thumbnailContextFittingSize = CGSize(width: floor(arguments.drawingSize.width * 0.5), height: floor(arguments.drawingSize.width * 0.5)) + let thumbnailContextFittingSize = CGSize(width: floor(arguments.drawingSize.width * 0.5), height: floor(arguments.drawingSize.width * 0.5)) + + if thumbnailContextFittingSize.width > thumbnailContextSize.width { let additionalContextSize = thumbnailContextFittingSize let additionalBlurContext = DrawingContext(size: additionalContextSize, scale: 1.0) additionalBlurContext.withFlippedContext { c in diff --git a/TelegramUI/SelectablePeerNode.swift b/TelegramUI/SelectablePeerNode.swift index b387b1dff9..5c69783b64 100644 --- a/TelegramUI/SelectablePeerNode.swift +++ b/TelegramUI/SelectablePeerNode.swift @@ -133,7 +133,7 @@ final class SelectablePeerNode: ASDisplayNode { self.currentSelected = selected if let attributedText = self.textNode.attributedText { - self.textNode.attributedText = NSAttributedString(string: attributedText.string, font: textFont, textColor: selected ? self.theme.selectedTextColor : self.theme.textColor, paragraphAlignment: .center) + self.textNode.attributedText = NSAttributedString(string: attributedText.string, font: textFont, textColor: selected ? self.theme.selectedTextColor : (self.peer?.peerId.namespace == Namespaces.Peer.SecretChat ? self.theme.secretTextColor : self.theme.textColor), paragraphAlignment: .center) } if selected { diff --git a/TelegramUI/ShareControllerNode.swift b/TelegramUI/ShareControllerNode.swift index 8212e014f5..f3f85a8f5b 100644 --- a/TelegramUI/ShareControllerNode.swift +++ b/TelegramUI/ShareControllerNode.swift @@ -142,20 +142,20 @@ final class ShareControllerNode: ViewControllerTracingNode, UIScrollViewDelegate self.controllerInteraction = ShareControllerInteraction(togglePeer: { [weak self] peer, search in if let strongSelf = self { var added = false - if strongSelf.controllerInteraction!.selectedPeerIds.contains(peer.id) { - strongSelf.controllerInteraction!.selectedPeerIds.remove(peer.id) - strongSelf.controllerInteraction!.selectedPeers = strongSelf.controllerInteraction!.selectedPeers.filter({ $0.id != peer.id }) + if strongSelf.controllerInteraction!.selectedPeerIds.contains(peer.peerId) { + strongSelf.controllerInteraction!.selectedPeerIds.remove(peer.peerId) + strongSelf.controllerInteraction!.selectedPeers = strongSelf.controllerInteraction!.selectedPeers.filter({ $0.peerId != peer.peerId }) } else { - strongSelf.controllerInteraction!.selectedPeerIds.insert(peer.id) + strongSelf.controllerInteraction!.selectedPeerIds.insert(peer.peerId) strongSelf.controllerInteraction!.selectedPeers.append(peer) - strongSelf.contentNode?.setEnsurePeerVisibleOnLayout(peer.id) + strongSelf.contentNode?.setEnsurePeerVisibleOnLayout(peer.peerId) added = true } if search && added { strongSelf.controllerInteraction!.foundPeers = strongSelf.controllerInteraction!.foundPeers.filter { otherPeer in - return peer.id != otherPeer.id + return peer.peerId != otherPeer.peerId } strongSelf.controllerInteraction!.foundPeers.append(peer) strongSelf.peersContentNode?.updateFoundPeers() @@ -445,7 +445,7 @@ final class ShareControllerNode: ViewControllerTracingNode, UIScrollViewDelegate transition.updateAlpha(node: self.actionSeparatorNode, alpha: 0.0) transition.updateAlpha(node: self.actionsBackgroundNode, alpha: 0.0) - if let signal = self.share?(self.inputFieldNode.text, self.controllerInteraction!.selectedPeers.map { $0.id }) { + if let signal = self.share?(self.inputFieldNode.text, self.controllerInteraction!.selectedPeers.map { $0.peerId }) { self.transitionToContentNode(ShareLoadingContainerNode(theme: self.presentationData.theme, forceNativeAppearance: true), fastOut: true) let timestamp = CACurrentMediaTime() var wasDone = false diff --git a/TelegramUI/ShareControllerPeerGridItem.swift b/TelegramUI/ShareControllerPeerGridItem.swift index 29ba374601..6fc25a8d1b 100644 --- a/TelegramUI/ShareControllerPeerGridItem.swift +++ b/TelegramUI/ShareControllerPeerGridItem.swift @@ -6,12 +6,12 @@ import AsyncDisplayKit import Postbox final class ShareControllerInteraction { - var foundPeers: [Peer] = [] + var foundPeers: [RenderedPeer] = [] var selectedPeerIds = Set() - var selectedPeers: [Peer] = [] - let togglePeer: (Peer, Bool) -> Void + var selectedPeers: [RenderedPeer] = [] + let togglePeer: (RenderedPeer, Bool) -> Void - init(togglePeer: @escaping (Peer, Bool) -> Void) { + init(togglePeer: @escaping (RenderedPeer, Bool) -> Void) { self.togglePeer = togglePeer } } @@ -136,7 +136,7 @@ final class ShareControllerPeerGridItemNode: GridItemNode { if let strongSelf = self { if let (_, peer, search) = strongSelf.currentState { if let actualPeer = peer.peers[peer.peerId] { - strongSelf.controllerInteraction?.togglePeer(actualPeer, search) + strongSelf.controllerInteraction?.togglePeer(peer, search) } } } diff --git a/TelegramUI/ShareControllerRecentPeersGridItem.swift b/TelegramUI/ShareControllerRecentPeersGridItem.swift index e772f5603f..85189765be 100644 --- a/TelegramUI/ShareControllerRecentPeersGridItem.swift +++ b/TelegramUI/ShareControllerRecentPeersGridItem.swift @@ -57,7 +57,7 @@ final class ShareControllerRecentPeersGridItemNode: GridItemNode { peersNode.updateThemeAndStrings(theme: theme, strings: strings) } else { peersNode = ChatListSearchRecentPeersNode(account: account, theme: theme, mode: .actionSheet, strings: strings, peerSelected: { [weak self] peer in - self?.controllerInteraction?.togglePeer(peer, true) + self?.controllerInteraction?.togglePeer(RenderedPeer(peer: peer), true) }, peerLongTapped: {_ in }, isPeerSelected: { [weak self] peerId in return self?.controllerInteraction?.selectedPeerIds.contains(peerId) ?? false }, share: true) diff --git a/TelegramUI/SharePeersContainerNode.swift b/TelegramUI/SharePeersContainerNode.swift index a85f65661b..a8229e5c17 100644 --- a/TelegramUI/SharePeersContainerNode.swift +++ b/TelegramUI/SharePeersContainerNode.swift @@ -60,7 +60,7 @@ final class SharePeersContainerNode: ASDisplayNode, ShareContentContainerNode { private let controllerInteraction: ShareControllerInteraction private let accountPeer: Peer - private let foundPeers = Promise<[Peer]>([]) + private let foundPeers = Promise<[RenderedPeer]>([]) private let disposable = MetaDisposable() private var entries: [SharePeerEntry] = [] @@ -100,8 +100,8 @@ final class SharePeersContainerNode: ASDisplayNode, ShareContentContainerNode { index += 1 for peer in foundPeers.reversed() { - entries.append(SharePeerEntry(index: index, peer: RenderedPeer(peer: peer), theme: theme, strings: strings)) - existingPeerIds.insert(peer.id) + entries.append(SharePeerEntry(index: index, peer: peer, theme: theme, strings: strings)) + existingPeerIds.insert(peer.peerId) index += 1 } @@ -325,10 +325,10 @@ final class SharePeersContainerNode: ASDisplayNode, ShareContentContainerNode { if !self.controllerInteraction.selectedPeers.isEmpty { subtitleText = self.controllerInteraction.selectedPeers.reduce("", { string, peer in let text: String - if peer.id == self.accountPeer.id { + if peer.peerId == self.accountPeer.id { text = self.strings.DialogList_SavedMessages } else { - text = peer.displayTitle + text = peer.chatMainPeer?.displayTitle ?? "" } if !string.isEmpty { diff --git a/TelegramUI/ShareSearchContainerNode.swift b/TelegramUI/ShareSearchContainerNode.swift index 226a6510d4..2cf5079bb3 100644 --- a/TelegramUI/ShareSearchContainerNode.swift +++ b/TelegramUI/ShareSearchContainerNode.swift @@ -106,19 +106,19 @@ private enum ShareSearchRecentEntry: Comparable, Identifiable { private struct ShareSearchPeerEntry: Comparable, Identifiable { let index: Int32 - let peer: Peer + let peer: RenderedPeer let theme: PresentationTheme let strings: PresentationStrings var stableId: Int64 { - return self.peer.id.toInt64() + return self.peer.peerId.toInt64() } static func ==(lhs: ShareSearchPeerEntry, rhs: ShareSearchPeerEntry) -> Bool { if lhs.index != rhs.index { return false } - if !arePeersEqual(lhs.peer, rhs.peer) { + if lhs.peer != rhs.peer { return false } return true @@ -129,7 +129,7 @@ private struct ShareSearchPeerEntry: Comparable, Identifiable { } func item(account: Account, interfaceInteraction: ShareControllerInteraction) -> GridItem { - return ShareControllerPeerGridItem(account: account, theme: self.theme, strings: self.strings, peer: RenderedPeer(peer: self.peer), controllerInteraction: interfaceInteraction, search: true) + return ShareControllerPeerGridItem(account: account, theme: self.theme, strings: self.strings, peer: peer, controllerInteraction: interfaceInteraction, search: true) } } @@ -243,53 +243,49 @@ final class ShareSearchContainerNode: ASDisplayNode, ShareContentContainerNode { |> delay(0.2, queue: Queue.concurrentDefaultQueue())) return combineLatest(accountPeer, foundLocalPeers, foundRemotePeers) - |> map { accountPeer, foundLocalPeers, foundRemotePeers -> [ShareSearchPeerEntry]? in - var entries: [ShareSearchPeerEntry] = [] - var index: Int32 = 0 - - var existingPeerIds = Set() - - if strings.DialogList_SavedMessages.lowercased().hasPrefix(query.lowercased()) { - if !existingPeerIds.contains(accountPeer.id) { - existingPeerIds.insert(accountPeer.id) - entries.append(ShareSearchPeerEntry(index: index, peer: accountPeer, theme: theme, strings: strings)) + |> map { accountPeer, foundLocalPeers, foundRemotePeers -> [ShareSearchPeerEntry]? in + var entries: [ShareSearchPeerEntry] = [] + var index: Int32 = 0 + + var existingPeerIds = Set() + + if strings.DialogList_SavedMessages.lowercased().hasPrefix(query.lowercased()) { + if !existingPeerIds.contains(accountPeer.id) { + existingPeerIds.insert(accountPeer.id) + entries.append(ShareSearchPeerEntry(index: index, peer: RenderedPeer(peer: accountPeer), theme: theme, strings: strings)) + index += 1 + } + } + + for renderedPeer in foundLocalPeers { + if let peer = renderedPeer.peers[renderedPeer.peerId], peer.id != accountPeer.id { + if !existingPeerIds.contains(renderedPeer.peerId) && canSendMessagesToPeer(peer) { + existingPeerIds.insert(renderedPeer.peerId) + entries.append(ShareSearchPeerEntry(index: index, peer: renderedPeer, theme: theme, strings: strings)) index += 1 } } - - for renderedPeer in foundLocalPeers { - if let peer = renderedPeer.peers[renderedPeer.peerId], peer.id != accountPeer.id, peer.id.namespace != Namespaces.Peer.SecretChat { - if !existingPeerIds.contains(peer.id) && canSendMessagesToPeer(peer) { - existingPeerIds.insert(peer.id) - var associatedPeer: Peer? - if let associatedPeerId = peer.associatedPeerId { - associatedPeer = renderedPeer.peers[associatedPeerId] - } - entries.append(ShareSearchPeerEntry(index: index, peer: peer, theme: theme, strings: strings)) - index += 1 - } - } + } + + for foundPeer in foundRemotePeers.0 { + let peer = foundPeer.peer + if !existingPeerIds.contains(peer.id) && canSendMessagesToPeer(peer) { + existingPeerIds.insert(peer.id) + entries.append(ShareSearchPeerEntry(index: index, peer: RenderedPeer(peer: foundPeer.peer), theme: theme, strings: strings)) + index += 1 } - - for foundPeer in foundRemotePeers.0 { - let peer = foundPeer.peer - if !existingPeerIds.contains(peer.id) && canSendMessagesToPeer(peer) { - existingPeerIds.insert(peer.id) - entries.append(ShareSearchPeerEntry(index: index, peer: foundPeer.peer, theme: theme, strings: strings)) - index += 1 - } + } + + for foundPeer in foundRemotePeers.1 { + let peer = foundPeer.peer + if !existingPeerIds.contains(peer.id) && canSendMessagesToPeer(peer) { + existingPeerIds.insert(peer.id) + entries.append(ShareSearchPeerEntry(index: index, peer: RenderedPeer(peer: peer), theme: theme, strings: strings)) + index += 1 } - - for foundPeer in foundRemotePeers.1 { - let peer = foundPeer.peer - if !existingPeerIds.contains(peer.id) && canSendMessagesToPeer(peer) { - existingPeerIds.insert(peer.id) - entries.append(ShareSearchPeerEntry(index: index, peer: peer, theme: theme, strings: strings)) - index += 1 - } - } - - return entries + } + + return entries } } else { return .single(nil) @@ -298,28 +294,28 @@ final class ShareSearchContainerNode: ASDisplayNode, ShareContentContainerNode { let previousSearchItems = Atomic<[ShareSearchPeerEntry]?>(value: nil) self.searchDisposable.set((foundItems - |> deliverOnMainQueue).start(next: { [weak self] entries in - if let strongSelf = self { - let previousEntries = previousSearchItems.swap(entries) - strongSelf.entries = entries ?? [] - - let firstTime = previousEntries == nil - let transition = preparedGridEntryTransition(account: account, from: previousEntries ?? [], to: entries ?? [], interfaceInteraction: controllerInteraction) - strongSelf.enqueueTransition(transition, firstTime: firstTime) - - if (previousEntries == nil) != (entries == nil) { - if previousEntries == nil { - strongSelf.recentGridNode.isHidden = true - strongSelf.contentGridNode.isHidden = false - strongSelf.transitionToContentGridLayout() - } else { - strongSelf.recentGridNode.isHidden = false - strongSelf.contentGridNode.isHidden = true - strongSelf.transitionToRecentGridLayout() - } + |> deliverOnMainQueue).start(next: { [weak self] entries in + if let strongSelf = self { + let previousEntries = previousSearchItems.swap(entries) + strongSelf.entries = entries ?? [] + + let firstTime = previousEntries == nil + let transition = preparedGridEntryTransition(account: account, from: previousEntries ?? [], to: entries ?? [], interfaceInteraction: controllerInteraction) + strongSelf.enqueueTransition(transition, firstTime: firstTime) + + if (previousEntries == nil) != (entries == nil) { + if previousEntries == nil { + strongSelf.recentGridNode.isHidden = true + strongSelf.contentGridNode.isHidden = false + strongSelf.transitionToContentGridLayout() + } else { + strongSelf.recentGridNode.isHidden = false + strongSelf.contentGridNode.isHidden = true + strongSelf.transitionToRecentGridLayout() } } - })) + } + })) self.searchNode.textUpdated = { [weak self] text in self?.searchQuery.set(text) @@ -414,7 +410,7 @@ final class ShareSearchContainerNode: ASDisplayNode, ShareContentContainerNode { var scrollToItem: GridNodeScrollToItem? if !self.contentGridNode.isHidden, let ensurePeerVisibleOnLayout = self.ensurePeerVisibleOnLayout { self.ensurePeerVisibleOnLayout = nil - if let index = self.entries.index(where: { $0.peer.id == ensurePeerVisibleOnLayout }) { + if let index = self.entries.index(where: { $0.peer.peerId == ensurePeerVisibleOnLayout }) { scrollToItem = GridNodeScrollToItem(index: index, position: .visible, transition: transition, directionHint: .up, adjustForSection: false) } } diff --git a/TelegramUI/TwoStepVerificationUnlockController.swift b/TelegramUI/TwoStepVerificationUnlockController.swift index 995012f5c4..d8e707e305 100644 --- a/TelegramUI/TwoStepVerificationUnlockController.swift +++ b/TelegramUI/TwoStepVerificationUnlockController.swift @@ -183,14 +183,15 @@ private func twoStepVerificationUnlockSettingsControllerEntries(presentationData switch configuration { case let .notSet(pendingEmailAndValue): if let pendingEmailAndValue = pendingEmailAndValue { - entries.append(.pendingEmailConfirmInfo(presentationData.theme, presentationData.strings.TwoStepAuth_EmailSent)) + /*entries.append(.pendingEmailConfirmInfo(presentationData.theme, presentationData.strings.TwoStepAuth_EmailSent)) if pendingEmailAndValue.email != nil { } else { entries.append(.pendingEmailConfirmAddress(presentationData.theme, presentationData.strings.TwoStepAuth_EmailTitle, state.emailAddress)) } entries.append(.pendingEmailConfirmCode(presentationData.theme, presentationData.strings.TwoStepAuth_RecoveryCode, state.emailCode)) - //entries.append(.pendingEmailInfo(presentationData.theme, presentationData.strings.TwoStepAuth_ConfirmationText + "\n\n\(pendingEmail.pattern)\n\n[" + presentationData.strings.TwoStepAuth_ConfirmationAbort + "]()")) - entries.append(.pendingEmailInfo(presentationData.theme, "[" + presentationData.strings.TwoStepAuth_ConfirmationAbort + "]()")) + entries.append(.pendingEmailInfo(presentationData.theme, "[" + presentationData.strings.TwoStepAuth_ConfirmationAbort + "]()")) + */ + entries.append(.pendingEmailInfo(presentationData.theme, presentationData.strings.TwoStepAuth_ConfirmationText + "\n\n\(pendingEmailAndValue.pendingEmail.pattern)\n\n[" + presentationData.strings.TwoStepAuth_ConfirmationAbort + "]()")) } else { entries.append(.passwordSetup(presentationData.theme, presentationData.strings.TwoStepAuth_SetPassword)) entries.append(.passwordSetupInfo(presentationData.theme, presentationData.strings.TwoStepAuth_SetPasswordHelp)) @@ -209,14 +210,14 @@ private func twoStepVerificationUnlockSettingsControllerEntries(presentationData entries.append(.turnPasswordOff(presentationData.theme, presentationData.strings.TwoStepAuth_RemovePassword)) entries.append(.setupRecoveryEmail(presentationData.theme, emailSet ? presentationData.strings.TwoStepAuth_ChangeEmail : presentationData.strings.TwoStepAuth_SetupEmail)) if let pendingEmailAndValue = pendingEmailAndValue { - entries.append(.pendingEmailConfirmInfo(presentationData.theme, presentationData.strings.TwoStepAuth_EmailSent)) + /*entries.append(.pendingEmailConfirmInfo(presentationData.theme, presentationData.strings.TwoStepAuth_EmailSent)) if pendingEmailAndValue.email != nil { } else { entries.append(.pendingEmailConfirmAddress(presentationData.theme, presentationData.strings.TwoStepAuth_EmailTitle, state.emailAddress)) } - entries.append(.pendingEmailConfirmCode(presentationData.theme, presentationData.strings.TwoStepAuth_RecoveryCode, state.emailCode)) - //entries.append(.pendingEmailInfo(presentationData.theme, presentationData.strings.TwoStepAuth_ConfirmationText + "\n\n\(pendingEmail.pattern)\n\n[" + presentationData.strings.TwoStepAuth_ConfirmationAbort + "]()")) - //entries.append(.pendingEmailInfo(presentationData.theme, "[" + presentationData.strings.TwoStepAuth_ConfirmationAbort + "]()")) + entries.append(.pendingEmailConfirmCode(presentationData.theme, presentationData.strings.TwoStepAuth_RecoveryCode, state.emailCode))*/ + //entries.append(.pendingEmailInfo(presentationData.theme, presentationData.strings.TwoStepAuth_ConfirmationText + "\n\n\(pendingEmailAndValue.pendingEmail.pattern)\n\n[" + presentationData.strings.TwoStepAuth_ConfirmationAbort + "]()")) + entries.append(.pendingEmailInfo(presentationData.theme, presentationData.strings.TwoStepAuth_EmailSent)) } else { entries.append(.passwordInfo(presentationData.theme, presentationData.strings.TwoStepAuth_GenericHelp)) } @@ -697,11 +698,12 @@ func twoStepVerificationUnlockSettingsController(account: Account, mode: TwoStep } else { switch configuration { case let .notSet(pendingEmail): - if let pendingEmailAndValue = pendingEmail { + /*if let pendingEmailAndValue = pendingEmail { rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Next), style: .bold, enabled: (pendingEmailAndValue.email != nil || !state.emailAddress.isEmpty) && !state.emailCode.isEmpty, action: { checkEmailConfirmation() }) - } + }*/ + break case .set: rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Next), style: .bold, enabled: true, action: { arguments.checkPassword() @@ -716,11 +718,11 @@ func twoStepVerificationUnlockSettingsController(account: Account, mode: TwoStep if state.checking { rightNavigationButton = ItemListNavigationButton(content: .none, style: .activity, enabled: true, action: {}) } else { - if let pendingEmailAndValue = manage.pendingEmail { + /*if let pendingEmailAndValue = manage.pendingEmail { rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Next), style: .bold, enabled: (pendingEmailAndValue.email != nil || !state.emailAddress.isEmpty) && !state.emailCode.isEmpty, action: { checkEmailConfirmation() }) - } + }*/ } } diff --git a/TelegramUI/UniversalVideoGalleryItem.swift b/TelegramUI/UniversalVideoGalleryItem.swift index 9a617b9e0f..b4f864b404 100644 --- a/TelegramUI/UniversalVideoGalleryItem.swift +++ b/TelegramUI/UniversalVideoGalleryItem.swift @@ -374,7 +374,16 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode { initialBuffering = true //buffering = true isPaused = !whilePlaying - if let content = item.content as? NativeVideoContent, !content.streamVideo { + var isStreaming = false + if let fetchStatus = strongSelf.fetchStatus { + switch fetchStatus { + case .Local: + break + default: + isStreaming = true + } + } + if let content = item.content as? NativeVideoContent, !isStreaming { initialBuffering = false if !content.enableSound { isPaused = false