From d26313f99a2593f27cec11b9c19b7c6b1f635369 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Tue, 13 Apr 2021 21:06:58 +0400 Subject: [PATCH] Animation experiment --- .../Source/ASEditableTextNode.mm | 2 +- .../Sources/ChatListSearchContainerNode.swift | 2 +- .../Sources/CreatePollController.swift | 2 +- .../Sources/DebugController.swift | 10 +- .../SecretMediaPreviewController.swift | 2 +- .../Sources/LegacyMediaPickers.swift | 18 +- .../Sources/UserInfoController.swift | 1538 ----------------- .../Sources/AlertTheme.swift | 8 +- .../Sources/Themes/EditThemeController.swift | 2 +- .../Sources/ShareController.swift | 28 +- .../ShareItems/Sources/ShareItems.swift | 4 +- .../OutgoingMessageInfoAttribute.swift | 14 +- .../Sources/CallRatingController.swift | 4 +- .../Sources/VoiceChatController.swift | 2 +- submodules/TelegramCore/Sources/Account.swift | 8 + .../TelegramCore/Sources/EnqueueMessage.swift | 64 +- ...OutgoingMessageWithChatContextResult.swift | 30 +- .../PendingMessageUploadedContent.swift | 4 +- .../Sources/RequestStartBot.swift | 2 +- ...essageAutoremoveTimeoutInteractively.swift | 4 +- .../UnauthorizedAccountStateManager.swift | 10 +- .../Sources/AccessoryPanelNode.swift | 1 + .../TelegramUI/Sources/AppDelegate.swift | 2 +- .../Sources/ApplicationContext.swift | 16 + .../TelegramUI/Sources/ChatController.swift | 56 +- .../Sources/ChatControllerNode.swift | 33 +- .../Sources/ChatHistoryListNode.swift | 30 +- .../ChatInterfaceStateContextMenus.swift | 2 +- .../Sources/ChatMessageBackground.swift | 17 + .../Sources/ChatMessageBubbleItemNode.swift | 57 +- .../Sources/ChatMessageItemView.swift | 3 + .../Sources/ChatMessageReplyInfoNode.swift | 80 + .../ChatMessageTextBubbleContentNode.swift | 20 + .../Sources/ChatMessageTransitionNode.swift | 191 ++ .../Sources/ChatTextInputPanelNode.swift | 57 +- .../LegacyInstantVideoController.swift | 2 +- .../TelegramUI/Sources/OpenChatMessage.swift | 2 +- .../Sources/PeerInfo/PeerInfoScreen.swift | 6 +- .../Sources/ReplyAccessoryPanelNode.swift | 24 +- .../Sources/SharedAccountContext.swift | 2 +- .../Sources/WatchRequestHandlers.swift | 10 +- 41 files changed, 682 insertions(+), 1687 deletions(-) create mode 100644 submodules/TelegramUI/Sources/ChatMessageTransitionNode.swift diff --git a/submodules/AsyncDisplayKit/Source/ASEditableTextNode.mm b/submodules/AsyncDisplayKit/Source/ASEditableTextNode.mm index 87baeb09ac..cf7fd8bd2d 100644 --- a/submodules/AsyncDisplayKit/Source/ASEditableTextNode.mm +++ b/submodules/AsyncDisplayKit/Source/ASEditableTextNode.mm @@ -1045,7 +1045,7 @@ CGFloat baselineNudge = (lineHeight - fontLineHeight) * 0.6f; CGRect rect = *lineFragmentRect; - rect.size.height = lineHeight; + rect.size.height = lineHeight + 2.0f; CGRect usedRect = *lineFragmentUsedRect; usedRect.size.height = MAX(lineHeight, usedRect.size.height); diff --git a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift index 8b14972bfb..a2df45c8cd 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift @@ -911,7 +911,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo (strongSelf.navigationController?.topViewController as? ViewController)?.present(UndoOverlayController(presentationData: presentationData, content: .forward(savedMessages: true, text: messages.count == 1 ? presentationData.strings.Conversation_ForwardTooltip_SavedMessages_One : presentationData.strings.Conversation_ForwardTooltip_SavedMessages_Many), elevatedLayout: false, animateInAsReplacement: true, action: { _ in return false }), in: .window(.root)) let _ = (enqueueMessages(account: strongSelf.context.account, peerId: peerId, messages: messageIds.map { id -> EnqueueMessage in - return .forward(source: id, grouping: .auto, attributes: []) + return .forward(source: id, grouping: .auto, attributes: [], correlationId: nil) }) |> deliverOnMainQueue).start(next: { [weak self] messageIds in if let strongSelf = self { diff --git a/submodules/ComposePollUI/Sources/CreatePollController.swift b/submodules/ComposePollUI/Sources/CreatePollController.swift index 1ea4d85aa7..a34359769f 100644 --- a/submodules/ComposePollUI/Sources/CreatePollController.swift +++ b/submodules/ComposePollUI/Sources/CreatePollController.swift @@ -825,7 +825,7 @@ public func createPollController(context: AccountContext, peer: Peer, isQuiz: Bo dismissImpl?() - completion(.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.LocalPoll, id: arc4random64()), publicity: publicity, kind: kind, text: processPollText(state.text), options: options, correctAnswers: correctAnswers, results: TelegramMediaPollResults(voters: nil, totalVoters: nil, recentVoters: [], solution: resolvedSolution), isClosed: false, deadlineTimeout: deadlineTimeout)), replyToMessageId: nil, localGroupingKey: nil)) + completion(.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaPoll(pollId: MediaId(namespace: Namespaces.Media.LocalPoll, id: arc4random64()), publicity: publicity, kind: kind, text: processPollText(state.text), options: options, correctAnswers: correctAnswers, results: TelegramMediaPollResults(voters: nil, totalVoters: nil, recentVoters: [], solution: resolvedSolution), isClosed: false, deadlineTimeout: deadlineTimeout)), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) }) let leftNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: { diff --git a/submodules/DebugSettingsUI/Sources/DebugController.swift b/submodules/DebugSettingsUI/Sources/DebugController.swift index bc10d7a500..784cf55f70 100644 --- a/submodules/DebugSettingsUI/Sources/DebugController.swift +++ b/submodules/DebugSettingsUI/Sources/DebugController.swift @@ -227,7 +227,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { context.account.postbox.mediaBox.storeResourceData(fileResource.id, data: logData) let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: id), partialReference: nil, resource: fileResource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "application/text", size: logData.count, attributes: [.FileName(fileName: "Log-iOS-Full.txt")]) - let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil) + let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) let _ = enqueueMessages(account: context.account, peerId: peerId, messages: [message]).start() } @@ -307,7 +307,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { context.account.postbox.mediaBox.storeResourceData(fileResource.id, data: logData) let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: id), partialReference: nil, resource: fileResource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "application/text", size: logData.count, attributes: [.FileName(fileName: "Log-iOS-Short.txt")]) - let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil) + let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) let _ = enqueueMessages(account: context.account, peerId: peerId, messages: [message]).start() } @@ -379,7 +379,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { context.account.postbox.mediaBox.storeResourceData(fileResource.id, data: logData) let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: id), partialReference: nil, resource: fileResource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "application/text", size: logData.count, attributes: [.FileName(fileName: "Log-iOS-Full.txt")]) - let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil) + let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) let _ = enqueueMessages(account: context.account, peerId: peerId, messages: [message]).start() } @@ -426,7 +426,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { let messages = logs.map { (name, path) -> EnqueueMessage in let id = arc4random64() let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: id), partialReference: nil, resource: LocalFileReferenceMediaResource(localFilePath: path, randomId: id), previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "application/text", size: nil, attributes: [.FileName(fileName: name)]) - return .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) } let _ = enqueueMessages(account: context.account, peerId: peerId, messages: messages).start() } @@ -457,7 +457,7 @@ private enum DebugControllerEntry: ItemListNodeEntry { let messages = logs.map { (name, path) -> EnqueueMessage in let id = arc4random64() let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: id), partialReference: nil, resource: LocalFileReferenceMediaResource(localFilePath: path, randomId: id), previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "application/text", size: nil, attributes: [.FileName(fileName: name)]) - return .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) } let _ = enqueueMessages(account: context.account, peerId: peerId, messages: messages).start() } diff --git a/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift b/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift index 8d23425be3..931d409726 100644 --- a/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift +++ b/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift @@ -349,7 +349,7 @@ public final class SecretMediaPreviewController: ViewController { |> deliverOnMainQueue).start(next: { [weak self] _ in if let strongSelf = self, strongSelf.traceVisibility() { if strongSelf.messageId.peerId.namespace == Namespaces.Peer.CloudUser { - let _ = enqueueMessages(account: strongSelf.context.account, peerId: strongSelf.messageId.peerId, messages: [.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaAction(action: TelegramMediaActionType.historyScreenshot)), replyToMessageId: nil, localGroupingKey: nil)]).start() + let _ = enqueueMessages(account: strongSelf.context.account, peerId: strongSelf.messageId.peerId, messages: [.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaAction(action: TelegramMediaActionType.historyScreenshot)), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]).start() } else if strongSelf.messageId.peerId.namespace == Namespaces.Peer.SecretChat { let _ = addSecretChatMessageScreenshot(account: strongSelf.context.account, peerId: strongSelf.messageId.peerId).start() } diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift index bc1fc47954..d37b82eebc 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift @@ -254,7 +254,7 @@ public func legacyAssetPickerItemGenerator() -> ((Any?, String?, [Any]?, String? } } -public func legacyEnqueueGifMessage(account: Account, data: Data) -> Signal { +public func legacyEnqueueGifMessage(account: Account, data: Data, correlationId: Int64? = nil) -> Signal { return Signal { subscriber in if let previewImage = UIImage(data: data) { let dimensions = previewImage.size @@ -286,7 +286,7 @@ public func legacyEnqueueGifMessage(account: Account, data: Data) -> Signal Signal runOn(Queue.concurrentDefaultQueue()) } -public func legacyEnqueueVideoMessage(account: Account, data: Data) -> Signal { +public func legacyEnqueueVideoMessage(account: Account, data: Data, correlationId: Int64? = nil) -> Signal { return Signal { subscriber in if let previewImage = UIImage(data: data) { let dimensions = previewImage.size @@ -328,7 +328,7 @@ public func legacyEnqueueVideoMessage(account: Account, data: Data) -> Signal 0 && timer <= 60 { attributes.append(AutoremoveTimeoutMessageAttribute(timeout: Int32(timer), countdownBeginTime: nil)) } - messages.append(.message(text: caption ?? "", attributes: attributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: item.groupedId)) + messages.append(.message(text: caption ?? "", attributes: attributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: item.groupedId, correlationId: nil)) case .tempFile: break } @@ -418,13 +418,13 @@ public func legacyAssetPickerEnqueueMessages(account: Account, signals: [Any]) - arc4random_buf(&randomId, 8) let resource = LocalFileReferenceMediaResource(localFilePath: path, randomId: randomId) let media = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: randomId), partialReference: nil, resource: resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: mimeType, size: nil, attributes: [.FileName(fileName: name)]) - messages.append(.message(text: caption ?? "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: item.groupedId)) + messages.append(.message(text: caption ?? "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: item.groupedId, correlationId: nil)) case let .asset(asset): var randomId: Int64 = 0 arc4random_buf(&randomId, 8) let resource = PhotoLibraryMediaResource(localIdentifier: asset.localIdentifier, uniqueId: arc4random64()) let media = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: randomId), partialReference: nil, resource: resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: mimeType, size: nil, attributes: [.FileName(fileName: name)]) - messages.append(.message(text: caption ?? "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: item.groupedId)) + messages.append(.message(text: caption ?? "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: item.groupedId, correlationId: nil)) default: break } @@ -552,7 +552,7 @@ public func legacyAssetPickerEnqueueMessages(account: Account, signals: [Any]) - if let timer = item.timer, timer > 0 && timer <= 60 { attributes.append(AutoremoveTimeoutMessageAttribute(timeout: Int32(timer), countdownBeginTime: nil)) } - messages.append(.message(text: caption ?? "", attributes: attributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: item.groupedId)) + messages.append(.message(text: caption ?? "", attributes: attributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: item.groupedId, correlationId: nil)) } } } diff --git a/submodules/PeerInfoUI/Sources/UserInfoController.swift b/submodules/PeerInfoUI/Sources/UserInfoController.swift index 1c8c012ebc..07faaa9665 100644 --- a/submodules/PeerInfoUI/Sources/UserInfoController.swift +++ b/submodules/PeerInfoUI/Sources/UserInfoController.swift @@ -29,744 +29,6 @@ import LocalizedPeerData import PhoneNumberFormat import TelegramIntents -private final class UserInfoControllerArguments { - let context: AccountContext - let avatarAndNameInfoContext: ItemListAvatarAndNameInfoItemContext - let updateEditingName: (ItemListAvatarAndNameInfoItemName) -> Void - let tapAvatarAction: () -> Void - let openChat: () -> Void - let addContact: () -> Void - let shareContact: () -> Void - let shareMyContact: () -> Void - let startSecretChat: () -> Void - let changeNotificationMuteSettings: () -> Void - let openSharedMedia: () -> Void - let openGroupsInCommon: () -> Void - let updatePeerBlocked: (Bool) -> Void - let deleteContact: () -> Void - let displayUsernameContextMenu: (String) -> Void - let displayCopyContextMenu: (UserInfoEntryTag, String) -> Void - let call: () -> Void - let openCallMenu: (String) -> Void - let requestPhoneNumber: () -> Void - let aboutLinkAction: (TextLinkItemActionType, TextLinkItem) -> Void - let displayAboutContextMenu: (String) -> Void - let openEncryptionKey: (SecretChatKeyFingerprint) -> Void - let addBotToGroup: () -> Void - let shareBot: () -> Void - let botSettings: () -> Void - let botHelp: () -> Void - let botPrivacy: () -> Void - let report: () -> Void - - init(context: AccountContext, avatarAndNameInfoContext: ItemListAvatarAndNameInfoItemContext, updateEditingName: @escaping (ItemListAvatarAndNameInfoItemName) -> Void, tapAvatarAction: @escaping () -> Void, openChat: @escaping () -> Void, addContact: @escaping () -> Void, shareContact: @escaping () -> Void, shareMyContact: @escaping () -> Void, startSecretChat: @escaping () -> Void, changeNotificationMuteSettings: @escaping () -> Void, openSharedMedia: @escaping () -> Void, openGroupsInCommon: @escaping () -> Void, updatePeerBlocked: @escaping (Bool) -> Void, deleteContact: @escaping () -> Void, displayUsernameContextMenu: @escaping (String) -> Void, displayCopyContextMenu: @escaping (UserInfoEntryTag, String) -> Void, call: @escaping () -> Void, openCallMenu: @escaping (String) -> Void, requestPhoneNumber: @escaping () -> Void, aboutLinkAction: @escaping (TextLinkItemActionType, TextLinkItem) -> Void, displayAboutContextMenu: @escaping (String) -> Void, openEncryptionKey: @escaping (SecretChatKeyFingerprint) -> Void, addBotToGroup: @escaping () -> Void, shareBot: @escaping () -> Void, botSettings: @escaping () -> Void, botHelp: @escaping () -> Void, botPrivacy: @escaping () -> Void, report: @escaping () -> Void) { - self.context = context - self.avatarAndNameInfoContext = avatarAndNameInfoContext - self.updateEditingName = updateEditingName - self.tapAvatarAction = tapAvatarAction - self.openChat = openChat - self.addContact = addContact - - self.shareContact = shareContact - self.shareMyContact = shareMyContact - self.startSecretChat = startSecretChat - self.changeNotificationMuteSettings = changeNotificationMuteSettings - self.openSharedMedia = openSharedMedia - self.openGroupsInCommon = openGroupsInCommon - self.updatePeerBlocked = updatePeerBlocked - self.deleteContact = deleteContact - self.displayUsernameContextMenu = displayUsernameContextMenu - self.displayCopyContextMenu = displayCopyContextMenu - self.call = call - self.openCallMenu = openCallMenu - self.requestPhoneNumber = requestPhoneNumber - self.aboutLinkAction = aboutLinkAction - self.displayAboutContextMenu = displayAboutContextMenu - self.openEncryptionKey = openEncryptionKey - self.addBotToGroup = addBotToGroup - self.shareBot = shareBot - self.botSettings = botSettings - self.botHelp = botHelp - self.botPrivacy = botPrivacy - self.report = report - } -} - -private enum UserInfoSection: ItemListSectionId { - case info - case actions - case sharedMediaAndNotifications - case bot - case block -} - -private enum UserInfoEntryTag { - case about - case phoneNumber - case username -} - -private func areMessagesEqual(_ lhsMessage: Message, _ rhsMessage: Message) -> Bool { - if lhsMessage.stableVersion != rhsMessage.stableVersion { - return false - } - if lhsMessage.id != rhsMessage.id || lhsMessage.flags != rhsMessage.flags { - return false - } - return true -} - -private enum UserInfoEntry: ItemListNodeEntry { - case info(PresentationTheme, PresentationStrings, PresentationDateTimeFormat, peer: Peer?, presence: PeerPresence?, cachedData: CachedPeerData?, state: ItemListAvatarAndNameInfoItemState, displayCall: Bool) - case calls(PresentationTheme, PresentationStrings, PresentationDateTimeFormat, messages: [Message]) - case about(PresentationTheme, Peer, String, String) - case phoneNumber(PresentationTheme, Int, String, String, Bool) - case requestPhoneNumber(PresentationTheme, String, String) - case userName(PresentationTheme, String, String) - case sendMessage(PresentationTheme, String) - case addContact(PresentationTheme, String) - case shareContact(PresentationTheme, String) - case shareMyContact(PresentationTheme, String) - case startSecretChat(PresentationTheme, String) - case sharedMedia(PresentationTheme, String) - case notifications(PresentationTheme, String, String) - case groupsInCommon(PresentationTheme, String, String) - case secretEncryptionKey(PresentationTheme, String, SecretChatKeyFingerprint) - case botAddToGroup(PresentationTheme, String) - case botShare(PresentationTheme, String) - case botSettings(PresentationTheme, String) - case botHelp(PresentationTheme, String) - case botPrivacy(PresentationTheme, String) - case botReport(PresentationTheme, String) - case block(PresentationTheme, String, DestructiveUserInfoAction) - - var section: ItemListSectionId { - switch self { - case .info, .calls, .about, .phoneNumber, .requestPhoneNumber, .userName: - return UserInfoSection.info.rawValue - case .sendMessage, .addContact, .shareContact, .shareMyContact, .startSecretChat, .botAddToGroup, .botShare: - return UserInfoSection.actions.rawValue - case .botSettings, .botHelp, .botPrivacy: - return UserInfoSection.bot.rawValue - case .sharedMedia, .notifications, .groupsInCommon, .secretEncryptionKey: - return UserInfoSection.sharedMediaAndNotifications.rawValue - case .botReport, .block: - return UserInfoSection.block.rawValue - } - } - - var stableId: Int { - return self.sortIndex - } - - static func ==(lhs: UserInfoEntry, rhs: UserInfoEntry) -> Bool { - switch lhs { - case let .info(lhsTheme, lhsStrings, lhsDateTimeFormat, lhsPeer, lhsPresence, lhsCachedData, lhsState, lhsDisplayCall): - switch rhs { - case let .info(rhsTheme, rhsStrings, rhsDateTimeFormat, rhsPeer, rhsPresence, rhsCachedData, rhsState, rhsDisplayCall): - if lhsTheme !== rhsTheme { - return false - } - if lhsStrings !== rhsStrings { - return false - } - if lhsDateTimeFormat != rhsDateTimeFormat { - return false - } - if let lhsPeer = lhsPeer, let rhsPeer = rhsPeer { - if !lhsPeer.isEqual(rhsPeer) { - return false - } - } else if (lhsPeer != nil) != (rhsPeer != nil) { - return false - } - if let lhsPresence = lhsPresence, let rhsPresence = rhsPresence { - if !lhsPresence.isEqual(to: rhsPresence) { - return false - } - } else if (lhsPresence != nil) != (rhsPresence != nil) { - return false - } - if let lhsCachedData = lhsCachedData, let rhsCachedData = rhsCachedData { - if !lhsCachedData.isEqual(to: rhsCachedData) { - return false - } - } else if (lhsCachedData != nil) != (rhsCachedData != nil) { - return false - } - if lhsState != rhsState { - return false - } - if lhsDisplayCall != rhsDisplayCall { - return false - } - return true - default: - return false - } - case let .calls(lhsTheme, lhsStrings, lhsDateTimeFormat, lhsMessages): - if case let .calls(rhsTheme, rhsStrings, rhsDateTimeFormat, rhsMessages) = rhs, lhsTheme === rhsTheme, lhsStrings === rhsStrings, lhsDateTimeFormat == rhsDateTimeFormat { - if lhsMessages.count != rhsMessages.count { - return false - } - for i in 0 ..< lhsMessages.count { - if !areMessagesEqual(lhsMessages[i], rhsMessages[i]) { - return false - } - } - return true - } else { - return false - } - case let .about(lhsTheme, lhsPeer, lhsText, lhsValue): - if case let .about(rhsTheme, rhsPeer, rhsText, rhsValue) = rhs, lhsTheme === rhsTheme, lhsPeer.isEqual(rhsPeer), lhsText == rhsText, lhsValue == rhsValue { - return true - } else { - return false - } - case let .phoneNumber(lhsTheme, lhsIndex, lhsLabel, lhsValue, lhsMain): - if case let .phoneNumber(rhsTheme, rhsIndex, rhsLabel, rhsValue, rhsMain) = rhs, lhsTheme === rhsTheme, lhsIndex == rhsIndex, lhsLabel == rhsLabel, lhsValue == rhsValue, lhsMain == rhsMain { - return true - } else { - return false - } - case let .requestPhoneNumber(lhsTheme, lhsLabel, lhsValue): - if case let .requestPhoneNumber(rhsTheme, rhsLabel, rhsValue) = rhs, lhsTheme === rhsTheme, lhsLabel == rhsLabel, lhsValue == rhsValue { - return true - } else { - return false - } - case let .userName(lhsTheme, lhsText, lhsValue): - if case let .userName(rhsTheme, rhsText, rhsValue) = rhs, lhsTheme === rhsTheme, lhsText == rhsText, lhsValue == rhsValue { - return true - } else { - return false - } - case let .sendMessage(lhsTheme, lhsText): - if case let .sendMessage(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .addContact(lhsTheme, lhsText): - if case let .addContact(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .shareContact(lhsTheme, lhsText): - if case let .shareContact(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .shareMyContact(lhsTheme, lhsText): - if case let .shareMyContact(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .startSecretChat(lhsTheme, lhsText): - if case let .startSecretChat(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .sharedMedia(lhsTheme, lhsText): - if case let .sharedMedia(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .notifications(lhsTheme, lhsText, lhsValue): - if case let .notifications(rhsTheme, rhsText, rhsValue) = rhs, lhsTheme === rhsTheme, lhsText == rhsText, lhsValue == rhsValue { - return true - } else { - return false - } - case let .groupsInCommon(lhsTheme, lhsText, lhsValue): - if case let .groupsInCommon(rhsTheme, rhsText, rhsValue) = rhs, lhsTheme === rhsTheme, lhsText == rhsText, lhsValue == rhsValue { - return true - } else { - return false - } - case let .secretEncryptionKey(lhsTheme, lhsText, lhsValue): - if case let .secretEncryptionKey(rhsTheme, rhsText, rhsValue) = rhs, lhsTheme === rhsTheme, lhsText == rhsText, lhsValue == rhsValue { - return true - } else { - return false - } - case let .botAddToGroup(lhsTheme, lhsText): - if case let .botAddToGroup(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .botShare(lhsTheme, lhsText): - if case let .botShare(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .botSettings(lhsTheme, lhsText): - if case let .botSettings(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .botHelp(lhsTheme, lhsText): - if case let .botHelp(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .botPrivacy(lhsTheme, lhsText): - if case let .botPrivacy(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .botReport(lhsTheme, lhsText): - if case let .botReport(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText { - return true - } else { - return false - } - case let .block(lhsTheme, lhsText, lhsAction): - if case let .block(rhsTheme, rhsText, rhsAction) = rhs, lhsTheme === rhsTheme, lhsText == rhsText, lhsAction == rhsAction { - return true - } else { - return false - } - } - } - - private var sortIndex: Int { - switch self { - case .info: - return 0 - case .calls: - return 1 - case let .phoneNumber(_, index, _, _, _): - return 2 + index - case .requestPhoneNumber: - return 998 - case .about: - return 999 - case .userName: - return 1000 - case .sendMessage: - return 1001 - case .addContact: - return 1002 - case .shareContact: - return 1003 - case .shareMyContact: - return 1004 - case .startSecretChat: - return 1005 - case .botAddToGroup: - return 1006 - case .botShare: - return 1007 - case .botSettings: - return 1008 - case .botHelp: - return 1009 - case .botPrivacy: - return 1010 - case .sharedMedia: - return 1011 - case .notifications: - return 1012 - case .secretEncryptionKey: - return 1014 - case .groupsInCommon: - return 1015 - case .botReport: - return 1016 - case .block: - return 1017 - } - } - - static func <(lhs: UserInfoEntry, rhs: UserInfoEntry) -> Bool { - return lhs.sortIndex < rhs.sortIndex - } - - func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { - let arguments = arguments as! UserInfoControllerArguments - switch self { - case let .info(theme, strings, dateTimeFormat, peer, presence, cachedData, state, displayCall): - return ItemListAvatarAndNameInfoItem(accountContext: arguments.context, presentationData: presentationData, dateTimeFormat: dateTimeFormat, mode: .generic, peer: peer, presence: presence, cachedData: cachedData, state: state, sectionId: self.section, style: .plain, editingNameUpdated: { editingName in - arguments.updateEditingName(editingName) - }, avatarTapped: { - arguments.tapAvatarAction() - }, context: arguments.avatarAndNameInfoContext, call: displayCall ? { - arguments.call() - } : nil) - case let .calls(theme, strings, dateTimeFormat, messages): - return ItemListCallListItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, messages: messages, sectionId: self.section, style: .plain) - case let .about(theme, peer, text, value): - var enabledEntityTypes: EnabledEntityTypes = [] - if let peer = peer as? TelegramUser, let _ = peer.botInfo { - enabledEntityTypes = [.allUrl, .mention, .hashtag] - } - return ItemListTextWithLabelItem(presentationData: presentationData, label: text, text: foldMultipleLineBreaks(value), enabledEntityTypes: enabledEntityTypes, multiline: true, sectionId: self.section, action: nil, longTapAction: { - arguments.displayAboutContextMenu(value) - }, linkItemAction: { action, itemLink in - arguments.aboutLinkAction(action, itemLink) - }, tag: UserInfoEntryTag.about) - case let .phoneNumber(theme, _, label, value, isMain): - return ItemListTextWithLabelItem(presentationData: presentationData, label: label, text: value, textColor: isMain ? .highlighted : .accent, enabledEntityTypes: [], multiline: false, sectionId: self.section, action: { - arguments.openCallMenu(value) - }, longTapAction: { - arguments.displayCopyContextMenu(.phoneNumber, value) - }, tag: UserInfoEntryTag.phoneNumber) - case let .requestPhoneNumber(theme, label, value): - return ItemListTextWithLabelItem(presentationData: presentationData, label: label, text: value, textColor: .accent, enabledEntityTypes: [], multiline: false, sectionId: self.section, action: { - arguments.requestPhoneNumber() - }) - case let .userName(theme, text, value): - return ItemListTextWithLabelItem(presentationData: presentationData, label: text, text: "@\(value)", textColor: .accent, enabledEntityTypes: [], multiline: false, sectionId: self.section, action: { - arguments.displayUsernameContextMenu("@\(value)") - }, longTapAction: { - arguments.displayCopyContextMenu(.username, "@\(value)") - }, tag: UserInfoEntryTag.username) - case let .sendMessage(theme, text): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .plain, action: { - arguments.openChat() - }) - case let .addContact(theme, text): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .plain, action: { - arguments.addContact() - }) - case let .shareContact(theme, text): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .plain, action: { - arguments.shareContact() - }) - case let .shareMyContact(theme, text): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .plain, action: { - arguments.shareMyContact() - }) - case let .startSecretChat(theme, text): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .plain, action: { - arguments.startSecretChat() - }) - case let .sharedMedia(theme, text): - return ItemListDisclosureItem(presentationData: presentationData, title: text, label: "", sectionId: self.section, style: .plain, action: { - arguments.openSharedMedia() - }) - case let .notifications(theme, text, value): - return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .plain, action: { - arguments.changeNotificationMuteSettings() - }) - case let .groupsInCommon(theme, text, value): - return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .plain, action: { - arguments.openGroupsInCommon() - }) - case let .secretEncryptionKey(theme, text, fingerprint): - return ItemListSecretChatKeyItem(presentationData: presentationData, title: text, fingerprint: fingerprint, sectionId: self.section, style: .plain, action: { - arguments.openEncryptionKey(fingerprint) - }) - case let .botAddToGroup(theme, text): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .plain, action: { - arguments.addBotToGroup() - }) - case let .botShare(theme, text): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .plain, action: { - arguments.shareBot() - }) - case let .botSettings(theme, text): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .plain, action: { - arguments.botSettings() - }) - case let .botHelp(theme, text): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .plain, action: { - arguments.botHelp() - }) - case let .botPrivacy(theme, text): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .plain, action: { - arguments.botPrivacy() - }) - case let .botReport(theme, text): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .plain, action: { - arguments.report() - }) - case let .block(theme, text, action): - return ItemListActionItem(presentationData: presentationData, title: text, kind: .destructive, alignment: .natural, sectionId: self.section, style: .plain, action: { - switch action { - case .block: - arguments.updatePeerBlocked(true) - case .unblock: - arguments.updatePeerBlocked(false) - case .removeContact: - arguments.deleteContact() - } - }) - } - } -} - -private enum DestructiveUserInfoAction { - case block - case removeContact - case unblock -} - -private struct UserInfoEditingState: Equatable { - let editingName: ItemListAvatarAndNameInfoItemName? - - static func ==(lhs: UserInfoEditingState, rhs: UserInfoEditingState) -> Bool { - if lhs.editingName != rhs.editingName { - return false - } - return true - } -} - -private struct UserInfoState: Equatable { - let savingData: Bool - let editingState: UserInfoEditingState? - - init() { - self.savingData = false - self.editingState = nil - } - - init(savingData: Bool, editingState: UserInfoEditingState?) { - self.savingData = savingData - self.editingState = editingState - } - - static func ==(lhs: UserInfoState, rhs: UserInfoState) -> Bool { - if lhs.savingData != rhs.savingData { - return false - } - if lhs.editingState != rhs.editingState { - return false - } - return true - } - - func withUpdatedSavingData(_ savingData: Bool) -> UserInfoState { - return UserInfoState(savingData: savingData, editingState: self.editingState) - } - - func withUpdatedEditingState(_ editingState: UserInfoEditingState?) -> UserInfoState { - return UserInfoState(savingData: self.savingData, editingState: editingState) - } -} - -private func stringForBlockAction(strings: PresentationStrings, action: DestructiveUserInfoAction, peer: Peer) -> String { - switch action { - case .block: - if let user = peer as? TelegramUser, user.botInfo != nil { - return strings.Bot_Stop - } else { - return strings.Conversation_BlockUser - } - case .unblock: - if let user = peer as? TelegramUser, user.botInfo != nil { - return strings.Bot_Unblock - } else { - return strings.Conversation_UnblockUser - } - case .removeContact: - return strings.UserInfo_DeleteContact - } -} - -private func userInfoEntries(account: Account, presentationData: PresentationData, view: PeerView, cachedPeerData: CachedPeerData?, deviceContacts: [(DeviceContactStableId, DeviceContactBasicData)], mode: PeerInfoControllerMode, state: UserInfoState, peerChatState: PostboxCoding?, globalNotificationSettings: GlobalNotificationSettings) -> [UserInfoEntry] { - var entries: [UserInfoEntry] = [] - - guard let peer = view.peers[view.peerId], let user = peerViewMainPeer(view) as? TelegramUser else { - return [] - } - - var editingName: ItemListAvatarAndNameInfoItemName? - - var isEditing = false - if let editingState = state.editingState { - isEditing = true - - if view.peerIsContact { - editingName = editingState.editingName - } - } - - var callsAvailable = true - if let cachedUserData = cachedPeerData as? CachedUserData { - callsAvailable = cachedUserData.voiceCallsAvailable - } - - entries.append(UserInfoEntry.info(presentationData.theme, presentationData.strings, presentationData.dateTimeFormat, peer: user, presence: view.peerPresences[user.id], cachedData: cachedPeerData, state: ItemListAvatarAndNameInfoItemState(editingName: editingName, updatingName: nil), displayCall: user.botInfo == nil && callsAvailable)) - - if case let .calls(messages) = mode, !isEditing { - entries.append(UserInfoEntry.calls(presentationData.theme, presentationData.strings, presentationData.dateTimeFormat, messages: messages)) - } - - if let phoneNumber = user.phone, !phoneNumber.isEmpty { - let formattedNumber = formatPhoneNumber(phoneNumber) - let normalizedNumber = DeviceContactNormalizedPhoneNumber(rawValue: formattedNumber) - - var index = 0 - var found = false - - var existingNumbers = Set() - var phoneNumbers: [(String, DeviceContactNormalizedPhoneNumber, Bool)] = [] - - for (_, contact) in deviceContacts { - inner: for number in contact.phoneNumbers { - var isMain = false - let normalizedContactNumber = DeviceContactNormalizedPhoneNumber(rawValue: formatPhoneNumber(number.value)) - if !existingNumbers.contains(normalizedContactNumber) { - existingNumbers.insert(normalizedContactNumber) - } else { - continue inner - } - if normalizedContactNumber == normalizedNumber { - found = true - isMain = true - } - - phoneNumbers.append((number.label, normalizedContactNumber, isMain)) - } - } - if !found { - entries.append(UserInfoEntry.phoneNumber(presentationData.theme, index, presentationData.strings.ContactInfo_PhoneLabelMobile, formattedNumber, false)) - index += 1 - } else { - for (label, number, isMain) in phoneNumbers { - entries.append(UserInfoEntry.phoneNumber(presentationData.theme, index, localizedPhoneNumberLabel(label: label, strings: presentationData.strings), number.rawValue, isMain && phoneNumbers.count != 1)) - index += 1 - } - } - } else { - //entries.append(UserInfoEntry.requestPhoneNumber(presentationData.theme, "phone", "Request Number")) - } - - let aboutTitle: String - if let _ = user.botInfo { - aboutTitle = presentationData.strings.Profile_BotInfo - } else { - aboutTitle = presentationData.strings.Profile_About - } - if user.isFake { - let aboutValue: String - if let _ = user.botInfo { - aboutValue = presentationData.strings.UserInfo_FakeBotWarning - } else { - aboutValue = presentationData.strings.UserInfo_FakeUserWarning - } - entries.append(UserInfoEntry.about(presentationData.theme, peer, aboutTitle, aboutValue)) - } else if user.isScam { - let aboutValue: String - if let _ = user.botInfo { - aboutValue = presentationData.strings.UserInfo_ScamBotWarning - } else { - aboutValue = presentationData.strings.UserInfo_ScamUserWarning - } - entries.append(UserInfoEntry.about(presentationData.theme, peer, aboutTitle, aboutValue)) - } else if let cachedUserData = cachedPeerData as? CachedUserData, let about = cachedUserData.about, !about.isEmpty { - entries.append(UserInfoEntry.about(presentationData.theme, peer, aboutTitle, about)) - } - - if !isEditing { - if let username = user.username, !username.isEmpty { - entries.append(UserInfoEntry.userName(presentationData.theme, presentationData.strings.Profile_Username, username)) - } - - if !(peer is TelegramSecretChat) { - entries.append(UserInfoEntry.sendMessage(presentationData.theme, presentationData.strings.UserInfo_SendMessage)) - } - - if user.botInfo == nil { - if view.peerIsContact { - if let phone = user.phone, !phone.isEmpty { - entries.append(UserInfoEntry.shareContact(presentationData.theme, presentationData.strings.UserInfo_ShareContact)) - } - } else { - entries.append(UserInfoEntry.addContact(presentationData.theme, presentationData.strings.Conversation_AddToContacts)) - } - } - - if let cachedUserData = cachedPeerData as? CachedUserData, let peerStatusSettings = cachedUserData.peerStatusSettings, peerStatusSettings.contains(.canShareContact) { - entries.append(UserInfoEntry.shareMyContact(presentationData.theme, presentationData.strings.UserInfo_ShareMyContactInfo)) - } - - if let peer = peer as? TelegramUser, peer.botInfo == nil { - entries.append(UserInfoEntry.startSecretChat(presentationData.theme, presentationData.strings.UserInfo_StartSecretChat)) - } - - if let peer = peer as? TelegramUser, let botInfo = peer.botInfo { - if botInfo.flags.contains(.worksWithGroups) { - entries.append(UserInfoEntry.botAddToGroup(presentationData.theme, presentationData.strings.UserInfo_InviteBotToGroup)) - } - entries.append(UserInfoEntry.botShare(presentationData.theme, presentationData.strings.UserInfo_ShareBot)) - - if let cachedUserData = cachedPeerData as? CachedUserData, let botInfo = cachedUserData.botInfo { - for command in botInfo.commands { - if command.text == "settings" { - entries.append(UserInfoEntry.botSettings(presentationData.theme, presentationData.strings.UserInfo_BotSettings)) - } else if command.text == "help" { - entries.append(UserInfoEntry.botHelp(presentationData.theme, presentationData.strings.UserInfo_BotHelp)) - } else if command.text == "privacy" { - entries.append(UserInfoEntry.botPrivacy(presentationData.theme, presentationData.strings.UserInfo_BotPrivacy)) - } - } - } - } - - entries.append(UserInfoEntry.sharedMedia(presentationData.theme, presentationData.strings.GroupInfo_SharedMedia)) - } - let notificationsLabel: String - let notificationSettings = view.notificationSettings as? TelegramPeerNotificationSettings ?? TelegramPeerNotificationSettings.defaultSettings - if case let .muted(until) = notificationSettings.muteState, until >= Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) { - if until < Int32.max - 1 { - notificationsLabel = stringForRemainingMuteInterval(strings: presentationData.strings, muteInterval: until) - } else { - notificationsLabel = presentationData.strings.UserInfo_NotificationsDisabled - } - } else if case .default = notificationSettings.messageSound { - notificationsLabel = presentationData.strings.UserInfo_NotificationsEnabled - } else { - notificationsLabel = localizedPeerNotificationSoundString(strings: presentationData.strings, sound: notificationSettings.messageSound, default: globalNotificationSettings.effective.channels.sound) - } - entries.append(UserInfoEntry.notifications(presentationData.theme, presentationData.strings.GroupInfo_Notifications, notificationsLabel)) - - if isEditing { - if view.peerIsContact { - entries.append(UserInfoEntry.block(presentationData.theme, stringForBlockAction(strings: presentationData.strings, action: .removeContact, peer: user), .removeContact)) - } - } else { - if peer is TelegramSecretChat, let peerChatState = peerChatState as? SecretChatKeyState, let keyFingerprint = peerChatState.keyFingerprint { - entries.append(UserInfoEntry.secretEncryptionKey(presentationData.theme, presentationData.strings.Profile_EncryptionKey, keyFingerprint)) - } - - if let groupsInCommon = (cachedPeerData as? CachedUserData)?.commonGroupCount, groupsInCommon != 0 { - entries.append(UserInfoEntry.groupsInCommon(presentationData.theme, presentationData.strings.UserInfo_GroupsInCommon, presentationStringsFormattedNumber(groupsInCommon, presentationData.dateTimeFormat.groupingSeparator))) - } - - if let peer = peer as? TelegramUser, let _ = peer.botInfo { - entries.append(UserInfoEntry.botReport(presentationData.theme, presentationData.strings.ReportPeer_Report)) - } - - if let cachedData = cachedPeerData as? CachedUserData { - if cachedData.isBlocked { - entries.append(UserInfoEntry.block(presentationData.theme, stringForBlockAction(strings: presentationData.strings, action: .unblock, peer: user), .unblock)) - } else { - if let peer = peer as? TelegramUser, peer.flags.contains(.isSupport) { - } else { - entries.append(UserInfoEntry.block(presentationData.theme, stringForBlockAction(strings: presentationData.strings, action: .block, peer: user), .block)) - } - } - } - } - - return entries -} - private func getUserPeer(postbox: Postbox, peerId: PeerId) -> Signal<(Peer?, CachedPeerData?), NoError> { return postbox.transaction { transaction -> (Peer?, CachedPeerData?) in guard let peer = transaction.getPeer(peerId) else { @@ -805,803 +67,3 @@ public func openAddPersonContactImpl(context: AccountContext, peerId: PeerId, pu }), completed: nil, cancelled: nil)) }) } - -public func userInfoController(context: AccountContext, peerId: PeerId, mode: PeerInfoControllerMode = .generic) -> ViewController { - let statePromise = ValuePromise(UserInfoState(), ignoreRepeated: true) - let stateValue = Atomic(value: UserInfoState()) - let updateState: ((UserInfoState) -> UserInfoState) -> Void = { f in - statePromise.set(stateValue.modify { f($0) }) - } - - var pushControllerImpl: ((ViewController) -> Void)? - var presentControllerImpl: ((ViewController, Any?) -> Void)? - var openChatImpl: (() -> Void)? - var shareContactImpl: (() -> Void)? - var shareMyContactImpl: (() -> Void)? - var startSecretChatImpl: (() -> Void)? - var botAddToGroupImpl: (() -> Void)? - var shareBotImpl: (() -> Void)? - var dismissInputImpl: (() -> Void)? - var dismissImpl: (() -> Void)? - - let actionsDisposable = DisposableSet() - - let updatePeerNameDisposable = MetaDisposable() - actionsDisposable.add(updatePeerNameDisposable) - - let updatePeerBlockedDisposable = MetaDisposable() - actionsDisposable.add(updatePeerBlockedDisposable) - - let changeMuteSettingsDisposable = MetaDisposable() - actionsDisposable.add(changeMuteSettingsDisposable) - - let hiddenAvatarRepresentationDisposable = MetaDisposable() - actionsDisposable.add(hiddenAvatarRepresentationDisposable) - - let createSecretChatDisposable = MetaDisposable() - actionsDisposable.add(createSecretChatDisposable) - - let navigateDisposable = MetaDisposable() - actionsDisposable.add(navigateDisposable) - - var avatarGalleryTransitionArguments: ((AvatarGalleryEntry) -> GalleryTransitionArguments?)? - let avatarAndNameInfoContext = ItemListAvatarAndNameInfoItemContext() - var updateHiddenAvatarImpl: (() -> Void)? - - var aboutLinkActionImpl: ((TextLinkItemActionType, TextLinkItem) -> Void)? - var displayAboutContextMenuImpl: ((String) -> Void)? - var displayCopyContextMenuImpl: ((UserInfoEntryTag, String) -> Void)? - var popToRootImpl: (() -> Void)? - - let cachedAvatarEntries = Atomic?>(value: nil) - - let peerView = Promise<(PeerView, CachedPeerData?)>() - peerView.set(context.account.viewTracker.peerView(peerId, updateData: true) |> mapToSignal({ view -> Signal<(PeerView, CachedPeerData?), NoError> in - if peerId.namespace == Namespaces.Peer.SecretChat { - if let peer = peerViewMainPeer(view) { - return context.account.viewTracker.peerView(peer.id) |> map({ secretChatView -> (PeerView, CachedPeerData?) in - return (view, secretChatView.cachedData) - }) - } - } - return .single((view, view.cachedData)) - })) - - let requestCallImpl: (Bool) -> Void = { isVideo in - let _ = (peerView.get() - |> take(1) - |> deliverOnMainQueue).start(next: { view in - guard let peer = peerViewMainPeer(view.0) else { - return - } - - if let cachedUserData = view.1 as? CachedUserData, cachedUserData.callsPrivate { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - presentControllerImpl?(textAlertController(context: context, title: presentationData.strings.Call_ConnectionErrorTitle, text: presentationData.strings.Call_PrivacyErrorMessage(peer.compactDisplayTitle).0, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil) - return - } - - context.requestCall(peerId: peer.id, isVideo: isVideo, completion: {}) - }) - } - - let arguments = UserInfoControllerArguments(context: context, avatarAndNameInfoContext: avatarAndNameInfoContext, updateEditingName: { editingName in - updateState { state in - if let _ = state.editingState { - return state.withUpdatedEditingState(UserInfoEditingState(editingName: editingName)) - } else { - return state - } - } - }, tapAvatarAction: { - let _ = (getUserPeer(postbox: context.account.postbox, peerId: peerId) |> deliverOnMainQueue).start(next: { peer, _ in - guard let peer = peer else { - return - } - - if peer.profileImageRepresentations.isEmpty { - return - } - - let galleryController = AvatarGalleryController(context: context, peer: peer, remoteEntries: cachedAvatarEntries.with { $0 }, replaceRootController: { controller, ready in - }) - hiddenAvatarRepresentationDisposable.set((galleryController.hiddenMedia |> deliverOnMainQueue).start(next: { entry in - avatarAndNameInfoContext.hiddenAvatarRepresentation = entry?.representations.first?.representation - updateHiddenAvatarImpl?() - })) - presentControllerImpl?(galleryController, AvatarGalleryControllerPresentationArguments(transitionArguments: { entry in - return avatarGalleryTransitionArguments?(entry) - })) - }) - }, openChat: { - openChatImpl?() - }, addContact: { - openAddPersonContactImpl(context: context, peerId: peerId, pushController: { c in - pushControllerImpl?(c) - }, present: { c, a in - presentControllerImpl?(c, a) - }) - }, shareContact: { - shareContactImpl?() - }, shareMyContact: { - shareMyContactImpl?() - }, startSecretChat: { - startSecretChatImpl?() - }, changeNotificationMuteSettings: { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let _ = (context.account.postbox.transaction { transaction -> (TelegramPeerNotificationSettings, GlobalNotificationSettings) in - let peerSettings: TelegramPeerNotificationSettings = (transaction.getPeerNotificationSettings(peerId) as? TelegramPeerNotificationSettings) ?? TelegramPeerNotificationSettings.defaultSettings - let globalSettings: GlobalNotificationSettings = (transaction.getPreferencesEntry(key: PreferencesKeys.globalNotifications) as? GlobalNotificationSettings) ?? GlobalNotificationSettings.defaultSettings - return (peerSettings, globalSettings) - } - |> deliverOnMainQueue).start(next: { peerSettings, globalSettings in - let soundSettings: NotificationSoundSettings? - if case .default = peerSettings.messageSound { - soundSettings = NotificationSoundSettings(value: nil) - } else { - soundSettings = NotificationSoundSettings(value: peerSettings.messageSound) - } - let controller = notificationMuteSettingsController(presentationData: presentationData, notificationSettings: globalSettings.effective.groupChats, soundSettings: soundSettings, openSoundSettings: { - let controller = notificationSoundSelectionController(context: context, isModal: true, currentSound: peerSettings.messageSound, defaultSound: globalSettings.effective.groupChats.sound, completion: { sound in - let _ = updatePeerNotificationSoundInteractive(account: context.account, peerId: peerId, sound: sound).start() - }) - presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) - }, updateSettings: { value in - changeMuteSettingsDisposable.set(updatePeerMuteSetting(account: context.account, peerId: peerId, muteInterval: value).start()) - }) - presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) - }) - }, openSharedMedia: { - if let controller = context.sharedContext.makePeerSharedMediaController(context: context, peerId: peerId) { - pushControllerImpl?(controller) - } - }, openGroupsInCommon: { - let _ = (getUserPeer(postbox: context.account.postbox, peerId: peerId) - |> take(1) - |> deliverOnMainQueue).start(next: { peer, _ in - guard let peer = peer else { - return - } - - pushControllerImpl?(groupsInCommonController(context: context, peerId: peer.id)) - }) - }, updatePeerBlocked: { value in - let _ = (getUserPeer(postbox: context.account.postbox, peerId: peerId) - |> take(1) - |> deliverOnMainQueue).start(next: { peer, _ in - guard let peer = peer else { - return - } - - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - if let peer = peer as? TelegramUser, let _ = peer.botInfo { - updatePeerBlockedDisposable.set(requestUpdatePeerIsBlocked(account: context.account, peerId: peer.id, isBlocked: value).start()) - if !value { - let _ = enqueueMessages(account: context.account, peerId: peer.id, messages: [.message(text: "/start", attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]).start() - openChatImpl?() - } - } else { - if value { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let controller = ActionSheetController(presentationData: presentationData) - let dismissAction: () -> Void = { [weak controller] in - controller?.dismissAnimated() - } - var reportSpam = false - var deleteChat = false - controller.setItemGroups([ - ActionSheetItemGroup(items: [ - ActionSheetTextItem(title: presentationData.strings.UserInfo_BlockConfirmationTitle(peer.compactDisplayTitle).0), - /*ActionSheetCheckboxItem(title: presentationData.strings.Conversation_Moderate_Report, label: "", value: reportSpam, action: { [weak controller] checkValue in - reportSpam = checkValue - controller?.updateItem(groupIndex: 0, itemIndex: 1, { item in - if let item = item as? ActionSheetCheckboxItem { - return ActionSheetCheckboxItem(title: item.title, label: item.label, value: !item.value, action: item.action) - } - return item - }) - }), - ActionSheetCheckboxItem(title: presentationData.strings.ReportSpam_DeleteThisChat, label: "", value: deleteChat, action: { [weak controller] checkValue in - deleteChat = checkValue - controller?.updateItem(groupIndex: 0, itemIndex: 2, { item in - if let item = item as? ActionSheetCheckboxItem { - return ActionSheetCheckboxItem(title: item.title, label: item.label, value: !item.value, action: item.action) - } - return item - }) - }),*/ - ActionSheetButtonItem(title: presentationData.strings.UserInfo_BlockActionTitle(peer.compactDisplayTitle).0, color: .destructive, action: { - dismissAction() - updatePeerBlockedDisposable.set(requestUpdatePeerIsBlocked(account: context.account, peerId: peer.id, isBlocked: true).start()) - if deleteChat { - let _ = removePeerChat(account: context.account, peerId: peerId, reportChatSpam: reportSpam).start() - popToRootImpl?() - } else if reportSpam { - let _ = reportPeer(account: context.account, peerId: peerId, reason: .spam, message: "").start() - } - - deleteSendMessageIntents(peerId: peerId) - }) - ]), - ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })]) - ]) - presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) - } else { - let text: String - if value { - text = presentationData.strings.UserInfo_BlockConfirmation(peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).0 - } else { - text = presentationData.strings.UserInfo_UnblockConfirmation(peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)).0 - } - presentControllerImpl?(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_No, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.Common_Yes, action: { - updatePeerBlockedDisposable.set(requestUpdatePeerIsBlocked(account: context.account, peerId: peer.id, isBlocked: value).start()) - })]), nil) - } - } - }) - }, deleteContact: { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let controller = ActionSheetController(presentationData: presentationData) - let dismissAction: () -> Void = { [weak controller] in - controller?.dismissAnimated() - } - controller.setItemGroups([ - ActionSheetItemGroup(items: [ - ActionSheetButtonItem(title: presentationData.strings.UserInfo_DeleteContact, color: .destructive, action: { - dismissAction() - let _ = (getUserPeer(postbox: context.account.postbox, peerId: peerId) - |> deliverOnMainQueue).start(next: { peer, _ in - guard let peer = peer else { - return - } - let deleteContactFromDevice: Signal - if let contactDataManager = context.sharedContext.contactDataManager { - deleteContactFromDevice = contactDataManager.deleteContactWithAppSpecificReference(peerId: peer.id) - } else { - deleteContactFromDevice = .complete() - } - - var deleteSignal = deleteContactPeerInteractively(account: context.account, peerId: peer.id) - |> then(deleteContactFromDevice) - - let progressSignal = Signal { subscriber in - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil)) - presentControllerImpl?(controller, nil) - return ActionDisposable { [weak controller] in - Queue.mainQueue().async() { - controller?.dismiss() - } - } - } - |> runOn(Queue.mainQueue()) - |> delay(0.15, queue: Queue.mainQueue()) - let progressDisposable = progressSignal.start() - - deleteSignal = deleteSignal - |> afterDisposed { - Queue.mainQueue().async { - progressDisposable.dispose() - } - } - - updatePeerBlockedDisposable.set((deleteSignal - |> deliverOnMainQueue).start(completed: { - dismissImpl?() - })) - - deleteSendMessageIntents(peerId: peerId) - }) - }) - ]), - ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })]) - ]) - presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) - }, displayUsernameContextMenu: { text in - let shareController = ShareController(context: context, subject: .url("\(text)")) - presentControllerImpl?(shareController, nil) - }, displayCopyContextMenu: { tag, phone in - displayCopyContextMenuImpl?(tag, phone) - }, call: { - requestCallImpl(false) - }, openCallMenu: { number in - let _ = (getUserPeer(postbox: context.account.postbox, peerId: peerId) - |> deliverOnMainQueue).start(next: { peer, _ in - if let peer = peer as? TelegramUser, let peerPhoneNumber = peer.phone, formatPhoneNumber(number) == formatPhoneNumber(peerPhoneNumber) { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let controller = ActionSheetController(presentationData: presentationData) - let dismissAction: () -> Void = { [weak controller] in - controller?.dismissAnimated() - } - controller.setItemGroups([ - ActionSheetItemGroup(items: [ - ActionSheetButtonItem(title: presentationData.strings.UserInfo_TelegramCall, action: { - dismissAction() - requestCallImpl(false) - }), - ActionSheetButtonItem(title: presentationData.strings.UserInfo_PhoneCall, action: { - dismissAction() - context.sharedContext.applicationBindings.openUrl("tel:\(formatPhoneNumber(number).replacingOccurrences(of: " ", with: ""))") - }), - ]), - ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })]) - ]) - presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) - } else { - context.sharedContext.applicationBindings.openUrl("tel:\(formatPhoneNumber(number).replacingOccurrences(of: " ", with: ""))") - } - }) - }, requestPhoneNumber: { - let _ = (requestPhoneNumber(account: context.account, peerId: peerId) - |> deliverOnMainQueue).start(completed: { - - }) - }, aboutLinkAction: { action, itemLink in - aboutLinkActionImpl?(action, itemLink) - }, displayAboutContextMenu: { text in - displayAboutContextMenuImpl?(text) - }, openEncryptionKey: { fingerprint in - let _ = (context.account.postbox.transaction { transaction -> Peer? in - if let peer = transaction.getPeer(peerId) as? TelegramSecretChat { - if let userPeer = transaction.getPeer(peer.regularPeerId) { - return userPeer - } - } - return nil - } |> deliverOnMainQueue).start(next: { peer in - if let peer = peer { - pushControllerImpl?(SecretChatKeyController(context: context, fingerprint: fingerprint, peer: peer)) - } - }) - }, addBotToGroup: { - botAddToGroupImpl?() - }, shareBot: { - shareBotImpl?() - }, botSettings: { - let _ = (context.account.postbox.loadedPeerWithId(peerId) - |> deliverOnMainQueue).start(next: { peer in - let _ = enqueueMessages(account: context.account, peerId: peer.id, messages: [.message(text: "/settings", attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]).start() - openChatImpl?() - }) - }, botHelp: { - let _ = (context.account.postbox.loadedPeerWithId(peerId) - |> deliverOnMainQueue).start(next: { peer in - let _ = enqueueMessages(account: context.account, peerId: peer.id, messages: [.message(text: "/help", attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]).start() - openChatImpl?() - }) - }, botPrivacy: { - let _ = (context.account.postbox.loadedPeerWithId(peerId) - |> deliverOnMainQueue).start(next: { peer in - let _ = enqueueMessages(account: context.account, peerId: peer.id, messages: [.message(text: "/privacy", attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]).start() - openChatImpl?() - }) - }, report: { - presentControllerImpl?(peerReportOptionsController(context: context, subject: .peer(peerId), passthrough: false, present: { c, a in - presentControllerImpl?(c, a) - }, push: { c in - pushControllerImpl?(c) - }, completion: { _, _ in }), nil) - }) - - let deviceContacts: Signal<[(DeviceContactStableId, DeviceContactBasicData)], NoError> = peerView.get() - |> map { peerView -> String in - if let peer = peerView.0.peers[peerId] as? TelegramUser { - return peer.phone ?? "" - } - return "" - } - |> distinctUntilChanged - |> mapToSignal { number -> Signal<[(DeviceContactStableId, DeviceContactBasicData)], NoError> in - if number.isEmpty { - return .single([]) - } else { - return context.sharedContext.contactDataManager?.basicDataForNormalizedPhoneNumber(DeviceContactNormalizedPhoneNumber(rawValue: formatPhoneNumber(number))) ?? .single([]) - } - } - - let globalNotificationsKey: PostboxViewKey = .preferences(keys: Set([PreferencesKeys.globalNotifications])) - let signal = combineLatest(context.sharedContext.presentationData, statePromise.get(), peerView.get(), deviceContacts, context.account.postbox.combinedView(keys: [.peerChatState(peerId: peerId), globalNotificationsKey])) - |> map { presentationData, state, view, deviceContacts, combinedView -> (ItemListControllerState, (ItemListNodeState, Any)) in - let peer = peerViewMainPeer(view.0) - - var globalNotificationSettings: GlobalNotificationSettings = .defaultSettings - if let preferencesView = combinedView.views[globalNotificationsKey] as? PreferencesView { - if let settings = preferencesView.values[PreferencesKeys.globalNotifications] as? GlobalNotificationSettings { - globalNotificationSettings = settings - } - } - - if let peer = peer { - let _ = cachedAvatarEntries.modify { value in - if value != nil { - return value - } else { - let promise = Promise<[AvatarGalleryEntry]>() - promise.set(fetchedAvatarGalleryEntries(account: context.account, peer: peer)) - return promise - } - } - } - var leftNavigationButton: ItemListNavigationButton? - let rightNavigationButton: ItemListNavigationButton - if let editingState = state.editingState { - leftNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: { - updateState { - $0.withUpdatedEditingState(nil) - } - }) - - var doneEnabled = true - if let editingName = editingState.editingName, editingName.isEmpty { - doneEnabled = false - } - - if state.savingData { - rightNavigationButton = ItemListNavigationButton(content: .none, style: .activity, enabled: doneEnabled, action: {}) - } else { - rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Done), style: .bold, enabled: doneEnabled, action: { - var updateName: ItemListAvatarAndNameInfoItemName? - updateState { state in - if let editingState = state.editingState, let editingName = editingState.editingName { - if let user = peer { - if ItemListAvatarAndNameInfoItemName(user) != editingName { - updateName = editingName - } - } - } - if updateName != nil { - return state.withUpdatedSavingData(true) - } else { - return state.withUpdatedEditingState(nil) - } - } - - if let updateName = updateName, case let .personName(firstName, lastName, _) = updateName { - updatePeerNameDisposable.set((updateContactName(account: context.account, peerId: peerId, firstName: firstName, lastName: lastName) - |> deliverOnMainQueue).start(error: { _ in - updateState { state in - return state.withUpdatedSavingData(false) - } - }, completed: { - updateState { state in - return state.withUpdatedSavingData(false).withUpdatedEditingState(nil) - } - - let _ = (getUserPeer(postbox: context.account.postbox, peerId: peerId) - |> mapToSignal { peer, _ -> Signal in - guard let peer = peer as? TelegramUser, let phone = peer.phone, !phone.isEmpty else { - return .complete() - } - return (context.sharedContext.contactDataManager?.basicDataForNormalizedPhoneNumber(DeviceContactNormalizedPhoneNumber(rawValue: formatPhoneNumber(phone))) ?? .single([])) - |> take(1) - |> mapToSignal { records -> Signal in - var signals: [Signal] = [] - if let contactDataManager = context.sharedContext.contactDataManager { - for (id, basicData) in records { - signals.append(contactDataManager.appendContactData(DeviceContactExtendedData(basicData: DeviceContactBasicData(firstName: firstName, lastName: lastName, phoneNumbers: basicData.phoneNumbers), middleName: "", prefix: "", suffix: "", organization: "", jobTitle: "", department: "", emailAddresses: [], urls: [], addresses: [], birthdayDate: nil, socialProfiles: [], instantMessagingProfiles: [], note: ""), to: id)) - } - } - return combineLatest(signals) - |> mapToSignal { _ -> Signal in - return .complete() - } - } - }).start() - })) - } - }) - } - } else { - rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Edit), style: .regular, enabled: true, action: { - if let user = peer { - updateState { state in - return state.withUpdatedEditingState(UserInfoEditingState(editingName: ItemListAvatarAndNameInfoItemName(user))) - } - } - }) - } - - let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.UserInfo_Title), leftNavigationButton: leftNavigationButton, rightNavigationButton: rightNavigationButton, backNavigationButton: nil) - let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: userInfoEntries(account: context.account, presentationData: presentationData, view: view.0, cachedPeerData: view.1, deviceContacts: deviceContacts, mode: mode, state: state, peerChatState: (combinedView.views[.peerChatState(peerId: peerId)] as? PeerChatStateView)?.chatState, globalNotificationSettings: globalNotificationSettings), style: .plain) - - return (controllerState, (listState, arguments)) - } - |> afterDisposed { - actionsDisposable.dispose() - } - - let controller = ItemListController(context: context, state: signal) - - pushControllerImpl = { [weak controller] value in - (controller?.navigationController as? NavigationController)?.pushViewController(value) - } - dismissImpl = { [weak controller] in - guard let controller = controller else { - return - } - (controller.navigationController as? NavigationController)?.filterController(controller, animated: true) - } - presentControllerImpl = { [weak controller] value, presentationArguments in - controller?.present(value, in: .window(.root), with: presentationArguments, blockInteraction: true) - } - dismissInputImpl = { [weak controller] in - controller?.view.endEditing(true) - } - openChatImpl = { [weak controller] in - if let navigationController = (controller?.navigationController as? NavigationController) { - context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: context, chatLocation: .peer(peerId))) - } - } - shareContactImpl = { [weak controller] in - let _ = (getUserPeer(postbox: context.account.postbox, peerId: peerId) - |> deliverOnMainQueue).start(next: { peer, _ in - if let peer = peer as? TelegramUser, let phone = peer.phone { - let contact = TelegramMediaContact(firstName: peer.firstName ?? "", lastName: peer.lastName ?? "", phoneNumber: phone, peerId: peer.id, vCardData: nil) - let shareController = ShareController(context: context, subject: .media(.standalone(media: contact))) - controller?.present(shareController, in: .window(.root)) - } - }) - } - shareMyContactImpl = { [weak controller] in - let _ = (getUserPeer(postbox: context.account.postbox, peerId: context.account.peerId) - |> deliverOnMainQueue).start(next: { peer, _ in - guard let peer = peer as? TelegramUser, let phone = peer.phone else { - return - } - let contact = TelegramMediaContact(firstName: peer.firstName ?? "", lastName: peer.lastName ?? "", phoneNumber: phone, peerId: peer.id, vCardData: nil) - - let _ = (enqueueMessages(account: context.account, peerId: peerId, messages: [.message(text: "", attributes: [], mediaReference: .standalone(media: contact), replyToMessageId: nil, localGroupingKey: nil)]) - |> deliverOnMainQueue).start(next: { [weak controller] _ in - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - controller?.present(OverlayStatusController(theme: presentationData.theme, type: .success), in: .window(.root)) - }) - }) - } - startSecretChatImpl = { [weak controller] in - let _ = (context.account.postbox.transaction { transaction -> (Peer?, PeerId?) in - let peer = transaction.getPeer(peerId) - let filteredPeerIds = Array(transaction.getAssociatedPeerIds(peerId)).filter { $0.namespace == Namespaces.Peer.SecretChat } - var activeIndices: [ChatListIndex] = [] - for associatedId in filteredPeerIds { - if let state = (transaction.getPeer(associatedId) as? TelegramSecretChat)?.embeddedState { - switch state { - case .active, .handshake: - if let (_, index) = transaction.getPeerChatListIndex(associatedId) { - activeIndices.append(index) - } - default: - break - } - } - } - activeIndices.sort() - if let index = activeIndices.last { - return (peer, index.messageIndex.id.peerId) - } else { - return (peer, nil) - } - } |> deliverOnMainQueue).start(next: { peer, currentPeerId in - if let currentPeerId = currentPeerId { - if let navigationController = (controller?.navigationController as? NavigationController) { - context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: context, chatLocation: .peer(currentPeerId))) - } - } else if let controller = controller { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let displayTitle = peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) ?? "" - controller.present(textAlertController(context: context, title: nil, text: presentationData.strings.UserInfo_StartSecretChatConfirmation(displayTitle).0, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .defaultAction, title: presentationData.strings.UserInfo_StartSecretChatStart, action: { - var createSignal = createSecretChat(account: context.account, peerId: peerId) - var cancelImpl: (() -> Void)? - let progressSignal = Signal { subscriber in - let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: { - cancelImpl?() - })) - presentControllerImpl?(controller, nil) - return ActionDisposable { [weak controller] in - Queue.mainQueue().async() { - controller?.dismiss() - } - } - } - |> runOn(Queue.mainQueue()) - |> delay(0.15, queue: Queue.mainQueue()) - let progressDisposable = progressSignal.start() - - createSignal = createSignal - |> afterDisposed { - Queue.mainQueue().async { - progressDisposable.dispose() - } - } - cancelImpl = { - createSecretChatDisposable.set(nil) - } - - createSecretChatDisposable.set((createSignal |> deliverOnMainQueue).start(next: { [weak controller] peerId in - if let navigationController = (controller?.navigationController as? NavigationController) { - context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: context, chatLocation: .peer(peerId))) - } - }, error: { [weak controller] error in - if let controller = controller { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let text: String - switch error { - case .limitExceeded: - text = presentationData.strings.TwoStepAuth_FloodError - default: - text = presentationData.strings.Login_UnknownError - } - controller.present(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), in: .window(.root)) - } - })) - })]), in: .window(.root)) - } - }) - } - botAddToGroupImpl = { [weak controller] in - guard let controller = controller else { - return - } - context.sharedContext.openResolvedUrl(.groupBotStart(peerId: peerId, payload: ""), context: context, urlContext: .generic, navigationController: controller.navigationController as? NavigationController, openPeer: { id, navigation in - - }, sendFile: nil, - sendSticker: nil, - requestMessageActionUrlAuth: nil, - joinVoiceChat: nil, - present: { c, a in - presentControllerImpl?(c, a) - }, dismissInput: { - dismissInputImpl?() - }, contentContext: nil) - } - shareBotImpl = { [weak controller] in - let _ = (getUserPeer(postbox: context.account.postbox, peerId: peerId) - |> deliverOnMainQueue).start(next: { peer, _ in - if let peer = peer as? TelegramUser, let username = peer.username { - let shareController = ShareController(context: context, subject: .url("https://t.me/\(username)")) - controller?.present(shareController, in: .window(.root)) - } - }) - } - avatarGalleryTransitionArguments = { [weak controller] entry in - if let controller = controller { - var result: ((ASDisplayNode, CGRect, () -> (UIView?, UIView?)), CGRect)? - controller.forEachItemNode { itemNode in - if let itemNode = itemNode as? ItemListAvatarAndNameInfoItemNode { - result = itemNode.avatarTransitionNode() - } - } - if let (node, _) = result { - return GalleryTransitionArguments(transitionNode: node, addToTransitionSurface: { _ in - }) - } - } - return nil - } - updateHiddenAvatarImpl = { [weak controller] in - if let controller = controller { - controller.forEachItemNode { itemNode in - if let itemNode = itemNode as? ItemListAvatarAndNameInfoItemNode { - itemNode.updateAvatarHidden() - } - } - } - } - aboutLinkActionImpl = { [weak context, weak controller] action, itemLink in - if let controller = controller, let context = context { - context.sharedContext.handleTextLinkAction(context: context, peerId: peerId, navigateDisposable: navigateDisposable, controller: controller, action: action, itemLink: itemLink) - } - } - displayAboutContextMenuImpl = { [weak controller] text in - if let strongController = controller { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - var resultItemNode: ListViewItemNode? - let _ = strongController.frameForItemNode({ itemNode in - if let itemNode = itemNode as? ItemListTextWithLabelItemNode { - if let tag = itemNode.tag as? UserInfoEntryTag { - if tag == .about { - resultItemNode = itemNode - return true - } - } - } - return false - }) - if let resultItemNode = resultItemNode { - let contextMenuController = ContextMenuController(actions: [ContextMenuAction(content: .text(title: presentationData.strings.Conversation_ContextMenuCopy, accessibilityLabel: presentationData.strings.Conversation_ContextMenuCopy), action: { - UIPasteboard.general.string = text - })]) - strongController.present(contextMenuController, in: .window(.root), with: ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak resultItemNode] in - if let strongController = controller, let resultItemNode = resultItemNode { - return (resultItemNode, resultItemNode.contentBounds.insetBy(dx: 0.0, dy: -2.0), strongController.displayNode, strongController.view.bounds) - } else { - return nil - } - })) - - } - } - } - - displayCopyContextMenuImpl = { [weak controller] tag, value in - if let strongController = controller { - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - var resultItemNode: ListViewItemNode? - let _ = strongController.frameForItemNode({ itemNode in - if let itemNode = itemNode as? ItemListTextWithLabelItemNode { - if let itemTag = itemNode.tag as? UserInfoEntryTag { - if itemTag == tag && itemNode.item?.text == value { - resultItemNode = itemNode - return true - } - } - } - return false - }) - if let resultItemNode = resultItemNode { - let contextMenuController = ContextMenuController(actions: [ContextMenuAction(content: .text(title: presentationData.strings.Conversation_ContextMenuCopy, accessibilityLabel: presentationData.strings.Conversation_ContextMenuCopy), action: { - UIPasteboard.general.string = value - })]) - strongController.present(contextMenuController, in: .window(.root), with: ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak resultItemNode] in - if let strongController = controller, let resultItemNode = resultItemNode { - return (resultItemNode, resultItemNode.contentBounds.insetBy(dx: 0.0, dy: -2.0), strongController.displayNode, strongController.view.bounds) - } else { - return nil - } - })) - } - } - } - - popToRootImpl = { [weak controller] in - (controller?.navigationController as? NavigationController)?.popToRoot(animated: true) - } - - controller.didAppear = { [weak controller] firstTime in - guard let controller = controller, firstTime else { - return - } - - var resultItemNode: ItemListAvatarAndNameInfoItemNode? - let _ = controller.frameForItemNode({ itemNode in - if let itemNode = itemNode as? ItemListAvatarAndNameInfoItemNode { - resultItemNode = itemNode - return true - } - return false - }) - if let resultItemNode = resultItemNode, let callButtonFrame = resultItemNode.callButtonFrame { - let _ = (ApplicationSpecificNotice.getProfileCallTips(accountManager: context.sharedContext.accountManager) - |> deliverOnMainQueue).start(next: { [weak controller] counter in - guard let controller = controller else { - return - } - - var displayTip = false - if counter == 0 { - displayTip = true - } else if counter < 3 && arc4random_uniform(4) == 1 { - displayTip = true - } - if !displayTip { - return - } - let _ = ApplicationSpecificNotice.incrementProfileCallTips(accountManager: context.sharedContext.accountManager).start() - - let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let text: String = presentationData.strings.UserInfo_TapToCall - - let tooltipController = TooltipController(content: .text(text), baseFontSize: presentationData.listsFontSize.baseDisplaySize, dismissByTapOutside: true) - controller.present(tooltipController, in: .window(.root), with: TooltipControllerPresentationArguments(sourceNodeAndRect: { [weak resultItemNode] in - if let resultItemNode = resultItemNode { - return (resultItemNode, callButtonFrame) - } - return nil - })) - }) - } - } - - controller.navigationItem.backBarButtonItem = UIBarButtonItem(title: context.sharedContext.currentPresentationData.with{ $0 }.strings.Common_Back, style: .plain, target: nil, action: nil) - - return controller -} diff --git a/submodules/PresentationDataUtils/Sources/AlertTheme.swift b/submodules/PresentationDataUtils/Sources/AlertTheme.swift index a2d4ddb5a2..9fbfb15c0f 100644 --- a/submodules/PresentationDataUtils/Sources/AlertTheme.swift +++ b/submodules/PresentationDataUtils/Sources/AlertTheme.swift @@ -6,11 +6,15 @@ import SwiftSignalKit import TelegramPresentationData public func textAlertController(context: AccountContext, forceTheme: PresentationTheme? = nil, title: String?, text: String, actions: [TextAlertAction], actionLayout: TextAlertContentActionLayout = .horizontal, allowInputInset: Bool = true, dismissOnOutsideTap: Bool = true) -> AlertController { - var presentationData = context.sharedContext.currentPresentationData.with { $0 } + return textAlertController(sharedContext: context.sharedContext, forceTheme: forceTheme, title: title, text: text, actions: actions, actionLayout: actionLayout, allowInputInset: allowInputInset, dismissOnOutsideTap: dismissOnOutsideTap) +} + +public func textAlertController(sharedContext: SharedAccountContext, forceTheme: PresentationTheme? = nil, title: String?, text: String, actions: [TextAlertAction], actionLayout: TextAlertContentActionLayout = .horizontal, allowInputInset: Bool = true, dismissOnOutsideTap: Bool = true) -> AlertController { + var presentationData = sharedContext.currentPresentationData.with { $0 } if let forceTheme = forceTheme { presentationData = presentationData.withUpdated(theme: forceTheme) } - return textAlertController(alertContext: AlertControllerContext(theme: AlertControllerTheme(presentationData: presentationData), themeSignal: context.sharedContext.presentationData |> map { + return textAlertController(alertContext: AlertControllerContext(theme: AlertControllerTheme(presentationData: presentationData), themeSignal: sharedContext.presentationData |> map { presentationData in var presentationData = presentationData if let forceTheme = forceTheme { diff --git a/submodules/SettingsUI/Sources/Themes/EditThemeController.swift b/submodules/SettingsUI/Sources/Themes/EditThemeController.swift index 063e9c92c4..aceae5b956 100644 --- a/submodules/SettingsUI/Sources/Themes/EditThemeController.swift +++ b/submodules/SettingsUI/Sources/Themes/EditThemeController.swift @@ -443,7 +443,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll |> take(1)).start(next: { previewTheme, settings in let saveThemeTemplateFile: (String, LocalFileMediaResource, @escaping () -> Void) -> Void = { title, resource, completion in let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: resource.fileId), partialReference: nil, resource: resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "application/x-tgtheme-ios", size: nil, attributes: [.FileName(fileName: "\(title).tgios-theme")]) - let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil) + let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) let _ = enqueueMessages(account: context.account, peerId: context.account.peerId, messages: [message]).start() diff --git a/submodules/ShareController/Sources/ShareController.swift b/submodules/ShareController/Sources/ShareController.swift index 1867d75dad..caa4732617 100644 --- a/submodules/ShareController/Sources/ShareController.swift +++ b/submodules/ShareController/Sources/ShareController.swift @@ -519,9 +519,9 @@ public final class ShareController: ViewController { for peerId in peerIds { var messages: [EnqueueMessage] = [] if !text.isEmpty { - messages.append(.message(text: url + "\n\n" + text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: url + "\n\n" + text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) } else { - messages.append(.message(text: url, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: url, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) } shareSignals.append(enqueueMessages(account: strongSelf.currentAccount, peerId: peerId, messages: messages)) } @@ -529,58 +529,58 @@ public final class ShareController: ViewController { for peerId in peerIds { var messages: [EnqueueMessage] = [] if !text.isEmpty { - messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) } - messages.append(.message(text: string, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: string, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) shareSignals.append(enqueueMessages(account: strongSelf.currentAccount, peerId: peerId, messages: messages)) } case let .quote(string, url): for peerId in peerIds { var messages: [EnqueueMessage] = [] if !text.isEmpty { - messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) } let attributedText = NSMutableAttributedString(string: string, attributes: [ChatTextInputAttributes.italic: true as NSNumber]) attributedText.append(NSAttributedString(string: "\n\n\(url)")) let entities = generateChatInputTextEntities(attributedText) - messages.append(.message(text: attributedText.string, attributes: [TextEntitiesMessageAttribute(entities: entities)], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: attributedText.string, attributes: [TextEntitiesMessageAttribute(entities: entities)], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) shareSignals.append(enqueueMessages(account: strongSelf.currentAccount, peerId: peerId, messages: messages)) } case let .image(representations): for peerId in peerIds { var messages: [EnqueueMessage] = [] if !text.isEmpty { - messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) } - messages.append(.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaImage(imageId: MediaId(namespace: Namespaces.Media.LocalImage, id: arc4random64()), representations: representations.map({ $0.representation }), immediateThumbnailData: nil, reference: nil, partialReference: nil, flags: [])), replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaImage(imageId: MediaId(namespace: Namespaces.Media.LocalImage, id: arc4random64()), representations: representations.map({ $0.representation }), immediateThumbnailData: nil, reference: nil, partialReference: nil, flags: [])), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) shareSignals.append(enqueueMessages(account: strongSelf.currentAccount, peerId: peerId, messages: messages)) } case let .media(mediaReference): for peerId in peerIds { var messages: [EnqueueMessage] = [] if !text.isEmpty { - messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) } - messages.append(.message(text: "", attributes: [], mediaReference: mediaReference, replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: "", attributes: [], mediaReference: mediaReference, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) shareSignals.append(enqueueMessages(account: strongSelf.currentAccount, peerId: peerId, messages: messages)) } case let .mapMedia(media): for peerId in peerIds { var messages: [EnqueueMessage] = [] if !text.isEmpty { - messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) } - messages.append(.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) shareSignals.append(enqueueMessages(account: strongSelf.currentAccount, peerId: peerId, messages: messages)) } case let .messages(messages): for peerId in peerIds { var messagesToEnqueue: [EnqueueMessage] = [] if !text.isEmpty { - messagesToEnqueue.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)) + messagesToEnqueue.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) } for message in messages { - messagesToEnqueue.append(.forward(source: message.id, grouping: .auto, attributes: [])) + messagesToEnqueue.append(.forward(source: message.id, grouping: .auto, attributes: [], correlationId: nil)) } shareSignals.append(enqueueMessages(account: strongSelf.currentAccount, peerId: peerId, messages: messagesToEnqueue)) } diff --git a/submodules/ShareItems/Sources/ShareItems.swift b/submodules/ShareItems/Sources/ShareItems.swift index 48d7040e80..0e67edb262 100644 --- a/submodules/ShareItems/Sources/ShareItems.swift +++ b/submodules/ShareItems/Sources/ShareItems.swift @@ -403,11 +403,11 @@ public func sentShareItems(account: Account, to peerIds: [PeerId], items: [Prepa for item in items { switch item { case let .text(text): - messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)) + messages.append(.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)) case let .media(media): switch media { case let .media(reference): - let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: reference, replyToMessageId: nil, localGroupingKey: groupingKey) + let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: reference, replyToMessageId: nil, localGroupingKey: groupingKey, correlationId: nil) messages.append(message) mediaMessages.append(message) diff --git a/submodules/SyncCore/Sources/OutgoingMessageInfoAttribute.swift b/submodules/SyncCore/Sources/OutgoingMessageInfoAttribute.swift index 42856b9faf..9426cf01ab 100644 --- a/submodules/SyncCore/Sources/OutgoingMessageInfoAttribute.swift +++ b/submodules/SyncCore/Sources/OutgoingMessageInfoAttribute.swift @@ -19,30 +19,38 @@ public class OutgoingMessageInfoAttribute: MessageAttribute { public let uniqueId: Int64 public let flags: OutgoingMessageInfoFlags public let acknowledged: Bool + public let correlationId: Int64? - public init(uniqueId: Int64, flags: OutgoingMessageInfoFlags, acknowledged: Bool) { + public init(uniqueId: Int64, flags: OutgoingMessageInfoFlags, acknowledged: Bool, correlationId: Int64?) { self.uniqueId = uniqueId self.flags = flags self.acknowledged = acknowledged + self.correlationId = correlationId } required public init(decoder: PostboxDecoder) { self.uniqueId = decoder.decodeInt64ForKey("u", orElse: 0) self.flags = OutgoingMessageInfoFlags(rawValue: decoder.decodeInt32ForKey("f", orElse: 0)) self.acknowledged = decoder.decodeInt32ForKey("ack", orElse: 0) != 0 + self.correlationId = decoder.decodeOptionalInt64ForKey("cid") } public func encode(_ encoder: PostboxEncoder) { encoder.encodeInt64(self.uniqueId, forKey: "u") encoder.encodeInt32(self.flags.rawValue, forKey: "f") encoder.encodeInt32(self.acknowledged ? 1 : 0, forKey: "ack") + if let correlationId = self.correlationId { + encoder.encodeInt64(correlationId, forKey: "cid") + } else { + encoder.encodeNil(forKey: "cid") + } } public func withUpdatedFlags(_ flags: OutgoingMessageInfoFlags) -> OutgoingMessageInfoAttribute { - return OutgoingMessageInfoAttribute(uniqueId: self.uniqueId, flags: flags, acknowledged: self.acknowledged) + return OutgoingMessageInfoAttribute(uniqueId: self.uniqueId, flags: flags, acknowledged: self.acknowledged, correlationId: self.correlationId) } public func withUpdatedAcknowledged(_ acknowledged: Bool) -> OutgoingMessageInfoAttribute { - return OutgoingMessageInfoAttribute(uniqueId: self.uniqueId, flags: self.flags, acknowledged: acknowledged) + return OutgoingMessageInfoAttribute(uniqueId: self.uniqueId, flags: self.flags, acknowledged: acknowledged, correlationId: self.correlationId) } } diff --git a/submodules/TelegramCallsUI/Sources/CallRatingController.swift b/submodules/TelegramCallsUI/Sources/CallRatingController.swift index ebf86e48f1..af2e52c23f 100644 --- a/submodules/TelegramCallsUI/Sources/CallRatingController.swift +++ b/submodules/TelegramCallsUI/Sources/CallRatingController.swift @@ -249,7 +249,7 @@ func rateCallAndSendLogs(account: Account, callId: CallId, starsCount: Int, comm let name = "\(callId.id)_\(callId.accessHash).log.json" let path = callLogsPath(account: account) + "/" + name let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: id), partialReference: nil, resource: LocalFileReferenceMediaResource(localFilePath: path, randomId: id), previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "application/text", size: nil, attributes: [.FileName(fileName: name)]) - let message = EnqueueMessage.message(text: comment, attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil) + let message = EnqueueMessage.message(text: comment, attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) return rate |> then(enqueueMessages(account: account, peerId: peerId, messages: [message]) |> mapToSignal({ _ -> Signal in @@ -257,7 +257,7 @@ func rateCallAndSendLogs(account: Account, callId: CallId, starsCount: Int, comm })) } else if !comment.isEmpty { return rate - |> then(enqueueMessages(account: account, peerId: peerId, messages: [.message(text: comment, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]) + |> then(enqueueMessages(account: account, peerId: peerId, messages: [.message(text: comment, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]) |> mapToSignal({ _ -> Signal in return .single(Void()) })) diff --git a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift index 86b28773a5..7040f3e4be 100644 --- a/submodules/TelegramCallsUI/Sources/VoiceChatController.swift +++ b/submodules/TelegramCallsUI/Sources/VoiceChatController.swift @@ -982,7 +982,7 @@ public final class VoiceChatController: ViewController { dismissController?() if let strongSelf = self { - let _ = (enqueueMessages(account: strongSelf.context.account, peerId: peer.id, messages: [.message(text: listenerLink, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]) + let _ = (enqueueMessages(account: strongSelf.context.account, peerId: peer.id, messages: [.message(text: listenerLink, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]) |> deliverOnMainQueue).start(next: { [weak self] _ in if let strongSelf = self { strongSelf.presentUndoOverlay(content: .forward(savedMessages: false, text: strongSelf.presentationData.strings.UserInfo_LinkForwardTooltip_Chat_One(peer.displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder)).0), action: { _ in return true }) diff --git a/submodules/TelegramCore/Sources/Account.swift b/submodules/TelegramCore/Sources/Account.swift index eb509bba7f..9c39c9e485 100644 --- a/submodules/TelegramCore/Sources/Account.swift +++ b/submodules/TelegramCore/Sources/Account.swift @@ -67,6 +67,11 @@ public class UnauthorizedAccount { public var updateLoginTokenEvents: Signal { return self.updateLoginTokenPipe.signal() } + + private let serviceNotificationPipe = ValuePipe() + public var serviceNotificationEvents: Signal { + return self.serviceNotificationPipe.signal() + } public var masterDatacenterId: Int32 { return Int32(self.network.mtProto.datacenterId) @@ -83,8 +88,11 @@ public class UnauthorizedAccount { self.postbox = postbox self.network = network let updateLoginTokenPipe = self.updateLoginTokenPipe + let serviceNotificationPipe = self.serviceNotificationPipe self.stateManager = UnauthorizedAccountStateManager(network: network, updateLoginToken: { updateLoginTokenPipe.putNext(Void()) + }, displayServiceNotification: { text in + serviceNotificationPipe.putNext(text) }) network.shouldKeepConnection.set(self.shouldBeServiceTaskMaster.get() diff --git a/submodules/TelegramCore/Sources/EnqueueMessage.swift b/submodules/TelegramCore/Sources/EnqueueMessage.swift index 6c5fddddc3..4ee74e0518 100644 --- a/submodules/TelegramCore/Sources/EnqueueMessage.swift +++ b/submodules/TelegramCore/Sources/EnqueueMessage.swift @@ -11,13 +11,13 @@ public enum EnqueueMessageGrouping { } public enum EnqueueMessage { - case message(text: String, attributes: [MessageAttribute], mediaReference: AnyMediaReference?, replyToMessageId: MessageId?, localGroupingKey: Int64?) - case forward(source: MessageId, grouping: EnqueueMessageGrouping, attributes: [MessageAttribute]) + case message(text: String, attributes: [MessageAttribute], mediaReference: AnyMediaReference?, replyToMessageId: MessageId?, localGroupingKey: Int64?, correlationId: Int64?) + case forward(source: MessageId, grouping: EnqueueMessageGrouping, attributes: [MessageAttribute], correlationId: Int64?) public func withUpdatedReplyToMessageId(_ replyToMessageId: MessageId?) -> EnqueueMessage { switch self { - case let .message(text, attributes, mediaReference, _, localGroupingKey): - return .message(text: text, attributes: attributes, mediaReference: mediaReference, replyToMessageId: replyToMessageId, localGroupingKey: localGroupingKey) + case let .message(text, attributes, mediaReference, _, localGroupingKey, correlationId): + return .message(text: text, attributes: attributes, mediaReference: mediaReference, replyToMessageId: replyToMessageId, localGroupingKey: localGroupingKey, correlationId: correlationId) case .forward: return self } @@ -25,21 +25,41 @@ public enum EnqueueMessage { public func withUpdatedAttributes(_ f: ([MessageAttribute]) -> [MessageAttribute]) -> EnqueueMessage { switch self { - case let .message(text, attributes, mediaReference, replyToMessageId, localGroupingKey): - return .message(text: text, attributes: f(attributes), mediaReference: mediaReference, replyToMessageId: replyToMessageId, localGroupingKey: localGroupingKey) - case let .forward(source, grouping, attributes): - return .forward(source: source, grouping: grouping, attributes: f(attributes)) + case let .message(text, attributes, mediaReference, replyToMessageId, localGroupingKey, correlationId): + return .message(text: text, attributes: f(attributes), mediaReference: mediaReference, replyToMessageId: replyToMessageId, localGroupingKey: localGroupingKey, correlationId: correlationId) + case let .forward(source, grouping, attributes, correlationId): + return .forward(source: source, grouping: grouping, attributes: f(attributes), correlationId: correlationId) } } public func withUpdatedGroupingKey(_ f: (Int64?) -> Int64?) -> EnqueueMessage { switch self { - case let .message(text, attributes, mediaReference, replyToMessageId, localGroupingKey): - return .message(text: text, attributes: attributes, mediaReference: mediaReference, replyToMessageId: replyToMessageId, localGroupingKey: f(localGroupingKey)) + case let .message(text, attributes, mediaReference, replyToMessageId, localGroupingKey, correlationId): + return .message(text: text, attributes: attributes, mediaReference: mediaReference, replyToMessageId: replyToMessageId, localGroupingKey: f(localGroupingKey), correlationId: correlationId) case .forward: return self } } + + public func withUpdatedCorrelationId(_ value: Int64?) -> EnqueueMessage { + switch self { + case let .message(text, attributes, mediaReference, replyToMessageId, localGroupingKey, _): + return .message(text: text, attributes: attributes, mediaReference: mediaReference, replyToMessageId: replyToMessageId, localGroupingKey: localGroupingKey, correlationId: value) + case let .forward(source, grouping, attributes, _): + return .forward(source: source, grouping: grouping, attributes: attributes, correlationId: value) + } + } +} + +private extension EnqueueMessage { + var correlationId: Int64? { + switch self { + case let .message(_, _, _, _, _, correlationId): + return correlationId + case let .forward(_, _, _, correlationId): + return correlationId + } + } } func augmentMediaWithReference(_ mediaReference: AnyMediaReference) -> Media { @@ -139,7 +159,7 @@ private func opportunisticallyTransformOutgoingMedia(network: Network, postbox: var hasMedia = false loop: for message in messages { switch message { - case let .message(_, _, mediaReference, _, _): + case let .message(_, _, mediaReference, _, _, _): if mediaReference != nil { hasMedia = true break loop @@ -156,14 +176,14 @@ private func opportunisticallyTransformOutgoingMedia(network: Network, postbox: var signals: [Signal<(Bool, EnqueueMessage), NoError>] = [] for message in messages { switch message { - case let .message(text, attributes, mediaReference, replyToMessageId, localGroupingKey): + case let .message(text, attributes, mediaReference, replyToMessageId, localGroupingKey, correlationId): if let mediaReference = mediaReference { signals.append(opportunisticallyTransformMessageWithMedia(network: network, postbox: postbox, transformOutgoingMessageMedia: transformOutgoingMessageMedia, mediaReference: mediaReference, userInteractive: userInteractive) |> map { result -> (Bool, EnqueueMessage) in if let result = result { - return (true, .message(text: text, attributes: attributes, mediaReference: .standalone(media: result.media), replyToMessageId: replyToMessageId, localGroupingKey: localGroupingKey)) + return (true, .message(text: text, attributes: attributes, mediaReference: .standalone(media: result.media), replyToMessageId: replyToMessageId, localGroupingKey: localGroupingKey, correlationId: correlationId)) } else { - return (false, .message(text: text, attributes: attributes, mediaReference: mediaReference, replyToMessageId: replyToMessageId, localGroupingKey: localGroupingKey)) + return (false, .message(text: text, attributes: attributes, mediaReference: mediaReference, replyToMessageId: replyToMessageId, localGroupingKey: localGroupingKey, correlationId: correlationId)) } }) } else { @@ -235,7 +255,7 @@ public func resendMessages(account: Account, messageIds: [MessageId]) -> Signal< } } - messages.append(.message(text: message.text, attributes: filteredAttributes, mediaReference: message.media.first.flatMap(AnyMediaReference.standalone), replyToMessageId: replyToMessageId, localGroupingKey: message.groupingKey)) + messages.append(.message(text: message.text, attributes: filteredAttributes, mediaReference: message.media.first.flatMap(AnyMediaReference.standalone), replyToMessageId: replyToMessageId, localGroupingKey: message.groupingKey, correlationId: nil)) } } let _ = enqueueMessages(transaction: transaction, account: account, peerId: peerId, messages: messages.map { (false, $0) }) @@ -258,7 +278,7 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId, } } switch message { - case let .message(_, _, _, replyToMessageId, _): + case let .message(_, _, _, replyToMessageId, _, _): if let replyToMessageId = replyToMessageId, replyToMessageId.peerId != peerId, let replyMessage = transaction.getMessage(replyToMessageId) { var canBeForwarded = true if replyMessage.id.namespace != Namespaces.Message.Cloud { @@ -271,10 +291,10 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId, } } if canBeForwarded { - updatedMessages.append((true, .forward(source: replyToMessageId, grouping: .none, attributes: []))) + updatedMessages.append((true, .forward(source: replyToMessageId, grouping: .none, attributes: [], correlationId: nil))) } } - case let .forward(sourceId, _, _): + case let .forward(sourceId, _, _, _): if let sourceMessage = forwardedMessageToBeReuploaded(transaction: transaction, id: sourceId) { var mediaReference: AnyMediaReference? if sourceMessage.id.peerId.namespace == Namespaces.Peer.SecretChat { @@ -282,7 +302,7 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId, mediaReference = .standalone(media: media) } } - updatedMessages.append((transformedMedia, .message(text: sourceMessage.text, attributes: sourceMessage.attributes, mediaReference: mediaReference, replyToMessageId: nil, localGroupingKey: nil))) + updatedMessages.append((transformedMedia, .message(text: sourceMessage.text, attributes: sourceMessage.attributes, mediaReference: mediaReference, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil))) continue outer } } @@ -319,11 +339,11 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId, if transformedMedia { infoFlags.insert(.transformedMedia) } - attributes.append(OutgoingMessageInfoAttribute(uniqueId: randomId, flags: infoFlags, acknowledged: false)) + attributes.append(OutgoingMessageInfoAttribute(uniqueId: randomId, flags: infoFlags, acknowledged: false, correlationId: message.correlationId)) globallyUniqueIds.append(randomId) switch message { - case let .message(text, requestedAttributes, mediaReference, replyToMessageId, localGroupingKey): + case let .message(text, requestedAttributes, mediaReference, replyToMessageId, localGroupingKey, correlationId): var peerAutoremoveTimeout: Int32? if let peer = peer as? TelegramSecretChat { var isAction = false @@ -495,7 +515,7 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId, } storeMessages.append(StoreMessage(peerId: peerId, namespace: messageNamespace, globallyUniqueId: randomId, groupingKey: localGroupingKey, threadId: threadId, timestamp: effectiveTimestamp, flags: flags, tags: tags, globalTags: globalTags, localTags: localTags, forwardInfo: nil, authorId: authorId, text: text, attributes: attributes, media: mediaList)) - case let .forward(source, grouping, requestedAttributes): + case let .forward(source, grouping, requestedAttributes, correlationId): let sourceMessage = transaction.getMessage(source) if let sourceMessage = sourceMessage, let author = sourceMessage.author ?? sourceMessage.peers[sourceMessage.id.peerId] { if let peer = peer as? TelegramSecretChat { diff --git a/submodules/TelegramCore/Sources/OutgoingMessageWithChatContextResult.swift b/submodules/TelegramCore/Sources/OutgoingMessageWithChatContextResult.swift index c25e8dfb48..9b186b1fd0 100644 --- a/submodules/TelegramCore/Sources/OutgoingMessageWithChatContextResult.swift +++ b/submodules/TelegramCore/Sources/OutgoingMessageWithChatContextResult.swift @@ -4,7 +4,7 @@ import SwiftSignalKit import SyncCore -public func outgoingMessageWithChatContextResult(to peerId: PeerId, results: ChatContextResultCollection, result: ChatContextResult, hideVia: Bool = false, scheduleTime: Int32? = nil) -> EnqueueMessage? { +public func outgoingMessageWithChatContextResult(to peerId: PeerId, results: ChatContextResultCollection, result: ChatContextResult, hideVia: Bool = false, scheduleTime: Int32? = nil, correlationId: Int64? = nil) -> EnqueueMessage? { var attributes: [MessageAttribute] = [] attributes.append(OutgoingChatContextResultMessageAttribute(queryId: result.queryId, id: result.id, hideVia: hideVia)) if !hideVia { @@ -32,19 +32,19 @@ public func outgoingMessageWithChatContextResult(to peerId: PeerId, results: Cha return true } if let media: Media = internalReference.file ?? internalReference.image { - return .message(text: caption, attributes: filteredAttributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: caption, attributes: filteredAttributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) } else { - return .message(text: caption, attributes: filteredAttributes, mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil) + return .message(text: caption, attributes: filteredAttributes, mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) } } else { - return .message(text: "", attributes: attributes, mediaReference: .standalone(media: TelegramMediaGame(gameId: 0, accessHash: 0, name: "", title: internalReference.title ?? "", description: internalReference.description ?? "", image: internalReference.image, file: internalReference.file)), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: "", attributes: attributes, mediaReference: .standalone(media: TelegramMediaGame(gameId: 0, accessHash: 0, name: "", title: internalReference.title ?? "", description: internalReference.description ?? "", image: internalReference.image, file: internalReference.file)), replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) } } else if let file = internalReference.file, internalReference.type == "gif" { - return .message(text: caption, attributes: attributes, mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: caption, attributes: attributes, mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) } else if let image = internalReference.image { - return .message(text: caption, attributes: attributes, mediaReference: .standalone(media: image), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: caption, attributes: attributes, mediaReference: .standalone(media: image), replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) } else if let file = internalReference.file { - return .message(text: caption, attributes: attributes, mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: caption, attributes: attributes, mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) } else { return nil } @@ -56,9 +56,9 @@ public func outgoingMessageWithChatContextResult(to peerId: PeerId, results: Cha let thumbnailResource = thumbnail.resource let imageDimensions = thumbnail.dimensions ?? PixelDimensions(width: 128, height: 128) let tmpImage = TelegramMediaImage(imageId: MediaId(namespace: Namespaces.Media.LocalImage, id: randomId), representations: [TelegramMediaImageRepresentation(dimensions: imageDimensions, resource: thumbnailResource, progressiveSizes: [], immediateThumbnailData: nil)], immediateThumbnailData: nil, reference: nil, partialReference: nil, flags: []) - return .message(text: caption, attributes: attributes, mediaReference: .standalone(media: tmpImage), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: caption, attributes: attributes, mediaReference: .standalone(media: tmpImage), replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) } else { - return .message(text: caption, attributes: attributes, mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil) + return .message(text: caption, attributes: attributes, mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) } } else if externalReference.type == "document" || externalReference.type == "gif" || externalReference.type == "audio" || externalReference.type == "voice" { var videoThumbnails: [TelegramMediaFile.VideoThumbnail] = [] @@ -118,9 +118,9 @@ public func outgoingMessageWithChatContextResult(to peerId: PeerId, results: Cha } let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: randomId), partialReference: nil, resource: resource, previewRepresentations: previewRepresentations, videoThumbnails: videoThumbnails, immediateThumbnailData: nil, mimeType: externalReference.content?.mimeType ?? "application/binary", size: nil, attributes: fileAttributes) - return .message(text: caption, attributes: attributes, mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: caption, attributes: attributes, mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) } else { - return .message(text: caption, attributes: attributes, mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil) + return .message(text: caption, attributes: attributes, mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) } } case let .text(text, entities, disableUrlPreview, replyMarkup): @@ -130,21 +130,21 @@ public func outgoingMessageWithChatContextResult(to peerId: PeerId, results: Cha if let replyMarkup = replyMarkup { attributes.append(replyMarkup) } - return .message(text: text, attributes: attributes, mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil) + return .message(text: text, attributes: attributes, mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) case let .mapLocation(media, replyMarkup): if let replyMarkup = replyMarkup { attributes.append(replyMarkup) } - return .message(text: "", attributes: attributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: "", attributes: attributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) case let .contact(media, replyMarkup): if let replyMarkup = replyMarkup { attributes.append(replyMarkup) } - return .message(text: "", attributes: attributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: "", attributes: attributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) case let .invoice(media, replyMarkup): if let replyMarkup = replyMarkup { attributes.append(replyMarkup) } - return .message(text: "", attributes: attributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil) + return .message(text: "", attributes: attributes, mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil, correlationId: correlationId) } } diff --git a/submodules/TelegramCore/Sources/PendingMessageUploadedContent.swift b/submodules/TelegramCore/Sources/PendingMessageUploadedContent.swift index 0de3aa8a3a..7ce8a7df08 100644 --- a/submodules/TelegramCore/Sources/PendingMessageUploadedContent.swift +++ b/submodules/TelegramCore/Sources/PendingMessageUploadedContent.swift @@ -374,7 +374,7 @@ private func uploadedMediaImageContent(network: Network, postbox: Postbox, trans let attribute = updatedAttributes[index] as! OutgoingMessageInfoAttribute updatedAttributes[index] = attribute.withUpdatedFlags(attribute.flags.union([.transformedMedia])) } else { - updatedAttributes.append(OutgoingMessageInfoAttribute(uniqueId: arc4random64(), flags: [.transformedMedia], acknowledged: false)) + updatedAttributes.append(OutgoingMessageInfoAttribute(uniqueId: arc4random64(), flags: [.transformedMedia], acknowledged: false, correlationId: nil)) } return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, threadId: currentMessage.threadId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media)) }) @@ -664,7 +664,7 @@ private func uploadedMediaFileContent(network: Network, postbox: Postbox, auxili let attribute = updatedAttributes[index] as! OutgoingMessageInfoAttribute updatedAttributes[index] = attribute.withUpdatedFlags(attribute.flags.union([.transformedMedia])) } else { - updatedAttributes.append(OutgoingMessageInfoAttribute(uniqueId: arc4random64(), flags: [.transformedMedia], acknowledged: false)) + updatedAttributes.append(OutgoingMessageInfoAttribute(uniqueId: arc4random64(), flags: [.transformedMedia], acknowledged: false, correlationId: nil)) } return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, threadId: currentMessage.threadId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: updatedAttributes, media: currentMessage.media)) }) diff --git a/submodules/TelegramCore/Sources/RequestStartBot.swift b/submodules/TelegramCore/Sources/RequestStartBot.swift index 44e6b1118b..41c2834228 100644 --- a/submodules/TelegramCore/Sources/RequestStartBot.swift +++ b/submodules/TelegramCore/Sources/RequestStartBot.swift @@ -26,7 +26,7 @@ public func requestStartBot(account: Account, botPeerId: PeerId, payload: String } } } else { - return enqueueMessages(account: account, peerId: botPeerId, messages: [.message(text: "/start", attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]) |> mapToSignal { _ -> Signal in + return enqueueMessages(account: account, peerId: botPeerId, messages: [.message(text: "/start", attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]) |> mapToSignal { _ -> Signal in return .complete() } } diff --git a/submodules/TelegramCore/Sources/SetSecretChatMessageAutoremoveTimeoutInteractively.swift b/submodules/TelegramCore/Sources/SetSecretChatMessageAutoremoveTimeoutInteractively.swift index eb1473f89c..13906bc270 100644 --- a/submodules/TelegramCore/Sources/SetSecretChatMessageAutoremoveTimeoutInteractively.swift +++ b/submodules/TelegramCore/Sources/SetSecretChatMessageAutoremoveTimeoutInteractively.swift @@ -17,7 +17,7 @@ public func setSecretChatMessageAutoremoveTimeoutInteractively(account: Account, transaction.setPeerChatState(peerId, state: updatedState) } - let _ = enqueueMessages(transaction: transaction, account: account, peerId: peerId, messages: [(true, .message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaAction(action: TelegramMediaActionType.messageAutoremoveTimeoutUpdated(timeout == nil ? 0 : timeout!))), replyToMessageId: nil, localGroupingKey: nil))]) + let _ = enqueueMessages(transaction: transaction, account: account, peerId: peerId, messages: [(true, .message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaAction(action: TelegramMediaActionType.messageAutoremoveTimeoutUpdated(timeout == nil ? 0 : timeout!))), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil))]) } } } @@ -32,7 +32,7 @@ public func addSecretChatMessageScreenshot(account: Account, peerId: PeerId) -> default: break } - let _ = enqueueMessages(transaction: transaction, account: account, peerId: peerId, messages: [(true, .message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaAction(action: TelegramMediaActionType.historyScreenshot)), replyToMessageId: nil, localGroupingKey: nil))]) + let _ = enqueueMessages(transaction: transaction, account: account, peerId: peerId, messages: [(true, .message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaAction(action: TelegramMediaActionType.historyScreenshot)), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil))]) } } } diff --git a/submodules/TelegramCore/Sources/UnauthorizedAccountStateManager.swift b/submodules/TelegramCore/Sources/UnauthorizedAccountStateManager.swift index b9993cf1f9..57895597f9 100644 --- a/submodules/TelegramCore/Sources/UnauthorizedAccountStateManager.swift +++ b/submodules/TelegramCore/Sources/UnauthorizedAccountStateManager.swift @@ -54,10 +54,12 @@ final class UnauthorizedAccountStateManager { private var updateService: UnauthorizedUpdateMessageService? private let updateServiceDisposable = MetaDisposable() private let updateLoginToken: () -> Void + private let displayServiceNotification: (String) -> Void - init(network: Network, updateLoginToken: @escaping () -> Void) { + init(network: Network, updateLoginToken: @escaping () -> Void, displayServiceNotification: @escaping (String) -> Void) { self.network = network self.updateLoginToken = updateLoginToken + self.displayServiceNotification = displayServiceNotification } deinit { @@ -69,11 +71,17 @@ final class UnauthorizedAccountStateManager { if self.updateService == nil { self.updateService = UnauthorizedUpdateMessageService() let updateLoginToken = self.updateLoginToken + let displayServiceNotification = self.displayServiceNotification self.updateServiceDisposable.set(self.updateService!.pipe.signal().start(next: { updates in for update in updates { switch update { case .updateLoginToken: updateLoginToken() + case let .updateServiceNotification(flags, _, _, message, _, _): + let popup = (flags & (1 << 0)) != 0 + if popup { + displayServiceNotification(message) + } default: break } diff --git a/submodules/TelegramUI/Sources/AccessoryPanelNode.swift b/submodules/TelegramUI/Sources/AccessoryPanelNode.swift index 067fe48fc8..28f7651ef3 100644 --- a/submodules/TelegramUI/Sources/AccessoryPanelNode.swift +++ b/submodules/TelegramUI/Sources/AccessoryPanelNode.swift @@ -4,6 +4,7 @@ import AsyncDisplayKit import TelegramPresentationData class AccessoryPanelNode: ASDisplayNode { + var originalFrameBeforeDismissed: CGRect? var dismiss: (() -> Void)? var interfaceInteraction: ChatPanelInterfaceInteraction? diff --git a/submodules/TelegramUI/Sources/AppDelegate.swift b/submodules/TelegramUI/Sources/AppDelegate.swift index b1cbaba978..f3b3b34686 100644 --- a/submodules/TelegramUI/Sources/AppDelegate.swift +++ b/submodules/TelegramUI/Sources/AppDelegate.swift @@ -1974,7 +1974,7 @@ final class SharedApplicationContext { if let messageId = messageIdFromNotification(peerId: peerId, notification: response.notification) { let _ = applyMaxReadIndexInteractively(postbox: account.postbox, stateManager: account.stateManager, index: MessageIndex(id: messageId, timestamp: 0)).start() } - return enqueueMessages(account: account, peerId: peerId, messages: [EnqueueMessage.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]) + return enqueueMessages(account: account, peerId: peerId, messages: [EnqueueMessage.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]) |> map { messageIds -> MessageId? in if messageIds.isEmpty { return nil diff --git a/submodules/TelegramUI/Sources/ApplicationContext.swift b/submodules/TelegramUI/Sources/ApplicationContext.swift index 4e4c9df927..708bbc0495 100644 --- a/submodules/TelegramUI/Sources/ApplicationContext.swift +++ b/submodules/TelegramUI/Sources/ApplicationContext.swift @@ -36,6 +36,8 @@ final class UnauthorizedApplicationContext { let isReady = Promise() var authorizationCompleted: Bool = false + + private var serviceNotificationEventsDisposable: Disposable? init(apiId: Int32, apiHash: String, sharedContext: SharedAccountContextImpl, account: UnauthorizedAccount, otherAccountPhoneNumbers: ((String, AccountRecordId, Bool)?, [(String, AccountRecordId, Bool)])) { self.sharedContext = sharedContext @@ -71,6 +73,20 @@ final class UnauthorizedApplicationContext { }, { result in ApplicationSpecificNotice.setPermissionWarning(accountManager: sharedContext.accountManager, permission: .cellularData, value: 0) }) + + self.serviceNotificationEventsDisposable = (account.serviceNotificationEvents + |> deliverOnMainQueue).start(next: { [weak self] text in + if let strongSelf = self { + let presentationData = strongSelf.sharedContext.currentPresentationData.with { $0 } + let alertController = textAlertController(sharedContext: strongSelf.sharedContext, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]) + + (strongSelf.rootController.viewControllers.last as? ViewController)?.present(alertController, in: .window(.root)) + } + }) + } + + deinit { + self.serviceNotificationEventsDisposable?.dispose() } } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 6a0a8535cc..f5b9533f3e 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -1004,7 +1004,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if !entities.isEmpty { attributes.append(TextEntitiesMessageAttribute(entities: entities)) } - strongSelf.sendMessages([.message(text: text, attributes: attributes, mediaReference: nil, replyToMessageId: strongSelf.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil)]) + strongSelf.sendMessages([.message(text: text, attributes: attributes, mediaReference: nil, replyToMessageId: strongSelf.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil, correlationId: nil)]) }, sendSticker: { [weak self] fileReference, query, clearInput, sourceNode, sourceRect in guard let strongSelf = self else { return false @@ -1043,7 +1043,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G attributes.append(EmojiSearchQueryMessageAttribute(query: query)) } - strongSelf.sendMessages([.message(text: "", attributes: attributes, mediaReference: fileReference.abstract, replyToMessageId: strongSelf.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil)]) + strongSelf.sendMessages([.message(text: "", attributes: attributes, mediaReference: fileReference.abstract, replyToMessageId: strongSelf.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil, correlationId: nil)]) return true }, sendGif: { [weak self] fileReference, sourceNode, sourceRect in if let strongSelf = self { @@ -1064,7 +1064,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G }) } }) - strongSelf.sendMessages([.message(text: "", attributes: [], mediaReference: fileReference.abstract, replyToMessageId: strongSelf.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil)]) + strongSelf.sendMessages([.message(text: "", attributes: [], mediaReference: fileReference.abstract, replyToMessageId: strongSelf.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil, correlationId: nil)]) } return true }, sendBotContextResultAsGif: { [weak self] collection, result, sourceNode, sourceRect in @@ -1363,7 +1363,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G |> deliverOnMainQueue).start(next: { coordinate in if let strongSelf = self { if let coordinate = coordinate { - strongSelf.sendMessages([.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaMap(latitude: coordinate.latitude, longitude: coordinate.longitude, heading: nil, accuracyRadius: nil, geoPlace: nil, venue: nil, liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil)), replyToMessageId: nil, localGroupingKey: nil)]) + strongSelf.sendMessages([.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaMap(latitude: coordinate.latitude, longitude: coordinate.longitude, heading: nil, accuracyRadius: nil, geoPlace: nil, venue: nil, liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil)), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]) } else { strongSelf.present(textAlertController(context: strongSelf.context, title: nil, text: strongSelf.presentationData.strings.Login_UnknownError, actions: [TextAlertAction(type: .genericAction, title: strongSelf.presentationData.strings.Common_Cancel, action: {})]), in: .window(.root)) } @@ -1387,7 +1387,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G let _ = (strongSelf.context.account.postbox.loadedPeerWithId(strongSelf.context.account.peerId) |> deliverOnMainQueue).start(next: { peer in if let peer = peer as? TelegramUser, let phone = peer.phone, !phone.isEmpty { - strongSelf.sendMessages([.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaContact(firstName: peer.firstName ?? "", lastName: peer.lastName ?? "", phoneNumber: phone, peerId: peer.id, vCardData: nil)), replyToMessageId: nil, localGroupingKey: nil)]) + strongSelf.sendMessages([.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaContact(firstName: peer.firstName ?? "", lastName: peer.lastName ?? "", phoneNumber: phone, peerId: peer.id, vCardData: nil)), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]) } }) } @@ -1427,7 +1427,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if !entities.isEmpty { attributes.append(TextEntitiesMessageAttribute(entities: entities)) } - strongSelf.sendMessages([.message(text: command, attributes: attributes, mediaReference: nil, replyToMessageId: (postAsReply && messageId != nil) ? messageId! : nil, localGroupingKey: nil)]) + strongSelf.sendMessages([.message(text: command, attributes: attributes, mediaReference: nil, replyToMessageId: (postAsReply && messageId != nil) ? messageId! : nil, localGroupingKey: nil, correlationId: nil)]) } }, openInstantPage: { [weak self] message, associatedData in if let strongSelf = self, strongSelf.isNodeLoaded, let navigationController = strongSelf.effectiveNavigationController, let message = strongSelf.chatDisplayNode.historyNode.messageInCurrentHistoryView(message.id) { @@ -1712,7 +1712,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.ShareMenu_Send, color: .accent, action: { [weak actionSheet] in actionSheet?.dismissAnimated() if let strongSelf = self { - strongSelf.sendMessages([.message(text: command, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]) + strongSelf.sendMessages([.message(text: command, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]) } })) } @@ -4074,6 +4074,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G strongSelf.currentPinchController?.addRelativeContentOffset(CGPoint(x: 0.0, y: -offset), transition: transition) } } + + strongSelf.chatDisplayNode.messageTransitionNode.addExternalOffset(offset: offset, transition: transition, itemNode: itemNode) } if case .pinnedMessages = self.presentationInterfaceState.subject { @@ -4480,7 +4482,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } else { isScheduledMessages = false } - strongSelf.chatDisplayNode.containerLayoutUpdated(validLayout, navigationBarHeight: strongSelf.navigationHeight, transition: .animated(duration: 0.2, curve: .easeInOut), listViewTransaction: { updateSizeAndInsets, _, _, _ in + strongSelf.chatDisplayNode.containerLayoutUpdated(validLayout, navigationBarHeight: strongSelf.navigationHeight, transition: .animated(duration: 0.4, curve: .spring), listViewTransaction: { updateSizeAndInsets, _, _, _ in var options = transition.options let _ = options.insert(.Synchronous) let _ = options.insert(.LowLatency) @@ -4506,9 +4508,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var scrollToItem: ListViewScrollToItem? if isScheduledMessages, let insertedIndex = insertedIndex { - scrollToItem = ListViewScrollToItem(index: insertedIndex, position: .visible, animated: true, curve: .Default(duration: 0.2), directionHint: .Down) + scrollToItem = ListViewScrollToItem(index: insertedIndex, position: .visible, animated: true, curve: .Spring(duration: 0.4), directionHint: .Down) } else if transition.historyView.originalView.laterId == nil { - scrollToItem = ListViewScrollToItem(index: 0, position: .top(0.0), animated: true, curve: .Default(duration: 0.2), directionHint: .Up) + scrollToItem = ListViewScrollToItem(index: 0, position: .top(0.0), animated: true, curve: .Spring(duration: 0.4), directionHint: .Up) } var stationaryItemRange: (Int, Int)? @@ -4566,12 +4568,12 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var forwardedMessages: [[EnqueueMessage]] = [] var forwardSourcePeerIds = Set() for message in transformedMessages { - if case let .forward(source, _, _) = message { + if case let .forward(source, _, _, _) = message { forwardSourcePeerIds.insert(source.peerId) var added = false if var last = forwardedMessages.last { - if let currentMessage = last.first, case let .forward(currentSource, _, _) = currentMessage, currentSource.peerId == source.peerId { + if let currentMessage = last.first, case let .forward(currentSource, _, _, _) = currentMessage, currentSource.peerId == source.peerId { last.append(message) added = true } @@ -5371,7 +5373,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if !entities.isEmpty { attributes.append(TextEntitiesMessageAttribute(entities: entities)) } - strongSelf.sendMessages([.message(text: messageText, attributes: attributes, mediaReference: nil, replyToMessageId: replyMessageId, localGroupingKey: nil)]) + strongSelf.sendMessages([.message(text: messageText, attributes: attributes, mediaReference: nil, replyToMessageId: replyMessageId, localGroupingKey: nil, correlationId: nil)]) } } }, sendBotStart: { [weak self] payload in @@ -8308,7 +8310,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } private func editMessageMediaWithMessages(_ messages: [EnqueueMessage]) { - if let message = messages.first, case let .message(text, _, maybeMediaReference, _, _) = message, let mediaReference = maybeMediaReference { + if let message = messages.first, case let .message(text, _, maybeMediaReference, _, _, _) = message, let mediaReference = maybeMediaReference { self.updateChatPresentationInterfaceState(animated: true, interactive: true, { state in var state = state if let editMessageState = state.editMessageState, case let .media(options) = editMessageState.content, !options.isEmpty { @@ -8661,7 +8663,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: fileId), partialReference: nil, resource: ICloudFileResource(urlData: item.urlData, thumbnail: false), previewRepresentations: previewRepresentations, videoThumbnails: [], immediateThumbnailData: nil, mimeType: mimeType, size: item.fileSize, attributes: attributes) - let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: replyMessageId, localGroupingKey: groupingKey) + let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: replyMessageId, localGroupingKey: groupingKey, correlationId: nil) messages.append(message) } if let _ = groupingKey, messages.count % 10 == 0 { @@ -8899,7 +8901,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return } let replyMessageId = strongSelf.presentationInterfaceState.interfaceState.replyMessageId - let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: location), replyToMessageId: replyMessageId, localGroupingKey: nil) + let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: location), replyToMessageId: replyMessageId, localGroupingKey: nil, correlationId: nil) strongSelf.chatDisplayNode.setupSendActionOnViewUpdate({ if let strongSelf = self { strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: false, { @@ -8954,7 +8956,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G }) } }) - let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: replyMessageId, localGroupingKey: nil) + let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: replyMessageId, localGroupingKey: nil, correlationId: nil) enqueueMessages.append(message) } } @@ -9013,7 +9015,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G }) } }) - let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: replyMessageId, localGroupingKey: nil) + let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: replyMessageId, localGroupingKey: nil, correlationId: nil) strongSelf.sendMessages([message]) } else { let contactController = strongSelf.context.sharedContext.makeDeviceContactInfoController(context: strongSelf.context, subject: .filter(peer: peerAndContactData.0, contactId: nil, contactData: contactData, completion: { peer, contactData in @@ -9031,7 +9033,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G }) } }) - let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: replyMessageId, localGroupingKey: nil) + let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: replyMessageId, localGroupingKey: nil, correlationId: nil) strongSelf.sendMessages([message]) } }), completed: nil, cancelled: nil) @@ -9406,7 +9408,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if let value = value { self.present(UndoOverlayController(presentationData: self.presentationData, content: .dice(dice: dice, account: self.context.account, text: value, action: canSendMessagesToChat(self.presentationInterfaceState) ? self.presentationData.strings.Conversation_SendDice : nil), elevatedLayout: false, action: { [weak self] action in if let strongSelf = self, canSendMessagesToChat(strongSelf.presentationInterfaceState), action == .undo { - strongSelf.sendMessages([.message(text: "", attributes: [], mediaReference: AnyMediaReference.standalone(media: TelegramMediaDice(emoji: dice.emoji)), replyToMessageId: nil, localGroupingKey: nil)]) + strongSelf.sendMessages([.message(text: "", attributes: [], mediaReference: AnyMediaReference.standalone(media: TelegramMediaDice(emoji: dice.emoji)), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]) } return false }), in: .current) @@ -9427,9 +9429,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if let defaultReplyMessageId = defaultReplyMessageId { switch message { - case let .message(text, attributes, mediaReference, replyToMessageId, localGroupingKey): + case let .message(text, attributes, mediaReference, replyToMessageId, localGroupingKey, correlationId): if replyToMessageId == nil { - message = .message(text: text, attributes: attributes, mediaReference: mediaReference, replyToMessageId: defaultReplyMessageId, localGroupingKey: localGroupingKey) + message = .message(text: text, attributes: attributes, mediaReference: mediaReference, replyToMessageId: defaultReplyMessageId, localGroupingKey: localGroupingKey, correlationId: correlationId) } case .forward: break @@ -9598,7 +9600,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G fileAttributes.append(.ImageSize(size: PixelDimensions(size))) let media = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: arc4random64()), partialReference: nil, resource: resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "image/webp", size: data.count, attributes: fileAttributes) - let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil) + let message = EnqueueMessage.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) let replyMessageId = strongSelf.presentationInterfaceState.interfaceState.replyMessageId strongSelf.chatDisplayNode.setupSendActionOnViewUpdate({ @@ -9814,7 +9816,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } }) - strongSelf.sendMessages([.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: randomId), partialReference: nil, resource: resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "audio/ogg", size: data.compressedData.count, attributes: [.Audio(isVoice: true, duration: Int(data.duration), title: nil, performer: nil, waveform: waveformBuffer)])), replyToMessageId: strongSelf.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil)]) + strongSelf.sendMessages([.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: randomId), partialReference: nil, resource: resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "audio/ogg", size: data.compressedData.count, attributes: [.Audio(isVoice: true, duration: Int(data.duration), title: nil, performer: nil, waveform: waveformBuffer)])), replyToMessageId: strongSelf.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil, correlationId: nil)]) strongSelf.recorderFeedback?.tap() strongSelf.recorderFeedback = nil @@ -9910,7 +9912,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } }) - let messages: [EnqueueMessage] = [.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: arc4random64()), partialReference: nil, resource: recordedMediaPreview.resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "audio/ogg", size: Int(recordedMediaPreview.fileSize), attributes: [.Audio(isVoice: true, duration: Int(recordedMediaPreview.duration), title: nil, performer: nil, waveform: waveformBuffer)])), replyToMessageId: self.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil)] + let messages: [EnqueueMessage] = [.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: arc4random64()), partialReference: nil, resource: recordedMediaPreview.resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "audio/ogg", size: Int(recordedMediaPreview.fileSize), attributes: [.Audio(isVoice: true, duration: Int(recordedMediaPreview.duration), title: nil, performer: nil, waveform: waveformBuffer)])), replyToMessageId: self.presentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil, correlationId: nil)] let transformedMessages: [EnqueueMessage] if let silentPosting = silentPosting { @@ -10628,7 +10630,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G }), in: .current) let _ = (enqueueMessages(account: strongSelf.context.account, peerId: peerId, messages: messages.map { message -> EnqueueMessage in - return .forward(source: message.id, grouping: .auto, attributes: []) + return .forward(source: message.id, grouping: .auto, attributes: [], correlationId: nil) }) |> deliverOnMainQueue).start(next: { messageIds in if let strongSelf = self { @@ -10986,7 +10988,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G Queue.mainQueue().async { unblockingPeer.set(false) if let strongSelf = self, restartBot { - let _ = enqueueMessages(account: strongSelf.context.account, peerId: peerId, messages: [.message(text: "/start", attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]).start() + let _ = enqueueMessages(account: strongSelf.context.account, peerId: peerId, messages: [.message(text: "/start", attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]).start() } } })).start()) diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index 3c4e4dbec0..d82bf18b66 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -393,6 +393,8 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { private var expandedInputDimNode: ASDisplayNode? private var dropDimNode: ASDisplayNode? + + let messageTransitionNode: ChatMessageTransitionNode private var containerLayoutAndNavigationBarHeight: (ContainerViewLayout, CGFloat)? @@ -501,6 +503,8 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { self.navigationBarSeparatorNode = ASDisplayNode() self.navigationBarSeparatorNode.backgroundColor = chatPresentationInterfaceState.theme.rootController.navigationBar.separatorColor + + self.messageTransitionNode = ChatMessageTransitionNode(listNode: self.historyNode) super.init() @@ -593,6 +597,9 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { self.addSubnode(self.navigationBarBackroundNode) self.addSubnode(self.navigationBarSeparatorNode) + + self.addSubnode(self.messageTransitionNode) + if !self.context.sharedContext.immediateExperimentalUISettings.playerEmbedding { self.navigationBarBackroundNode.isHidden = true self.navigationBarSeparatorNode.isHidden = true @@ -1150,7 +1157,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { var dismissedInputPanelNode: ASDisplayNode? var dismissedSecondaryInputPanelNode: ASDisplayNode? - var dismissedAccessoryPanelNode: ASDisplayNode? + var dismissedAccessoryPanelNode: AccessoryPanelNode? var dismissedInputContextPanelNode: ChatInputContextPanelNode? var dismissedOverlayContextPanelNode: ChatInputContextPanelNode? @@ -1743,6 +1750,9 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { if let inputPanelFrame = inputPanelFrame { transitionTargetY = inputPanelFrame.minY } + + dismissedAccessoryPanelNode.originalFrameBeforeDismissed = dismissedAccessoryPanelNode.frame + transition.updateFrame(node: dismissedAccessoryPanelNode, frame: CGRect(origin: CGPoint(x: 0.0, y: transitionTargetY), size: dismissedAccessoryPanelNode.frame.size), completion: { _ in frameCompleted = true completed() @@ -2607,7 +2617,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { let trimmedInputText = effectiveInputText.string.trimmingCharacters(in: .whitespacesAndNewlines) let peerId = effectivePresentationInterfaceState.chatLocation.peerId if peerId.namespace != Namespaces.Peer.SecretChat, let interactiveEmojis = self.interactiveEmojis, interactiveEmojis.emojis.contains(trimmedInputText) { - messages.append(.message(text: "", attributes: [], mediaReference: AnyMediaReference.standalone(media: TelegramMediaDice(emoji: trimmedInputText)), replyToMessageId: self.chatPresentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil)) + messages.append(.message(text: "", attributes: [], mediaReference: AnyMediaReference.standalone(media: TelegramMediaDice(emoji: trimmedInputText)), replyToMessageId: self.chatPresentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil, correlationId: nil)) } else { let inputText = convertMarkdownToAttributes(effectiveInputText) @@ -2624,7 +2634,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { } else { webpage = self.chatPresentationInterfaceState.urlPreview?.1 } - messages.append(.message(text: text.string, attributes: attributes, mediaReference: webpage.flatMap(AnyMediaReference.standalone), replyToMessageId: self.chatPresentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil)) + messages.append(.message(text: text.string, attributes: attributes, mediaReference: webpage.flatMap(AnyMediaReference.standalone), replyToMessageId: self.chatPresentationInterfaceState.interfaceState.replyMessageId, localGroupingKey: nil, correlationId: nil)) } } @@ -2654,7 +2664,22 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { if let forwardMessageIds = self.chatPresentationInterfaceState.interfaceState.forwardMessageIds { for id in forwardMessageIds { - messages.append(.forward(source: id, grouping: .auto, attributes: [])) + messages.append(.forward(source: id, grouping: .auto, attributes: [], correlationId: nil)) + } + } + + if !messages.isEmpty, case .message = messages[messages.count - 1] { + let correlationId = Int64.random(in: 0 ..< Int64.max) + messages[messages.count - 1] = messages[messages.count - 1].withUpdatedCorrelationId(correlationId) + + var replyPanel: ReplyAccessoryPanelNode? + if let accessoryPanelNode = self.accessoryPanelNode as? ReplyAccessoryPanelNode { + replyPanel = accessoryPanelNode + } + if let inputPanelNode = self.inputPanelNode as? ChatTextInputPanelNode, let textInput = inputPanelNode.makeSnapshotForTransition() { + let source: ChatMessageTransitionNode.Source = .textInput(textInput: textInput, replyPanel: replyPanel) + self.messageTransitionNode.add(correlationId: correlationId, source: source, initiated: { + }) } } diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index 65f74069c1..7cbaa46064 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -1780,7 +1780,6 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { if let historyView = strongSelf.historyView { if historyView.filteredEntries.isEmpty { if let firstEntry = historyView.originalView.entries.first { - var isPeerJoined = false var emptyType = ChatHistoryNodeLoadState.EmptyType.generic for media in firstEntry.message.media { if let action = media as? TelegramMediaAction { @@ -1893,6 +1892,28 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { } else if transition.scrolledToSomeIndex { self?.scrolledToSomeIndex?() } + + if let currentSendAnimationCorrelationId = strongSelf.currentSendAnimationCorrelationId { + var foundItemNode: ChatMessageItemView? + strongSelf.forEachItemNode { itemNode in + if let itemNode = itemNode as? ChatMessageItemView, let item = itemNode.item { + for (message, _) in item.content { + for attribute in message.attributes { + if let attribute = attribute as? OutgoingMessageInfoAttribute { + if attribute.correlationId == currentSendAnimationCorrelationId { + foundItemNode = itemNode + } + } + } + } + } + } + + if let foundItemNode = foundItemNode { + strongSelf.currentSendAnimationCorrelationId = nil + strongSelf.animationCorrelationMessageFound?(foundItemNode, currentSendAnimationCorrelationId) + } + } strongSelf.hasActiveTransition = false strongSelf.dequeueHistoryViewTransitions() @@ -2245,4 +2266,11 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { }) self.selectionScrollDisplayLink?.isPaused = false } + + private var currentSendAnimationCorrelationId: Int64? + func setCurrentSendAnimationCorrelationId(_ value: Int64?) { + self.currentSendAnimationCorrelationId = value + } + + var animationCorrelationMessageFound: ((ChatMessageItemView, Int64?) -> Void)? } diff --git a/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift b/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift index 8716e00cf2..c1eb63d8bd 100644 --- a/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift +++ b/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift @@ -475,7 +475,7 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState let id = arc4random64() let file = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: id), partialReference: nil, resource: LocalFileReferenceMediaResource(localFilePath: logPath, randomId: id), previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "application/text", size: nil, attributes: [.FileName(fileName: "CallStats.log")]) - let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil) + let message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: file), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) let _ = enqueueMessages(account: context.account, peerId: peerId, messages: [message]).start() } diff --git a/submodules/TelegramUI/Sources/ChatMessageBackground.swift b/submodules/TelegramUI/Sources/ChatMessageBackground.swift index 36bcc4941c..c939c10989 100644 --- a/submodules/TelegramUI/Sources/ChatMessageBackground.swift +++ b/submodules/TelegramUI/Sources/ChatMessageBackground.swift @@ -233,6 +233,23 @@ class ChatMessageBackground: ASDisplayNode { self.imageNode.image = image self.outlineImageNode.image = outlineImage } + + func animateFrom(sourceView: UIView, transition: ContainedViewLayoutTransition) { + if transition.isAnimated { + self.imageNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1) + self.outlineImageNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1) + + self.view.addSubview(sourceView) + sourceView.frame = CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: sourceView.bounds.size) + sourceView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false, completion: { [weak sourceView] _ in + sourceView?.removeFromSuperview() + }) + + transition.animateFrame(node: self.imageNode, from: sourceView.frame) + transition.animateFrame(node: self.outlineImageNode, from: sourceView.frame) + transition.updateFrame(view: sourceView, frame: CGRect(origin: self.imageNode.frame.origin, size: CGSize(width: self.imageNode.frame.width - 7.0, height: self.imageNode.frame.height))) + } + } } final class ChatMessageShadowNode: ASDisplayNode { diff --git a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift index 664d8726f6..4ffab33804 100644 --- a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift @@ -362,7 +362,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode } } - private let mainContextSourceNode: ContextExtractedContentContainingNode + let mainContextSourceNode: ContextExtractedContentContainingNode private let mainContainerNode: ContextControllerSourceNode private let backgroundWallpaperNode: ChatMessageBubbleBackdrop private let backgroundNode: ChatMessageBackground @@ -553,6 +553,40 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } + + override func cancelInsertionAnimations() { + self.shadowNode.layer.removeAllAnimations() + + func process(node: ASDisplayNode) { + if node === self.accessoryItemNode { + return + } + + if node !== self { + switch node { + case let node as ContextExtractedContentContainingNode: + process(node: node.contentNode) + return + case _ as ContextControllerSourceNode, _ as ContextExtractedContentNode: + break + default: + node.layer.removeAllAnimations() + node.layer.allowsGroupOpacity = false + return + } + } + + guard let subnodes = node.subnodes else { + return + } + + for subnode in subnodes { + process(node: subnode) + } + } + + process(node: self) + } override func animateInsertion(_ currentTimestamp: Double, duration: Double, short: Bool) { super.animateInsertion(currentTimestamp, duration: duration, short: short) @@ -614,6 +648,27 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode } } } + + func animateContentFromTextInputField(textInput: ChatMessageTransitionNode.Source.TextInput, transition: ContainedViewLayoutTransition) { + let widthDifference = self.backgroundNode.frame.width - textInput.backgroundView.frame.width + + self.backgroundNode.animateFrom(sourceView: textInput.backgroundView, transition: transition) + + for contentNode in self.contentNodes { + if let contentNode = contentNode as? ChatMessageTextBubbleContentNode { + let localSourceContentFrame = self.mainContextSourceNode.contentNode.view.convert(textInput.contentView.frame.offsetBy(dx: self.mainContextSourceNode.contentRect.minX, dy: self.mainContextSourceNode.contentRect.minY), to: contentNode.view) + textInput.contentView.frame = localSourceContentFrame + contentNode.animateFrom(sourceView: textInput.contentView, widthDifference: widthDifference, transition: transition) + } + } + } + + func animateReplyPanel(sourceReplyPanel: ChatMessageTransitionNode.ReplyPanel, transition: ContainedViewLayoutTransition) { + if let replyInfoNode = self.replyInfoNode { + let localRect = self.mainContextSourceNode.contentNode.view.convert(sourceReplyPanel.relativeSourceRect, to: replyInfoNode.view) + replyInfoNode.animateFromInputPanel(sourceReplyPanel: sourceReplyPanel, localRect: localRect, transition: transition) + } + } override func didLoad() { super.didLoad() diff --git a/submodules/TelegramUI/Sources/ChatMessageItemView.swift b/submodules/TelegramUI/Sources/ChatMessageItemView.swift index 02594b2cd2..a35dd9040a 100644 --- a/submodules/TelegramUI/Sources/ChatMessageItemView.swift +++ b/submodules/TelegramUI/Sources/ChatMessageItemView.swift @@ -729,6 +729,9 @@ public class ChatMessageItemView: ListViewItemNode { avatarNode.frame = CGRect(origin: CGPoint(x: leftInset + 3.0, y: self.apparentFrame.height - 38.0 - self.insets.top - 2.0 - UIScreenPixel), size: CGSize(width: 38.0, height: 38.0)) } } + + func cancelInsertionAnimations() { + } override public func animateInsertion(_ currentTimestamp: Double, duration: Double, short: Bool) { if short { diff --git a/submodules/TelegramUI/Sources/ChatMessageReplyInfoNode.swift b/submodules/TelegramUI/Sources/ChatMessageReplyInfoNode.swift index 91fd6ee3a6..deaeef52ce 100644 --- a/submodules/TelegramUI/Sources/ChatMessageReplyInfoNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageReplyInfoNode.swift @@ -229,4 +229,84 @@ class ChatMessageReplyInfoNode: ASDisplayNode { }) } } + + func animateFromInputPanel(sourceReplyPanel: ChatMessageTransitionNode.ReplyPanel, localRect: CGRect, transition: ContainedViewLayoutTransition) { + if let titleNode = self.titleNode { + let offset = CGPoint( + x: localRect.minX + sourceReplyPanel.titleNode.frame.minX - titleNode.frame.minX, + y: localRect.minY + sourceReplyPanel.titleNode.frame.midY - titleNode.frame.midY + ) + + transition.animatePositionAdditive(node: titleNode, offset: offset) + + self.addSubnode(sourceReplyPanel.titleNode) + + titleNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1) + sourceReplyPanel.titleNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false, completion: { [weak sourceReplyPanel] _ in + sourceReplyPanel?.titleNode.removeFromSupernode() + }) + + sourceReplyPanel.titleNode.frame = sourceReplyPanel.titleNode.frame.offsetBy(dx: localRect.minX - offset.x, dy: localRect.minY - offset.y) + transition.animatePositionAdditive(node: sourceReplyPanel.titleNode, offset: CGPoint(x: offset.x, y: offset.y), removeOnCompletion: false) + } + + if let textNode = self.textNode { + let offset = CGPoint( + x: localRect.minX + sourceReplyPanel.textNode.frame.minX - textNode.frame.minX, + y: localRect.minY + sourceReplyPanel.textNode.frame.midY - textNode.frame.midY + ) + + transition.animatePositionAdditive(node: textNode, offset: offset) + + self.addSubnode(sourceReplyPanel.textNode) + + textNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1) + sourceReplyPanel.textNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false, completion: { [weak sourceReplyPanel] _ in + sourceReplyPanel?.textNode.removeFromSupernode() + }) + + sourceReplyPanel.textNode.frame = sourceReplyPanel.textNode.frame.offsetBy(dx: localRect.minX - offset.x, dy: localRect.minY - offset.y) + transition.animatePositionAdditive(node: sourceReplyPanel.textNode, offset: CGPoint(x: offset.x, y: offset.y), removeOnCompletion: false) + } + + if let imageNode = self.imageNode { + let offset = CGPoint( + x: localRect.minX + sourceReplyPanel.imageNode.frame.midX - imageNode.frame.midX, + y: localRect.minY + sourceReplyPanel.imageNode.frame.midY - imageNode.frame.midY + ) + + transition.animatePositionAdditive(node: imageNode, offset: offset) + + self.addSubnode(sourceReplyPanel.imageNode) + + imageNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1) + sourceReplyPanel.imageNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false, completion: { [weak sourceReplyPanel] _ in + sourceReplyPanel?.imageNode.removeFromSupernode() + }) + + sourceReplyPanel.imageNode.frame = sourceReplyPanel.imageNode.frame.offsetBy(dx: localRect.minX - offset.x, dy: localRect.minY - offset.y) + transition.animatePositionAdditive(node: sourceReplyPanel.imageNode, offset: CGPoint(x: offset.x, y: offset.y), removeOnCompletion: false) + } + + do { + let lineNode = self.lineNode + + let offset = CGPoint( + x: localRect.minX + sourceReplyPanel.lineNode.frame.minX - lineNode.frame.minX, + y: localRect.minY + sourceReplyPanel.lineNode.frame.minY - lineNode.frame.minY + ) + + transition.animatePositionAdditive(node: lineNode, offset: offset) + + self.addSubnode(sourceReplyPanel.lineNode) + + lineNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1) + sourceReplyPanel.lineNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false, completion: { [weak sourceReplyPanel] _ in + sourceReplyPanel?.lineNode.removeFromSupernode() + }) + + sourceReplyPanel.lineNode.frame = sourceReplyPanel.lineNode.frame.offsetBy(dx: localRect.minX - offset.x, dy: localRect.minY - offset.y) + transition.animatePositionAdditive(node: sourceReplyPanel.lineNode, offset: CGPoint(x: offset.x, y: offset.y), removeOnCompletion: false) + } + } } diff --git a/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift b/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift index c018521b50..9188c4a238 100644 --- a/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageTextBubbleContentNode.swift @@ -640,4 +640,24 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode { override func getStatusNode() -> ASDisplayNode? { return self.statusNode } + + func animateFrom(sourceView: UIView, widthDifference: CGFloat, transition: ContainedViewLayoutTransition) { + self.view.addSubview(sourceView) + + sourceView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false, completion: { [weak sourceView] _ in + sourceView?.removeFromSuperview() + }) + self.textNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1) + + let offset = CGPoint( + x: sourceView.frame.minX - (self.textNode.frame.minX - 0.0), + y: sourceView.frame.minY - (self.textNode.frame.minY - 3.0) + ) + + transition.animatePositionAdditive(node: self.textNode, offset: offset) + transition.updatePosition(layer: sourceView.layer, position: CGPoint(x: sourceView.layer.position.x - offset.x, y: sourceView.layer.position.y - offset.y)) + + self.statusNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.25) + transition.animatePositionAdditive(node: self.statusNode, offset: CGPoint(x: -widthDifference, y: 0.0)) + } } diff --git a/submodules/TelegramUI/Sources/ChatMessageTransitionNode.swift b/submodules/TelegramUI/Sources/ChatMessageTransitionNode.swift new file mode 100644 index 0000000000..3a672f27c0 --- /dev/null +++ b/submodules/TelegramUI/Sources/ChatMessageTransitionNode.swift @@ -0,0 +1,191 @@ +import Foundation +import UIKit +import AsyncDisplayKit +import Display +import ContextUI + +final class ChatMessageTransitionNode: ASDisplayNode { + final class ReplyPanel { + let titleNode: ASDisplayNode + let textNode: ASDisplayNode + let lineNode: ASDisplayNode + let imageNode: ASDisplayNode + let relativeSourceRect: CGRect + + init(titleNode: ASDisplayNode, textNode: ASDisplayNode, lineNode: ASDisplayNode, imageNode: ASDisplayNode, relativeSourceRect: CGRect) { + self.titleNode = titleNode + self.textNode = textNode + self.lineNode = lineNode + self.imageNode = imageNode + self.relativeSourceRect = relativeSourceRect + } + } + + enum Source { + final class TextInput { + let backgroundView: UIView + let contentView: UIView + let sourceRect: CGRect + + init(backgroundView: UIView, contentView: UIView, sourceRect: CGRect) { + self.backgroundView = backgroundView + self.contentView = contentView + self.sourceRect = sourceRect + } + } + + case textInput(textInput: TextInput, replyPanel: ReplyAccessoryPanelNode?) + } + + private final class AnimatingItemNode: ASDisplayNode { + private let itemNode: ChatMessageItemView + private let contextSourceNode: ContextExtractedContentContainingNode + private let source: ChatMessageTransitionNode.Source + + private let scrollingContainer: ASDisplayNode + private let containerNode: ASDisplayNode + + var animationEnded: (() -> Void)? + + init(itemNode: ChatMessageItemView, contextSourceNode: ContextExtractedContentContainingNode, source: ChatMessageTransitionNode.Source) { + self.itemNode = itemNode + self.scrollingContainer = ASDisplayNode() + self.containerNode = ASDisplayNode() + self.contextSourceNode = contextSourceNode + self.source = source + + super.init() + + self.addSubnode(self.scrollingContainer) + self.scrollingContainer.addSubnode(self.containerNode) + } + + deinit { + self.contextSourceNode.addSubnode(self.contextSourceNode.contentNode) + } + + func beginAnimation() { + switch self.source { + case let .textInput(textInput, replyPanel): + self.containerNode.addSubnode(self.contextSourceNode.contentNode) + + let targetAbsoluteRect = self.contextSourceNode.view.convert(self.contextSourceNode.contentRect, to: nil) + let sourceAbsoluteRect = textInput.backgroundView.frame.offsetBy(dx: textInput.sourceRect.minX, dy: textInput.sourceRect.minY) + + var sourceReplyPanel: ReplyPanel? + if let replyPanel = replyPanel, let replyPanelParentView = replyPanel.view.superview { + var replySourceAbsoluteFrame = replyPanelParentView.convert(replyPanel.originalFrameBeforeDismissed ?? replyPanel.frame, to: nil) + replySourceAbsoluteFrame.origin.x -= sourceAbsoluteRect.minX - self.contextSourceNode.contentRect.minX + replySourceAbsoluteFrame.origin.y -= sourceAbsoluteRect.minY - self.contextSourceNode.contentRect.minY + + sourceReplyPanel = ReplyPanel(titleNode: replyPanel.titleNode, textNode: replyPanel.textNode, lineNode: replyPanel.lineNode, imageNode: replyPanel.imageNode, relativeSourceRect: replySourceAbsoluteFrame) + } + + self.itemNode.cancelInsertionAnimations() + + let duration: Double = 0.4 + let delay: Double = 0.0 + + let transition: ContainedViewLayoutTransition = .animated(duration: duration * 0.8, curve: .spring) + + if let itemNode = self.itemNode as? ChatMessageBubbleItemNode { + itemNode.animateContentFromTextInputField(textInput: textInput, transition: transition) + if let sourceReplyPanel = sourceReplyPanel { + itemNode.animateReplyPanel(sourceReplyPanel: sourceReplyPanel, transition: transition) + } + } + + self.containerNode.frame = targetAbsoluteRect.offsetBy(dx: -self.contextSourceNode.contentRect.minX, dy: self.contextSourceNode.contentRect.minY) + self.containerNode.layer.animatePosition(from: CGPoint(x: 0.0, y: sourceAbsoluteRect.minY - targetAbsoluteRect.minY), to: CGPoint(), duration: duration, delay: delay, timingFunction: kCAMediaTimingFunctionSpring, additive: true, force: true, completion: { [weak self] _ in + guard let strongSelf = self else { + return + } + strongSelf.endAnimation() + }) + self.containerNode.layer.animatePosition(from: CGPoint(x: sourceAbsoluteRect.minX - targetAbsoluteRect.minX, y: 0.0), to: CGPoint(), duration: duration * 0.8, delay: delay, timingFunction: kCAMediaTimingFunctionSpring, additive: true) + } + } + + private func endAnimation() { + self.animationEnded?() + } + + func addExternalOffset(offset: CGFloat, transition: ContainedViewLayoutTransition, itemNode: ListViewItemNode?) { + var applyOffset = false + if let itemNode = itemNode { + if itemNode === self.itemNode { + applyOffset = true + } + } else { + applyOffset = true + } + if applyOffset { + self.scrollingContainer.bounds = self.scrollingContainer.bounds.offsetBy(dx: 0.0, dy: -offset) + transition.animateOffsetAdditive(node: self.scrollingContainer, offset: offset) + } + } + } + + private let listNode: ChatHistoryListNode + + private var currentPendingItem: (Int64, Source, () -> Void)? + + private var animatingItemNodes: [AnimatingItemNode] = [] + + init(listNode: ChatHistoryListNode) { + self.listNode = listNode + + super.init() + + self.listNode.animationCorrelationMessageFound = { [weak self] itemNode, correlationId in + guard let strongSelf = self, let (currentId, currentSource, initiated) = strongSelf.currentPendingItem else { + return + } + if currentId == correlationId { + strongSelf.currentPendingItem = nil + strongSelf.beginAnimation(itemNode: itemNode, source: currentSource) + initiated() + } + } + } + + func add(correlationId: Int64, source: Source, initiated: @escaping () -> Void) { + self.currentPendingItem = (correlationId, source, initiated) + self.listNode.setCurrentSendAnimationCorrelationId(correlationId) + } + + private func beginAnimation(itemNode: ChatMessageItemView, source: Source) { + if let itemNode = itemNode as? ChatMessageBubbleItemNode { + let animatingItemNode = AnimatingItemNode(itemNode: itemNode, contextSourceNode: itemNode.mainContextSourceNode, source: source) + self.animatingItemNodes.append(animatingItemNode) + self.addSubnode(animatingItemNode) + + animatingItemNode.animationEnded = { [weak self, weak animatingItemNode] in + guard let strongSelf = self, let animatingItemNode = animatingItemNode else { + return + } + animatingItemNode.removeFromSupernode() + if let index = strongSelf.animatingItemNodes.firstIndex(where: { $0 === animatingItemNode }) { + strongSelf.animatingItemNodes.remove(at: index) + } + } + + animatingItemNode.frame = self.bounds + animatingItemNode.beginAnimation() + } else if let itemNode = itemNode as? ChatMessageStickerItemNode { + + } else if let itemNode = itemNode as? ChatMessageAnimatedStickerItemNode { + + } + } + + override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { + return nil + } + + func addExternalOffset(offset: CGFloat, transition: ContainedViewLayoutTransition, itemNode: ListViewItemNode?) { + for animatingItemNode in self.animatingItemNodes { + animatingItemNode.addExternalOffset(offset: offset, transition: transition, itemNode: itemNode) + } + } +} diff --git a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift index 00dfc33dcb..6fa624b188 100644 --- a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift +++ b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift @@ -162,20 +162,30 @@ private func calclulateTextFieldMinHeight(_ presentationInterfaceState: ChatPres } private var currentTextInputBackgroundImage: (UIColor, UIColor, CGFloat, UIImage)? -private func textInputBackgroundImage(backgroundColor: UIColor, strokeColor: UIColor, diameter: CGFloat) -> UIImage? { - if let current = currentTextInputBackgroundImage { +private func textInputBackgroundImage(backgroundColor: UIColor?, inputBackgroundColor: UIColor?, strokeColor: UIColor, diameter: CGFloat) -> UIImage? { + if let backgroundColor = backgroundColor, let current = currentTextInputBackgroundImage { if current.0.isEqual(backgroundColor) && current.1.isEqual(strokeColor) && current.2.isEqual(to: diameter) { return current.3 } } let image = generateImage(CGSize(width: diameter, height: diameter), rotatedContext: { size, context in - context.setFillColor(backgroundColor.cgColor) - context.fill(CGRect(x: 0.0, y: 0.0, width: diameter, height: diameter)) - - context.setBlendMode(.clear) - context.setFillColor(UIColor.clear.cgColor) + if let backgroundColor = backgroundColor { + context.setFillColor(backgroundColor.cgColor) + context.fill(CGRect(x: 0.0, y: 0.0, width: diameter, height: diameter)) + } else { + context.clear(CGRect(x: 0.0, y: 0.0, width: diameter, height: diameter)) + } + + if let inputBackgroundColor = inputBackgroundColor { + context.setBlendMode(.normal) + context.setFillColor(inputBackgroundColor.cgColor) + } else { + context.setBlendMode(.clear) + context.setFillColor(UIColor.clear.cgColor) + } context.fillEllipse(in: CGRect(x: 0.0, y: 0.0, width: diameter, height: diameter)) + context.setBlendMode(.normal) context.setStrokeColor(strokeColor.cgColor) let strokeWidth: CGFloat = 1.0 @@ -183,7 +193,9 @@ private func textInputBackgroundImage(backgroundColor: UIColor, strokeColor: UIC context.strokeEllipse(in: CGRect(x: strokeWidth / 2.0, y: strokeWidth / 2.0, width: diameter - strokeWidth, height: diameter - strokeWidth)) })?.stretchableImage(withLeftCapWidth: Int(diameter) / 2, topCapHeight: Int(diameter) / 2) if let image = image { - currentTextInputBackgroundImage = (backgroundColor, strokeColor, diameter, image) + if let backgroundColor = backgroundColor { + currentTextInputBackgroundImage = (backgroundColor, strokeColor, diameter, image) + } return image } else { return nil @@ -205,6 +217,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { var textInputNode: EditableTextNode? let textInputBackgroundNode: ASImageNode + private var transparentTextInputBackgroundImage: UIImage? let actionButtons: ChatTextInputActionButtonsNode var mediaRecordingAccessibilityArea: AccessibilityAreaNode? private let counterTextNode: ImmediateTextNode @@ -636,7 +649,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { let maxNumberOfLines = min(12, (Int(fieldMaxHeight - 11.0) - 33) / 22) - let updatedMaxHeight = (CGFloat(maxNumberOfLines) * 22.0 + 10.0) + let updatedMaxHeight = (CGFloat(maxNumberOfLines) * (22.0 + 2.0) + 10.0) textFieldHeight = max(textFieldMinHeight, min(updatedMaxHeight, unboundTextFieldHeight)) } else { @@ -779,7 +792,8 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { backgroundColor = interfaceState.theme.chat.inputPanel.panelBackgroundColor } - self.textInputBackgroundNode.image = textInputBackgroundImage(backgroundColor: backgroundColor, strokeColor: interfaceState.theme.chat.inputPanel.inputStrokeColor, diameter: minimalInputHeight) + self.textInputBackgroundNode.image = textInputBackgroundImage(backgroundColor: backgroundColor, inputBackgroundColor: nil, strokeColor: interfaceState.theme.chat.inputPanel.inputStrokeColor, diameter: minimalInputHeight) + self.transparentTextInputBackgroundImage = textInputBackgroundImage(backgroundColor: nil, inputBackgroundColor: interfaceState.theme.chat.inputPanel.inputBackgroundColor, strokeColor: interfaceState.theme.chat.inputPanel.inputStrokeColor, diameter: minimalInputHeight) self.searchLayoutClearImageNode.image = PresentationResourcesChat.chatInputTextFieldClearImage(interfaceState.theme) @@ -2152,5 +2166,28 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { } return nil } + + func makeSnapshotForTransition() -> ChatMessageTransitionNode.Source.TextInput? { + guard let backgroundImage = self.transparentTextInputBackgroundImage else { + return nil + } + guard let textInputNode = self.textInputNode else { + return nil + } + + let backgroundView = UIImageView(image: backgroundImage) + backgroundView.frame = self.textInputBackgroundNode.frame + + guard let contentView = textInputNode.view.snapshotView(afterScreenUpdates: false) else { + return nil + } + contentView.frame = textInputNode.frame + + return ChatMessageTransitionNode.Source.TextInput( + backgroundView: backgroundView, + contentView: contentView, + sourceRect: self.view.convert(self.bounds, to: nil) + ) + } } diff --git a/submodules/TelegramUI/Sources/LegacyInstantVideoController.swift b/submodules/TelegramUI/Sources/LegacyInstantVideoController.swift index c9cad730e7..b0b768758e 100644 --- a/submodules/TelegramUI/Sources/LegacyInstantVideoController.swift +++ b/submodules/TelegramUI/Sources/LegacyInstantVideoController.swift @@ -198,7 +198,7 @@ func legacyInstantVideoController(theme: PresentationTheme, panelFrame: CGRect, } let media = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: arc4random64()), partialReference: nil, resource: resource, previewRepresentations: previewRepresentations, videoThumbnails: [], immediateThumbnailData: nil, mimeType: "video/mp4", size: nil, attributes: [.FileName(fileName: "video.mp4"), .Video(duration: Int(finalDuration), size: PixelDimensions(finalDimensions), flags: [.instantRoundVideo])]) - var message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil) + var message: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) let scheduleTime: Int32? = scheduleTimestamp > 0 ? scheduleTimestamp : nil diff --git a/submodules/TelegramUI/Sources/OpenChatMessage.swift b/submodules/TelegramUI/Sources/OpenChatMessage.swift index 328df0ae33..87d8774376 100644 --- a/submodules/TelegramUI/Sources/OpenChatMessage.swift +++ b/submodules/TelegramUI/Sources/OpenChatMessage.swift @@ -67,7 +67,7 @@ func openChatMessageImpl(_ params: OpenChatMessageParams) -> Bool { params.dismissInput() let controllerParams = LocationViewParams(sendLiveLocation: { location in - let outMessage: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: location), replyToMessageId: nil, localGroupingKey: nil) + let outMessage: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: location), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) params.enqueueMessage(outMessage) }, stopLiveLocation: { messageId in params.context.liveLocationManager?.cancelLiveLocation(peerId: messageId?.peerId ?? params.message.id.peerId) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index a6b36c8e90..ac7ede4010 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -4273,7 +4273,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD if let peer = peer as? TelegramUser, let _ = peer.botInfo { strongSelf.activeActionDisposable.set(requestUpdatePeerIsBlocked(account: strongSelf.context.account, peerId: peer.id, isBlocked: block).start()) if !block { - let _ = enqueueMessages(account: strongSelf.context.account, peerId: peer.id, messages: [.message(text: "/start", attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]).start() + let _ = enqueueMessages(account: strongSelf.context.account, peerId: peer.id, messages: [.message(text: "/start", attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]).start() if let navigationController = strongSelf.controller?.navigationController as? NavigationController { strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(peer.id))) } @@ -4643,7 +4643,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD case .help: text = "/help" } - let _ = enqueueMessages(account: strongSelf.context.account, peerId: peer.id, messages: [.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil)]).start() + let _ = enqueueMessages(account: strongSelf.context.account, peerId: peer.id, messages: [.message(text: text, attributes: [], mediaReference: nil, replyToMessageId: nil, localGroupingKey: nil, correlationId: nil)]).start() if let navigationController = strongSelf.controller?.navigationController as? NavigationController { strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(strongSelf.peerId))) @@ -5629,7 +5629,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone) let _ = (enqueueMessages(account: strongSelf.context.account, peerId: peerId, messages: messageIds.map { id -> EnqueueMessage in - return .forward(source: id, grouping: .auto, attributes: []) + return .forward(source: id, grouping: .auto, attributes: [], correlationId: nil) }) |> deliverOnMainQueue).start(next: { [weak self] messageIds in if let strongSelf = self { diff --git a/submodules/TelegramUI/Sources/ReplyAccessoryPanelNode.swift b/submodules/TelegramUI/Sources/ReplyAccessoryPanelNode.swift index c07f07f6c1..d8da3768a1 100644 --- a/submodules/TelegramUI/Sources/ReplyAccessoryPanelNode.swift +++ b/submodules/TelegramUI/Sources/ReplyAccessoryPanelNode.swift @@ -48,10 +48,12 @@ final class ReplyAccessoryPanelNode: AccessoryPanelNode { self.titleNode = ImmediateTextNode() self.titleNode.maximumNumberOfLines = 1 self.titleNode.displaysAsynchronously = false + self.titleNode.insets = UIEdgeInsets(top: 3.0, left: 0.0, bottom: 3.0, right: 0.0) self.textNode = ImmediateTextNode() self.textNode.maximumNumberOfLines = 1 self.textNode.displaysAsynchronously = false + self.textNode.insets = UIEdgeInsets(top: 3.0, left: 0.0, bottom: 3.0, right: 0.0) self.imageNode = TransformImageNode() self.imageNode.contentAnimations = [.subsequentUpdates] @@ -162,8 +164,8 @@ final class ReplyAccessoryPanelNode: AccessoryPanelNode { isMedia = false } - strongSelf.titleNode.attributedText = NSAttributedString(string: authorName, font: Font.medium(15.0), textColor: strongSelf.theme.chat.inputPanel.panelControlAccentColor) - strongSelf.textNode.attributedText = NSAttributedString(string: text, font: Font.regular(15.0), textColor: isMedia ? strongSelf.theme.chat.inputPanel.secondaryTextColor : strongSelf.theme.chat.inputPanel.primaryTextColor) + strongSelf.titleNode.attributedText = NSAttributedString(string: authorName, font: Font.medium(14.0), textColor: strongSelf.theme.chat.inputPanel.panelControlAccentColor) + strongSelf.textNode.attributedText = NSAttributedString(string: text, font: Font.regular(14.0), textColor: isMedia ? strongSelf.theme.chat.inputPanel.secondaryTextColor : strongSelf.theme.chat.inputPanel.primaryTextColor) let headerString: String if let message = message, message.flags.contains(.Incoming), let author = message.author { @@ -239,20 +241,28 @@ final class ReplyAccessoryPanelNode: AccessoryPanelNode { self.closeButton.frame = closeButtonFrame self.actionArea.frame = CGRect(origin: CGPoint(x: leftInset, y: 2.0), size: CGSize(width: closeButtonFrame.minX - leftInset, height: bounds.height)) - - self.lineNode.frame = CGRect(origin: CGPoint(x: leftInset, y: 8.0), size: CGSize(width: 2.0, height: bounds.size.height - 10.0)) + + if self.lineNode.supernode == self { + self.lineNode.frame = CGRect(origin: CGPoint(x: leftInset, y: 8.0), size: CGSize(width: 2.0, height: bounds.size.height - 10.0)) + } var imageTextInset: CGFloat = 0.0 if !self.imageNode.isHidden { imageTextInset = 9.0 + 35.0 } - self.imageNode.frame = CGRect(origin: CGPoint(x: leftInset + 9.0, y: 8.0), size: CGSize(width: 35.0, height: 35.0)) + if self.imageNode.supernode == self { + self.imageNode.frame = CGRect(origin: CGPoint(x: leftInset + 9.0, y: 8.0), size: CGSize(width: 35.0, height: 35.0)) + } let titleSize = self.titleNode.updateLayout(CGSize(width: bounds.size.width - leftInset - textLineInset - rightInset - textRightInset - imageTextInset, height: bounds.size.height)) - self.titleNode.frame = CGRect(origin: CGPoint(x: leftInset + textLineInset + imageTextInset, y: 7.0), size: titleSize) + if self.titleNode.supernode == self { + self.titleNode.frame = CGRect(origin: CGPoint(x: leftInset + textLineInset + imageTextInset - self.titleNode.insets.left, y: 7.0 - self.titleNode.insets.top), size: titleSize) + } let textSize = self.textNode.updateLayout(CGSize(width: bounds.size.width - leftInset - textLineInset - rightInset - textRightInset - imageTextInset, height: bounds.size.height)) - self.textNode.frame = CGRect(origin: CGPoint(x: leftInset + textLineInset + imageTextInset, y: 25.0), size: textSize) + if self.textNode.supernode == self { + self.textNode.frame = CGRect(origin: CGPoint(x: leftInset + textLineInset + imageTextInset - self.textNode.insets.left, y: 25.0 - self.textNode.insets.top), size: textSize) + } } @objc func closePressed() { diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index 7f551fcd19..4bd2823eac 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -1121,7 +1121,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { if !found { let controllerParams = LocationViewParams(sendLiveLocation: { location in - let outMessage: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: location), replyToMessageId: nil, localGroupingKey: nil) + let outMessage: EnqueueMessage = .message(text: "", attributes: [], mediaReference: .standalone(media: location), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil) // params.enqueueMessage(outMessage) }, stopLiveLocation: { messageId in if let messageId = messageId { diff --git a/submodules/WatchBridge/Sources/WatchRequestHandlers.swift b/submodules/WatchBridge/Sources/WatchRequestHandlers.swift index aa7ca83050..59c79a24cf 100644 --- a/submodules/WatchBridge/Sources/WatchRequestHandlers.swift +++ b/submodules/WatchBridge/Sources/WatchRequestHandlers.swift @@ -200,17 +200,17 @@ final class WatchSendMessageHandler: WatchRequestHandler { if args.replyToMid != 0, let peerId = peerId { replyMessageId = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: args.replyToMid) } - messageSignal = .single((.message(text: args.text, attributes: [], mediaReference: nil, replyToMessageId: replyMessageId, localGroupingKey: nil), peerId)) + messageSignal = .single((.message(text: args.text, attributes: [], mediaReference: nil, replyToMessageId: replyMessageId, localGroupingKey: nil, correlationId: nil), peerId)) } else if let args = subscription as? TGBridgeSendLocationMessageSubscription, let location = args.location { let peerId = makePeerIdFromBridgeIdentifier(args.peerId) let map = TelegramMediaMap(latitude: location.latitude, longitude: location.longitude, heading: nil, accuracyRadius: nil, geoPlace: nil, venue: makeVenue(from: location.venue), liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil) - messageSignal = .single((.message(text: "", attributes: [], mediaReference: .standalone(media: map), replyToMessageId: nil, localGroupingKey: nil), peerId)) + messageSignal = .single((.message(text: "", attributes: [], mediaReference: .standalone(media: map), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil), peerId)) } else if let args = subscription as? TGBridgeSendStickerMessageSubscription { let peerId = makePeerIdFromBridgeIdentifier(args.peerId) messageSignal = mediaForSticker(documentId: args.document.documentId, account: context.account) |> map({ media -> (EnqueueMessage?, PeerId?) in if let media = media { - return (.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil), peerId) + return (.message(text: "", attributes: [], mediaReference: .standalone(media: media), replyToMessageId: nil, localGroupingKey: nil, correlationId: nil), peerId) } else { return (nil, nil) } @@ -218,7 +218,7 @@ final class WatchSendMessageHandler: WatchRequestHandler { } else if let args = subscription as? TGBridgeSendForwardedMessageSubscription { let peerId = makePeerIdFromBridgeIdentifier(args.targetPeerId) if let forwardPeerId = makePeerIdFromBridgeIdentifier(args.peerId) { - messageSignal = .single((.forward(source: MessageId(peerId: forwardPeerId, namespace: Namespaces.Message.Cloud, id: args.messageId), grouping: .none, attributes: []), peerId)) + messageSignal = .single((.forward(source: MessageId(peerId: forwardPeerId, namespace: Namespaces.Message.Cloud, id: args.messageId), grouping: .none, attributes: [], correlationId: nil), peerId)) } } @@ -728,7 +728,7 @@ final class WatchAudioHandler: WatchRequestHandler { replyMessageId = MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: replyToMid) } - let _ = enqueueMessages(account: context.account, peerId: peerId, messages: [.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: randomId), partialReference: nil, resource: resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "audio/ogg", size: data.count, attributes: [.Audio(isVoice: true, duration: Int(duration), title: nil, performer: nil, waveform: nil)])), replyToMessageId: replyMessageId, localGroupingKey: nil)]).start() + let _ = enqueueMessages(account: context.account, peerId: peerId, messages: [.message(text: "", attributes: [], mediaReference: .standalone(media: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: randomId), partialReference: nil, resource: resource, previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "audio/ogg", size: data.count, attributes: [.Audio(isVoice: true, duration: Int(duration), title: nil, performer: nil, waveform: nil)])), replyToMessageId: replyMessageId, localGroupingKey: nil, correlationId: nil)]).start() } }) } else {