From 954ec6b13e6a43bedf3a45e1607c486dd4028f28 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Mon, 26 Oct 2020 19:18:15 +0400 Subject: [PATCH] Pre-release fixes --- build-system/generate-xcode-project.sh | 6 +++-- .../Sources/Node/ChatListItem.swift | 9 ++++++- .../Sources/HistoryViewStateValidation.swift | 3 +++ .../Sources/ManagedLocalInputActivities.swift | 2 +- .../TelegramNotices/Sources/Notices.swift | 26 +++++++++++++++++++ .../TelegramUI/Sources/ChatController.swift | 16 +++++++++++- .../ChatInterfaceStateContextQueries.swift | 22 +++++++++++----- 7 files changed, 73 insertions(+), 11 deletions(-) diff --git a/build-system/generate-xcode-project.sh b/build-system/generate-xcode-project.sh index fb4dc01612..9910f9d3b9 100755 --- a/build-system/generate-xcode-project.sh +++ b/build-system/generate-xcode-project.sh @@ -54,9 +54,11 @@ BAZEL_OPTIONS=(\ --swiftcopt=-j${CORE_COUNT_MINUS_ONE} \ ) -if [ "$BAZEL_CACHE_DIR" != "" ]; then +if [ "$BAZEL_HTTP_CACHE_URL" != "" ]; then + BAZEL_OPTIONS=("${BAZEL_OPTIONS[@]}" --remote_cache="$(echo $BAZEL_HTTP_CACHE_URL | sed -e 's/[\/&]/\\&/g')") +elif [ "$BAZEL_CACHE_DIR" != "" ]; then BAZEL_OPTIONS=("${BAZEL_OPTIONS[@]}" --disk_cache="$(echo $BAZEL_CACHE_DIR | sed -e 's/[\/&]/\\&/g')") -fi +fi "$TULSI" -- \ --verbose \ diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index cf1a78d25f..d64ede01c7 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -795,7 +795,13 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { } embeddedState = embeddedStateValue summaryInfo = summaryInfoValue - inputActivities = inputActivitiesValue + + if let peerPresence = peerPresence as? TelegramUserPresence, case .present = peerPresence.status { + inputActivities = inputActivitiesValue + } else { + inputActivities = nil + } + isPeerGroup = false promoInfo = promoInfoValue displayAsMessage = displayAsMessageValue @@ -1320,6 +1326,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { var inputActivitiesSize: CGSize? var inputActivitiesApply: (() -> Void)? if let inputActivities = inputActivities, !inputActivities.isEmpty { + let (size, apply) = inputActivitiesLayout(CGSize(width: rawContentWidth - badgeSize, height: 40.0), item.presentationData, item.presentationData.theme.chatList.messageTextColor, item.index.messageIndex.id.peerId, inputActivities) inputActivitiesSize = size inputActivitiesApply = apply diff --git a/submodules/TelegramCore/Sources/HistoryViewStateValidation.swift b/submodules/TelegramCore/Sources/HistoryViewStateValidation.swift index 3a08b937fe..5e570a1b8e 100644 --- a/submodules/TelegramCore/Sources/HistoryViewStateValidation.swift +++ b/submodules/TelegramCore/Sources/HistoryViewStateValidation.swift @@ -416,6 +416,9 @@ private func hashForMessages(_ messages: [Message], withChannelIds: Bool) -> Int break inner } } + if message.tags.contains(.pinned) { + acc = (acc &* 20261) &+ UInt32(1) + } acc = (acc &* 20261) &+ UInt32(timestamp) } return Int32(bitPattern: acc & UInt32(0x7FFFFFFF)) diff --git a/submodules/TelegramCore/Sources/ManagedLocalInputActivities.swift b/submodules/TelegramCore/Sources/ManagedLocalInputActivities.swift index b8ace47668..2f435c6c29 100644 --- a/submodules/TelegramCore/Sources/ManagedLocalInputActivities.swift +++ b/submodules/TelegramCore/Sources/ManagedLocalInputActivities.swift @@ -139,7 +139,7 @@ private func requestActivity(postbox: Postbox, network: Network, accountPeerId: break case let .present(statusTimestamp): let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) - if statusTimestamp < timestamp { + if statusTimestamp < timestamp - 30 { return .complete() } } diff --git a/submodules/TelegramNotices/Sources/Notices.swift b/submodules/TelegramNotices/Sources/Notices.swift index 0d6aeeee83..01b4e7b6b4 100644 --- a/submodules/TelegramNotices/Sources/Notices.swift +++ b/submodules/TelegramNotices/Sources/Notices.swift @@ -302,6 +302,32 @@ public struct ApplicationSpecificNotice { } } + public static func inlineBotLocationRequestStatus(accountManager: AccountManager, peerId: PeerId) -> Signal { + return accountManager.noticeEntry(key: ApplicationSpecificNoticeKeys.inlineBotLocationRequestNotice(peerId: peerId)) + |> map { view -> Bool in + guard let value = view.value as? ApplicationSpecificTimestampNotice else { + return false + } + if value.value == 0 { + return true + } else { + return false + } + } + } + + public static func updateInlineBotLocationRequestState(accountManager: AccountManager, peerId: PeerId, timestamp: Int32) -> Signal { + return accountManager.transaction { transaction -> Bool in + if let notice = transaction.getNotice(ApplicationSpecificNoticeKeys.inlineBotLocationRequestNotice(peerId: peerId)) as? ApplicationSpecificTimestampNotice, (notice.value == 0 || timestamp <= notice.value + 10 * 60) { + return false + } + + transaction.setNotice(ApplicationSpecificNoticeKeys.inlineBotLocationRequestNotice(peerId: peerId), ApplicationSpecificTimestampNotice(value: timestamp)) + + return true + } + } + public static func setInlineBotLocationRequest(accountManager: AccountManager, peerId: PeerId, value: Int32) -> Signal { return accountManager.transaction { transaction -> Void in transaction.setNotice(ApplicationSpecificNoticeKeys.inlineBotLocationRequestNotice(peerId: peerId), ApplicationSpecificTimestampNotice(value: value)) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 9caf1c0821..85bab2bcac 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -6569,7 +6569,21 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G let inputTextPanelState = inputTextPanelStateForChatPresentationInterfaceState(temporaryChatPresentationInterfaceState, context: self.context) var updatedChatPresentationInterfaceState = temporaryChatPresentationInterfaceState.updatedInputTextPanelState({ _ in return inputTextPanelState }) - let contextQueryUpdates = contextQueryResultStateForChatInterfacePresentationState(updatedChatPresentationInterfaceState, context: self.context, currentQueryStates: &self.contextQueryStates) + let contextQueryUpdates = contextQueryResultStateForChatInterfacePresentationState(updatedChatPresentationInterfaceState, context: self.context, currentQueryStates: &self.contextQueryStates, requestBotLocationStatus: { [weak self] peerId in + guard let strongSelf = self else { + return + } + let _ = (ApplicationSpecificNotice.updateInlineBotLocationRequestState(accountManager: strongSelf.context.sharedContext.accountManager, peerId: peerId, timestamp: Int32(Date().timeIntervalSince1970 + 10 * 60)) + |> deliverOnMainQueue).start(next: { value in + guard let strongSelf = self, value else { + return + } + strongSelf.present(textAlertController(context: strongSelf.context, title: nil, text: strongSelf.presentationData.strings.Conversation_ShareInlineBotLocationConfirmation, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_Cancel, action: { + }), TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: { + let _ = ApplicationSpecificNotice.setInlineBotLocationRequest(accountManager: strongSelf.context.sharedContext.accountManager, peerId: peerId, value: 0).start() + })]), in: .window(.root)) + }) + }) for (kind, update) in contextQueryUpdates { switch update { diff --git a/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift b/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift index f3b0b519de..0a6f23285d 100644 --- a/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift +++ b/submodules/TelegramUI/Sources/ChatInterfaceStateContextQueries.swift @@ -11,6 +11,7 @@ import AccountContext import Emoji import SearchPeerMembers import DeviceLocationManager +import TelegramNotices enum ChatContextQueryError { case inlineBotLocationRequest(PeerId) @@ -21,7 +22,7 @@ enum ChatContextQueryUpdate { case update(ChatPresentationInputQuery, Signal<(ChatPresentationInputQueryResult?) -> ChatPresentationInputQueryResult?, ChatContextQueryError>) } -func contextQueryResultStateForChatInterfacePresentationState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState, context: AccountContext, currentQueryStates: inout [ChatPresentationInputQueryKind: (ChatPresentationInputQuery, Disposable)]) -> [ChatPresentationInputQueryKind: ChatContextQueryUpdate] { +func contextQueryResultStateForChatInterfacePresentationState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState, context: AccountContext, currentQueryStates: inout [ChatPresentationInputQueryKind: (ChatPresentationInputQuery, Disposable)], requestBotLocationStatus: @escaping (PeerId) -> Void) -> [ChatPresentationInputQueryKind: ChatContextQueryUpdate] { guard let peer = chatPresentationInterfaceState.renderedPeer?.peer else { return [:] } @@ -43,7 +44,7 @@ func contextQueryResultStateForChatInterfacePresentationState(_ chatPresentation for query in inputQueries { let previousQuery = currentQueryStates[query.kind]?.0 if previousQuery != query { - let signal = updatedContextQueryResultStateForQuery(context: context, peer: peer, chatLocation: chatPresentationInterfaceState.chatLocation, inputQuery: query, previousQuery: previousQuery) + let signal = updatedContextQueryResultStateForQuery(context: context, peer: peer, chatLocation: chatPresentationInterfaceState.chatLocation, inputQuery: query, previousQuery: previousQuery, requestBotLocationStatus: requestBotLocationStatus) updates[query.kind] = .update(query, signal) } } @@ -64,7 +65,7 @@ func contextQueryResultStateForChatInterfacePresentationState(_ chatPresentation return updates } -private func updatedContextQueryResultStateForQuery(context: AccountContext, peer: Peer, chatLocation: ChatLocation, inputQuery: ChatPresentationInputQuery, previousQuery: ChatPresentationInputQuery?) -> Signal<(ChatPresentationInputQueryResult?) -> ChatPresentationInputQueryResult?, ChatContextQueryError> { +private func updatedContextQueryResultStateForQuery(context: AccountContext, peer: Peer, chatLocation: ChatLocation, inputQuery: ChatPresentationInputQuery, previousQuery: ChatPresentationInputQuery?, requestBotLocationStatus: @escaping (PeerId) -> Void) -> Signal<(ChatPresentationInputQueryResult?) -> ChatPresentationInputQueryResult?, ChatContextQueryError> { switch inputQuery { case let .emoji(query): var signal: Signal<(ChatPresentationInputQueryResult?) -> ChatPresentationInputQueryResult?, ChatContextQueryError> = .complete() @@ -246,9 +247,18 @@ private func updatedContextQueryResultStateForQuery(context: AccountContext, pee |> mapToSignal { peer -> Signal<(ChatPresentationInputQueryResult?) -> ChatPresentationInputQueryResult?, ChatContextQueryError> in if let user = peer as? TelegramUser, let botInfo = user.botInfo, let _ = botInfo.inlinePlaceholder { let contextResults = requestChatContextResults(account: context.account, botId: user.id, peerId: chatPeer.id, query: query, location: context.sharedContext.locationManager.flatMap { locationManager in - return currentLocationManagerCoordinate(manager: locationManager, timeout: 5.0) - |> flatMap { coordinate -> (Double, Double) in - return (coordinate.latitude, coordinate.longitude) + Queue.mainQueue().async { + requestBotLocationStatus(user.id) + } + + return ApplicationSpecificNotice.inlineBotLocationRequestStatus(accountManager: context.sharedContext.accountManager, peerId: user.id) + |> filter { $0 } + |> take(1) + |> mapToSignal { _ -> Signal<(Double, Double)?, NoError> in + return currentLocationManagerCoordinate(manager: locationManager, timeout: 5.0) + |> flatMap { coordinate -> (Double, Double) in + return (coordinate.latitude, coordinate.longitude) + } } } ?? .single(nil), offset: "") |> mapError { error -> ChatContextQueryError in