From f0c60c379d1aadbb2d17e3f6c71a1b281f3d0a9b Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 20 Jun 2019 12:38:50 +0200 Subject: [PATCH] Fixed admins list update after transfering to non-participant Fixed peers nearby activity indicators Fixed Siri shortcut opening from cold start --- .../TelegramUI/TelegramUI/AppDelegate.swift | 8 ++--- .../TelegramUI/ApplicationContext.swift | 12 ++++---- .../ChannelMemberCategoryListContext.swift | 29 ++++++++++--------- .../TelegramUI/ChatController.swift | 14 ++++++--- .../ItemListSectionHeaderItem.swift | 4 +-- .../TelegramUI/NavigateToChatController.swift | 8 ++++- ...annelMemberCategoriesContextsManager.swift | 4 +-- .../TelegramUI/PeersNearbyController.swift | 14 +++++---- .../Sources/CallListSettings.swift | 2 +- 9 files changed, 55 insertions(+), 40 deletions(-) diff --git a/submodules/TelegramUI/TelegramUI/AppDelegate.swift b/submodules/TelegramUI/TelegramUI/AppDelegate.swift index 847e73a19e..eda3deda39 100644 --- a/submodules/TelegramUI/TelegramUI/AppDelegate.swift +++ b/submodules/TelegramUI/TelegramUI/AppDelegate.swift @@ -1641,8 +1641,8 @@ final class SharedApplicationContext { } else if let sendMessageIntent = userActivity.interaction?.intent as? INSendMessageIntent { if let contact = sendMessageIntent.recipients?.first, let handle = contact.customIdentifier, handle.hasPrefix("tg") { let string = handle.suffix(from: handle.index(handle.startIndex, offsetBy: 2)) - if let id = Int32(string), let context = self.contextValue { - navigateToChatController(navigationController: context.rootController, context: context.context, chatLocation: .peer(PeerId(namespace: Namespaces.Peer.CloudUser, id: id))) + if let id = Int32(string) { + self.openChatWhenReady(accountId: nil, peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: id), activateInput: true) } } } @@ -1689,7 +1689,7 @@ final class SharedApplicationContext { }) } - private func openChatWhenReady(accountId: AccountRecordId?, peerId: PeerId, messageId: MessageId? = nil) { + private func openChatWhenReady(accountId: AccountRecordId?, peerId: PeerId, messageId: MessageId? = nil, activateInput: Bool = false) { let signal = self.sharedContextPromise.get() |> take(1) |> mapToSignal { sharedApplicationContext -> Signal in @@ -1707,7 +1707,7 @@ final class SharedApplicationContext { } self.openChatWhenReadyDisposable.set((signal |> deliverOnMainQueue).start(next: { context in - context.openChatWithPeerId(peerId: peerId, messageId: messageId) + context.openChatWithPeerId(peerId: peerId, messageId: messageId, activateInput: activateInput) })) } diff --git a/submodules/TelegramUI/TelegramUI/ApplicationContext.swift b/submodules/TelegramUI/TelegramUI/ApplicationContext.swift index 00c8708175..87d33fe403 100644 --- a/submodules/TelegramUI/TelegramUI/ApplicationContext.swift +++ b/submodules/TelegramUI/TelegramUI/ApplicationContext.swift @@ -58,7 +58,7 @@ final class AuthorizedApplicationContext { let rootController: TelegramRootController let notificationController: NotificationContainerController - private var scheduledOperChatWithPeerId: PeerId? + private var scheduledOperChatWithPeerId: (PeerId, MessageId?, Bool)? private var scheduledOpenExternalUrl: URL? private let passcodeStatusDisposable = MetaDisposable() @@ -268,9 +268,9 @@ final class AuthorizedApplicationContext { strongSelf.notificationController.view.isHidden = false if strongSelf.rootController.rootTabController == nil { strongSelf.rootController.addRootControllers(showCallsTab: strongSelf.showCallsTab) - if let peerId = strongSelf.scheduledOperChatWithPeerId { + if let (peerId, messageId, activateInput) = strongSelf.scheduledOperChatWithPeerId { strongSelf.scheduledOperChatWithPeerId = nil - strongSelf.openChatWithPeerId(peerId: peerId) + strongSelf.openChatWithPeerId(peerId: peerId, messageId: messageId, activateInput: activateInput) } if let url = strongSelf.scheduledOpenExternalUrl { @@ -782,7 +782,7 @@ final class AuthorizedApplicationContext { self.permissionsDisposable.dispose() } - func openChatWithPeerId(peerId: PeerId, messageId: MessageId? = nil) { + func openChatWithPeerId(peerId: PeerId, messageId: MessageId? = nil, activateInput: Bool = false) { var visiblePeerId: PeerId? if let controller = self.rootController.topViewController as? ChatController, case let .peer(peerId) = controller.chatLocation { visiblePeerId = peerId @@ -790,9 +790,9 @@ final class AuthorizedApplicationContext { if visiblePeerId != peerId || messageId != nil { if self.rootController.rootTabController != nil { - navigateToChatController(navigationController: self.rootController, context: self.context, chatLocation: .peer(peerId), messageId: messageId) + navigateToChatController(navigationController: self.rootController, context: self.context, chatLocation: .peer(peerId), messageId: messageId, activateInput: activateInput) } else { - self.scheduledOperChatWithPeerId = peerId + self.scheduledOperChatWithPeerId = (peerId, messageId, activateInput) } } } diff --git a/submodules/TelegramUI/TelegramUI/ChannelMemberCategoryListContext.swift b/submodules/TelegramUI/TelegramUI/ChannelMemberCategoryListContext.swift index 51fcc654fa..caf8d372f6 100644 --- a/submodules/TelegramUI/TelegramUI/ChannelMemberCategoryListContext.swift +++ b/submodules/TelegramUI/TelegramUI/ChannelMemberCategoryListContext.swift @@ -294,19 +294,22 @@ private final class ChannelMemberSingleCategoryListContext: ChannelMemberCategor } switch self.category { case let .admins(query): - if let updated = updated, let _ = updated.participant.adminInfo, (query == nil || updated.peer.indexName.matchesByTokens(query!)) { - var found = false - loop: for i in 0 ..< list.count { - if list[i].peer.id == updated.peer.id { - list[i] = updated - found = true - updatedList = true - break loop + if let updated = updated, (query == nil || updated.peer.indexName.matchesByTokens(query!)) { + if case let .member(_, _, adminInfo, _) = updated.participant, adminInfo == nil { + } else { + var found = false + loop: for i in 0 ..< list.count { + if list[i].peer.id == updated.peer.id { + list[i] = updated + found = true + updatedList = true + break loop + } + } + if !found { + list.insert(updated, at: 0) + updatedList = true } - } - if !found { - list.insert(updated, at: 0) - updatedList = true } } else if let previous = previous, let _ = previous.adminInfo { loop: for i in 0 ..< list.count { @@ -316,7 +319,7 @@ private final class ChannelMemberSingleCategoryListContext: ChannelMemberCategor break loop } } - if let updated = updated, case .creator = updated.participant{ + if let updated = updated, case .creator = updated.participant { list.insert(updated, at: 0) updatedList = true } diff --git a/submodules/TelegramUI/TelegramUI/ChatController.swift b/submodules/TelegramUI/TelegramUI/ChatController.swift index ca9918034e..9e5ca00dbf 100644 --- a/submodules/TelegramUI/TelegramUI/ChatController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatController.swift @@ -6769,7 +6769,7 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget, strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { state in return state.updatedInterfaceState { interfaceState in return interfaceState.withUpdatedEffectiveInputState(interfaceState.effectiveInputState) - }.updatedInputMode({ _ in ChatInputMode.text }) + }.updatedInputMode({ _ in .text }) }) } }), @@ -6780,7 +6780,7 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget, return state.updatedInterfaceState { interfaceState in let effectiveInputState = ChatTextInputState(inputText: NSAttributedString(string: "/")) return interfaceState.withUpdatedEffectiveInputState(effectiveInputState) - }.updatedInputMode({ _ in ChatInputMode.text }) + }.updatedInputMode({ _ in .text }) } else { return state } @@ -6794,7 +6794,7 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget, return state.updatedInterfaceState { interfaceState in let effectiveInputState = ChatTextInputState(inputText: NSAttributedString(string: "@")) return interfaceState.withUpdatedEffectiveInputState(effectiveInputState) - }.updatedInputMode({ _ in ChatInputMode.text }) + }.updatedInputMode({ _ in .text }) } else { return state } @@ -6808,7 +6808,7 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget, return state.updatedInterfaceState { interfaceState in let effectiveInputState = ChatTextInputState(inputText: NSAttributedString(string: "#")) return interfaceState.withUpdatedEffectiveInputState(effectiveInputState) - }.updatedInputMode({ _ in ChatInputMode.text }) + }.updatedInputMode({ _ in .text }) } else { return state } @@ -6886,6 +6886,12 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget, } } + func activateInput() { + self.updateChatPresentationInterfaceState(animated: true, interactive: true, { state in + return state.updatedInputMode({ _ in .text }) + }) + } + private func clearInputText() { self.updateChatPresentationInterfaceState(animated: true, interactive: true, { state in if !state.interfaceState.effectiveInputState.inputText.string.isEmpty { diff --git a/submodules/TelegramUI/TelegramUI/ItemListSectionHeaderItem.swift b/submodules/TelegramUI/TelegramUI/ItemListSectionHeaderItem.swift index e582c1c954..2c729af3c2 100644 --- a/submodules/TelegramUI/TelegramUI/ItemListSectionHeaderItem.swift +++ b/submodules/TelegramUI/TelegramUI/ItemListSectionHeaderItem.swift @@ -166,10 +166,10 @@ class ItemListSectionHeaderItemNode: ListViewItemNode { } activityIndicator.isHidden = false if previousItem != nil { - activityIndicator.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + activityIndicator.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, removeOnCompletion: false) } } else if let activityIndicator = strongSelf.activityIndicator { - activityIndicator.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, completion: { finished in + activityIndicator.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false, completion: { finished in if finished { activityIndicator.isHidden = true } diff --git a/submodules/TelegramUI/TelegramUI/NavigateToChatController.swift b/submodules/TelegramUI/TelegramUI/NavigateToChatController.swift index 30b2cd0bdb..082a37fb4d 100644 --- a/submodules/TelegramUI/TelegramUI/NavigateToChatController.swift +++ b/submodules/TelegramUI/TelegramUI/NavigateToChatController.swift @@ -10,7 +10,7 @@ public enum NavigateToChatKeepStack { case never } -public func navigateToChatController(navigationController: NavigationController, chatController: ChatController? = nil, context: AccountContext, chatLocation: ChatLocation, messageId: MessageId? = nil, botStart: ChatControllerInitialBotStart? = nil, updateTextInputState: ChatTextInputState? = nil, keepStack: NavigateToChatKeepStack = .default, purposefulAction: (() -> Void)? = nil, scrollToEndIfExists: Bool = false, animated: Bool = true, parentGroupId: PeerGroupId? = nil, completion: @escaping () -> Void = {}) { +public func navigateToChatController(navigationController: NavigationController, chatController: ChatController? = nil, context: AccountContext, chatLocation: ChatLocation, messageId: MessageId? = nil, botStart: ChatControllerInitialBotStart? = nil, updateTextInputState: ChatTextInputState? = nil, activateInput: Bool = false, keepStack: NavigateToChatKeepStack = .default, purposefulAction: (() -> Void)? = nil, scrollToEndIfExists: Bool = false, animated: Bool = true, parentGroupId: PeerGroupId? = nil, completion: @escaping () -> Void = {}) { var found = false var isFirst = true for controller in navigationController.viewControllers.reversed() { @@ -35,6 +35,9 @@ public func navigateToChatController(navigationController: NavigationController, completion() } controller.purposefulAction = purposefulAction + if activateInput { + controller.activateInput() + } found = true break } @@ -80,6 +83,9 @@ public func navigateToChatController(navigationController: NavigationController, navigationController.replaceControllersAndPush(controllers: viewControllers, controller: controller, animated: animated, completion: completion) } } + if activateInput { + controller.activateInput() + } } navigationController.currentWindow?.forEachController { controller in diff --git a/submodules/TelegramUI/TelegramUI/PeerChannelMemberCategoriesContextsManager.swift b/submodules/TelegramUI/TelegramUI/PeerChannelMemberCategoriesContextsManager.swift index 1f5242f177..f258c50927 100644 --- a/submodules/TelegramUI/TelegramUI/PeerChannelMemberCategoriesContextsManager.swift +++ b/submodules/TelegramUI/TelegramUI/PeerChannelMemberCategoriesContextsManager.swift @@ -253,9 +253,7 @@ final class PeerChannelMemberCategoriesContextsManager { strongSelf.impl.with { impl in for (contextPeerId, context) in impl.contexts { if peerId == contextPeerId { - for (previous, updated) in results { - context.replayUpdates([(previous, updated, nil)]) - } + context.replayUpdates(results.map { ($0.0, $0.1, nil) }) } } } diff --git a/submodules/TelegramUI/TelegramUI/PeersNearbyController.swift b/submodules/TelegramUI/TelegramUI/PeersNearbyController.swift index f6a761fa7f..0f9901ae25 100644 --- a/submodules/TelegramUI/TelegramUI/PeersNearbyController.swift +++ b/submodules/TelegramUI/TelegramUI/PeersNearbyController.swift @@ -245,11 +245,11 @@ private struct PeersNearbyData: Equatable { } } -private func peersNearbyControllerEntries(data: PeersNearbyData?, presentationData: PresentationData) -> [PeersNearbyEntry] { +private func peersNearbyControllerEntries(data: PeersNearbyData?, presentationData: PresentationData, displayLoading: Bool) -> [PeersNearbyEntry] { var entries: [PeersNearbyEntry] = [] entries.append(.header(presentationData.theme, presentationData.strings.PeopleNearby_Description)) - entries.append(.usersHeader(presentationData.theme, presentationData.strings.PeopleNearby_Users.uppercased(), data == nil)) + entries.append(.usersHeader(presentationData.theme, presentationData.strings.PeopleNearby_Users.uppercased(), displayLoading && data == nil)) if let data = data, !data.users.isEmpty { var i: Int32 = 0 for user in data.users { @@ -260,7 +260,7 @@ private func peersNearbyControllerEntries(data: PeersNearbyData?, presentationDa entries.append(.empty(presentationData.theme, presentationData.strings.PeopleNearby_UsersEmpty)) } - entries.append(.groupsHeader(presentationData.theme, presentationData.strings.PeopleNearby_Groups.uppercased(), data == nil)) + entries.append(.groupsHeader(presentationData.theme, presentationData.strings.PeopleNearby_Groups.uppercased(), displayLoading && data == nil)) entries.append(.createGroup(presentationData.theme, presentationData.strings.PeopleNearby_CreateGroup, data?.latitude, data?.longitude, data?.address)) if let data = data, !data.groups.isEmpty { var i: Int32 = 0 @@ -376,9 +376,11 @@ public func peersNearbyController(context: AccountContext) -> ViewController { let previousData = Atomic(value: nil) - let signal = combineLatest(context.sharedContext.presentationData, dataPromise.get()) + let displayLoading: Signal = .single(false) |> then(.single(true) |> delay(1.0, queue: Queue.mainQueue())) + + let signal = combineLatest(context.sharedContext.presentationData, dataPromise.get(), displayLoading) |> deliverOnMainQueue - |> map { presentationData, data -> (ItemListControllerState, (ItemListNodeState, PeersNearbyEntry.ItemGenerationArguments)) in + |> map { presentationData, data, displayLoading -> (ItemListControllerState, (ItemListNodeState, PeersNearbyEntry.ItemGenerationArguments)) in let previous = previousData.swap(data) var crossfade = false @@ -390,7 +392,7 @@ public func peersNearbyController(context: AccountContext) -> ViewController { } let controllerState = ItemListControllerState(theme: presentationData.theme, title: .text(presentationData.strings.PeopleNearby_Title), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: true) - let listState = ItemListNodeState(entries: peersNearbyControllerEntries(data: data, presentationData: presentationData), style: .blocks, emptyStateItem: nil, crossfadeState: crossfade, animateChanges: !crossfade, userInteractionEnabled: true) + let listState = ItemListNodeState(entries: peersNearbyControllerEntries(data: data, presentationData: presentationData, displayLoading: displayLoading), style: .blocks, emptyStateItem: nil, crossfadeState: crossfade, animateChanges: !crossfade, userInteractionEnabled: true) return (controllerState, (listState, arguments)) } diff --git a/submodules/TelegramUIPreferences/Sources/CallListSettings.swift b/submodules/TelegramUIPreferences/Sources/CallListSettings.swift index ff81d69b1a..239f6a554c 100644 --- a/submodules/TelegramUIPreferences/Sources/CallListSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/CallListSettings.swift @@ -6,7 +6,7 @@ public struct CallListSettings: PreferencesEntry, Equatable { public var showTab: Bool public static var defaultSettings: CallListSettings { - return CallListSettings(showTab: false) + return CallListSettings(showTab: true) } public init(showTab: Bool) {