From d895130cd19a40a26dbafff9925f6682a80bf0f5 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 6 Nov 2021 11:26:18 +0400 Subject: [PATCH 1/4] Fix send as peer --- submodules/TelegramApi/Sources/Api4.swift | 15 --------------- .../Sources/ApiUtils/ApiUtils.swift | 7 +++++++ .../StandaloneSendMessage.swift | 2 +- .../Sources/State/PendingMessageManager.swift | 18 +++++++++--------- .../TelegramEngine/Messages/ForwardGame.swift | 2 +- .../TelegramEngine/Messages/SendAsPeers.swift | 2 +- .../TelegramUI/Sources/ChatController.swift | 2 +- 7 files changed, 20 insertions(+), 28 deletions(-) diff --git a/submodules/TelegramApi/Sources/Api4.swift b/submodules/TelegramApi/Sources/Api4.swift index 3a9a0b693d..0c31eeaaf1 100644 --- a/submodules/TelegramApi/Sources/Api4.swift +++ b/submodules/TelegramApi/Sources/Api4.swift @@ -5123,21 +5123,6 @@ public extension Api { }) } - public static func toggleNoForwards(channel: Api.InputChannel, enabled: Api.Bool) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { - let buffer = Buffer() - buffer.appendInt32(-219318255) - channel.serialize(buffer, true) - enabled.serialize(buffer, true) - return (FunctionDescription(name: "channels.toggleNoForwards", parameters: [("channel", channel), ("enabled", enabled)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.Updates? in - let reader = BufferReader(buffer) - var result: Api.Updates? - if let signature = reader.readInt32() { - result = Api.parse(reader, signature: signature) as? Api.Updates - } - return result - }) - } - public static func getSendAs(peer: Api.InputPeer) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() buffer.appendInt32(231174382) diff --git a/submodules/TelegramCore/Sources/ApiUtils/ApiUtils.swift b/submodules/TelegramCore/Sources/ApiUtils/ApiUtils.swift index 19bb0ca95e..dfeb3a34d2 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/ApiUtils.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/ApiUtils.swift @@ -79,6 +79,13 @@ func apiInputPeer(_ peer: Peer) -> Api.InputPeer? { } } +func apiInputPeerOrSelf(_ peer: Peer, accountPeerId: PeerId) -> Api.InputPeer? { + if peer.id == accountPeerId { + return .inputPeerSelf + } + return apiInputPeer(peer) +} + func apiInputChannel(_ peer: Peer) -> Api.InputChannel? { if let channel = peer as? TelegramChannel, let accessHash = channel.accessHash { return Api.InputChannel.inputChannel(channelId: channel.id.id._internalGetInt64Value(), accessHash: accessHash.value) diff --git a/submodules/TelegramCore/Sources/PendingMessages/StandaloneSendMessage.swift b/submodules/TelegramCore/Sources/PendingMessages/StandaloneSendMessage.swift index a65b827d13..cd0154fd42 100644 --- a/submodules/TelegramCore/Sources/PendingMessages/StandaloneSendMessage.swift +++ b/submodules/TelegramCore/Sources/PendingMessages/StandaloneSendMessage.swift @@ -112,7 +112,7 @@ private func sendMessageContent(account: Account, peerId: PeerId, attributes: [M } var sendAsInputPeer: Api.InputPeer? - if let sendAsPeerId = sendAsPeerId, let sendAsPeer = transaction.getPeer(sendAsPeerId), let inputPeer = apiInputPeer(sendAsPeer) { + if let sendAsPeerId = sendAsPeerId, let sendAsPeer = transaction.getPeer(sendAsPeerId), let inputPeer = apiInputPeerOrSelf(sendAsPeer, accountPeerId: account.peerId) { sendAsInputPeer = inputPeer flags |= (1 << 13) } diff --git a/submodules/TelegramCore/Sources/State/PendingMessageManager.swift b/submodules/TelegramCore/Sources/State/PendingMessageManager.swift index 0032b58d15..cba4a35efc 100644 --- a/submodules/TelegramCore/Sources/State/PendingMessageManager.swift +++ b/submodules/TelegramCore/Sources/State/PendingMessageManager.swift @@ -433,13 +433,13 @@ public final class PendingMessageManager { } Logger.shared.log("PendingMessageManager", "beginSendingMessages messagesToForward.count: \(messagesToForward.count)") - + for (_, messages) in messagesToForward { for (context, _, _) in messages { context.state = .sending(groupId: nil) } - let sendMessage: Signal = strongSelf.sendGroupMessagesContent(network: strongSelf.network, postbox: strongSelf.postbox, stateManager: strongSelf.stateManager, group: messages.map { data in + let sendMessage: Signal = strongSelf.sendGroupMessagesContent(network: strongSelf.network, postbox: strongSelf.postbox, stateManager: strongSelf.stateManager, accountPeerId: strongSelf.accountPeerId, group: messages.map { data in let (_, message, forwardInfo) = data return (message.id, PendingMessageUploadedContentAndReuploadInfo(content: .forward(forwardInfo), reuploadInfo: nil)) }) @@ -508,7 +508,7 @@ public final class PendingMessageManager { for (context, _, _) in messages { context.state = .sending(groupId: groupId) } - let sendMessage: Signal = self.sendGroupMessagesContent(network: self.network, postbox: self.postbox, stateManager: self.stateManager, group: messages.map { ($0.1, $0.2) }) + let sendMessage: Signal = self.sendGroupMessagesContent(network: self.network, postbox: self.postbox, stateManager: self.stateManager, accountPeerId: self.accountPeerId, group: messages.map { ($0.1, $0.2) }) |> map { next -> PendingMessageResult in return .progress(1.0) } @@ -518,7 +518,7 @@ public final class PendingMessageManager { private func commitSendingSingleMessage(messageContext: PendingMessageContext, messageId: MessageId, content: PendingMessageUploadedContentAndReuploadInfo) { messageContext.state = .sending(groupId: nil) - let sendMessage: Signal = self.sendMessageContent(network: self.network, postbox: self.postbox, stateManager: self.stateManager, messageId: messageId, content: content) + let sendMessage: Signal = self.sendMessageContent(network: self.network, postbox: self.postbox, stateManager: self.stateManager, accountPeerId: self.accountPeerId, messageId: messageId, content: content) |> map { next -> PendingMessageResult in return .progress(1.0) } @@ -669,7 +669,7 @@ public final class PendingMessageManager { } } - private func sendGroupMessagesContent(network: Network, postbox: Postbox, stateManager: AccountStateManager, group: [(messageId: MessageId, content: PendingMessageUploadedContentAndReuploadInfo)]) -> Signal { + private func sendGroupMessagesContent(network: Network, postbox: Postbox, stateManager: AccountStateManager, accountPeerId: PeerId, group: [(messageId: MessageId, content: PendingMessageUploadedContentAndReuploadInfo)]) -> Signal { let queue = self.queue return postbox.transaction { [weak self] transaction -> Signal in if group.isEmpty { @@ -738,7 +738,7 @@ public final class PendingMessageManager { } var sendAsInputPeer: Api.InputPeer? - if let sendAsPeerId = sendAsPeerId, let sendAsPeer = transaction.getPeer(sendAsPeerId), let inputPeer = apiInputPeer(sendAsPeer) { + if let sendAsPeerId = sendAsPeerId, let sendAsPeer = transaction.getPeer(sendAsPeerId), let inputPeer = apiInputPeerOrSelf(sendAsPeer, accountPeerId: accountPeerId) { sendAsInputPeer = inputPeer flags |= (1 << 13) } @@ -784,7 +784,7 @@ public final class PendingMessageManager { } var sendAsInputPeer: Api.InputPeer? - if let sendAsPeerId = sendAsPeerId, let sendAsPeer = transaction.getPeer(sendAsPeerId), let inputPeer = apiInputPeer(sendAsPeer) { + if let sendAsPeerId = sendAsPeerId, let sendAsPeer = transaction.getPeer(sendAsPeerId), let inputPeer = apiInputPeerOrSelf(sendAsPeer, accountPeerId: accountPeerId) { sendAsInputPeer = inputPeer flags |= (1 << 13) } @@ -976,7 +976,7 @@ public final class PendingMessageManager { } } - private func sendMessageContent(network: Network, postbox: Postbox, stateManager: AccountStateManager, messageId: MessageId, content: PendingMessageUploadedContentAndReuploadInfo) -> Signal { + private func sendMessageContent(network: Network, postbox: Postbox, stateManager: AccountStateManager, accountPeerId: PeerId, messageId: MessageId, content: PendingMessageUploadedContentAndReuploadInfo) -> Signal { let queue = self.queue return postbox.transaction { [weak self] transaction -> Signal in guard let message = transaction.getMessage(messageId) else { @@ -1034,7 +1034,7 @@ public final class PendingMessageManager { } var sendAsInputPeer: Api.InputPeer? - if let sendAsPeerId = sendAsPeerId, let sendAsPeer = transaction.getPeer(sendAsPeerId), let inputPeer = apiInputPeer(sendAsPeer) { + if let sendAsPeerId = sendAsPeerId, let sendAsPeer = transaction.getPeer(sendAsPeerId), let inputPeer = apiInputPeerOrSelf(sendAsPeer, accountPeerId: accountPeerId) { sendAsInputPeer = inputPeer flags |= (1 << 13) } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/ForwardGame.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ForwardGame.swift index 47e0b36d5f..4eae836fe4 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/ForwardGame.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/ForwardGame.swift @@ -9,7 +9,7 @@ func _internal_forwardGameWithScore(account: Account, messageId: MessageId, to p var flags: Int32 = 1 << 8 var sendAsInputPeer: Api.InputPeer? - if let sendAsPeerId = sendAsPeerId, let sendAsPeer = transaction.getPeer(sendAsPeerId), let inputPeer = apiInputPeer(sendAsPeer) { + if let sendAsPeerId = sendAsPeerId, let sendAsPeer = transaction.getPeer(sendAsPeerId), let inputPeer = apiInputPeerOrSelf(sendAsPeer, accountPeerId: account.peerId) { sendAsInputPeer = inputPeer flags |= (1 << 13) } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/SendAsPeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/SendAsPeers.swift index 4a14a4a35a..bb9571419e 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/SendAsPeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/SendAsPeers.swift @@ -125,7 +125,7 @@ public enum UpdatePeerSendAsPeerError { func _internal_updatePeerSendAsPeer(account: Account, peerId: PeerId, sendAs: PeerId) -> Signal { return account.postbox.transaction { transaction -> (Api.InputPeer, Api.InputPeer)? in - if let peer = transaction.getPeer(peerId), let sendAsPeer = transaction.getPeer(sendAs), let inputPeer = apiInputPeer(peer), let sendAsInputPeer = apiInputPeer(sendAsPeer) { + if let peer = transaction.getPeer(peerId), let sendAsPeer = transaction.getPeer(sendAs), let inputPeer = apiInputPeer(peer), let sendAsInputPeer = apiInputPeerOrSelf(sendAsPeer, accountPeerId: account.peerId) { transaction.updatePeerCachedData(peerIds: Set([peerId]), update: { _, cachedData -> CachedPeerData? in if let cachedData = cachedData as? CachedChannelData { return cachedData.withUpdatedSendAsPeerId(sendAs) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index c2ab63641a..2e2f079c63 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -3922,7 +3922,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var presentationData = presentationData var useDarkAppearance = presentationData.theme.overallDarkAppearance - if let themeEmoticon = themeEmoticon, let theme = chatThemes.first(where: { $0.emoticon == themeEmoticon }) { + if let themeEmoticon = themeEmoticon, let theme = chatThemes.first(where: { $0.emoticon?.strippedEmoji == themeEmoticon.strippedEmoji }) { if let darkAppearancePreview = darkAppearancePreview { useDarkAppearance = darkAppearancePreview } From ab59881d2d20b9749a5d97fb2f27e919c38f8fac Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 6 Nov 2021 14:40:24 +0400 Subject: [PATCH 2/4] Fix send as peer in discussion groups --- .../Telegram-iOS/en.lproj/Localizable.strings | 2 ++ .../TelegramUI/Sources/ChatController.swift | 28 ++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 4c16d038c0..589d7f4a94 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -7049,3 +7049,5 @@ Sorry for the inconvenience."; "Channel.AdminLog.MessageToggleNoForwardsOn" = "%@ enabled no-forwards"; "Channel.AdminLog.MessageToggleNoForwardsOff" = "%@ disabled no-forwards"; + +"VoiceChat.DiscussionGroup" = "discussion group"; diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 2e2f079c63..2e2bac23bb 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -4565,14 +4565,18 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G return [FoundPeer(peer: peer, subscribers: nil)] } - let _ = (combineLatest(queue: Queue.mainQueue(), currentAccountPeer, self.context.engine.peers.sendAsAvailablePeers(peerId: self.chatLocation.peerId))) - .start(next: { [weak self] currentAccountPeer, peers in + let _ = (combineLatest(queue: Queue.mainQueue(), currentAccountPeer, self.context.account.postbox.peerView(id: self.chatLocation.peerId), self.context.engine.peers.sendAsAvailablePeers(peerId: self.chatLocation.peerId))) + .start(next: { [weak self] currentAccountPeer, peerView, peers in guard let strongSelf = self else { return } var allPeers: [FoundPeer]? if !peers.isEmpty { - allPeers = currentAccountPeer + if let channel = peerViewMainPeer(peerView) as? TelegramChannel, case .group = channel.info, channel.hasPermission(.canBeAnonymous) { + allPeers = [] + } else { + allPeers = currentAccountPeer + } allPeers?.append(contentsOf: peers) } strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: false, { @@ -7397,8 +7401,14 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G guard let strongSelf = self, let node = node as? ContextReferenceContentNode, let peers = strongSelf.presentationInterfaceState.sendAsPeers else { return } - - let myPeerId = strongSelf.presentationInterfaceState.currentSendAsPeerId ?? strongSelf.context.account.peerId + + let defaultMyPeerId: PeerId + if let channel = strongSelf.presentationInterfaceState.renderedPeer?.chatMainPeer as? TelegramChannel, case .group = channel.info, channel.hasPermission(.canBeAnonymous) { + defaultMyPeerId = channel.id + } else { + defaultMyPeerId = strongSelf.context.account.peerId + } + let myPeerId = strongSelf.presentationInterfaceState.currentSendAsPeerId ?? defaultMyPeerId let avatarSize = CGSize(width: 28.0, height: 28.0) var items: [ContextMenuItem] = [] @@ -7410,8 +7420,12 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if peer.peer.id.namespace == Namespaces.Peer.CloudUser { subtitle = strongSelf.presentationData.strings.VoiceChat_PersonalAccount } else if let subscribers = peer.subscribers { - if let peer = peer.peer as? TelegramChannel, case .broadcast = peer.info { - subtitle = strongSelf.presentationData.strings.Conversation_StatusSubscribers(subscribers) + if let peer = peer.peer as? TelegramChannel { + if case .broadcast = peer.info { + subtitle = strongSelf.presentationData.strings.Conversation_StatusSubscribers(subscribers) + } else { + subtitle = strongSelf.presentationData.strings.VoiceChat_DiscussionGroup + } } else { subtitle = strongSelf.presentationData.strings.Conversation_StatusMembers(subscribers) } From b40173084a495f89be6eaf9fffd0e0ac0576be1d Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sun, 7 Nov 2021 00:11:05 +0400 Subject: [PATCH 3/4] Various Fixes --- .../Telegram-iOS/en.lproj/Localizable.strings | 4 ++ .../ChatListUI/Sources/ChatContextMenus.swift | 10 ++- .../Sources/ItemListPeerItem.swift | 1 + .../Sources/ChannelVisibilityController.swift | 10 ++- .../TelegramUI/Sources/ChatController.swift | 34 +++++++-- .../Sources/ChatControllerNode.swift | 11 ++- .../ChatInterfaceStateContextMenus.swift | 2 +- .../ChatRecentActionsHistoryTransition.swift | 72 ++++++++++++------- .../Sources/PeerInfo/PeerInfoHeaderNode.swift | 31 ++++++-- .../Sources/PeerInfo/PeerInfoScreen.swift | 58 +++++++-------- 10 files changed, 159 insertions(+), 74 deletions(-) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 589d7f4a94..b5056e38b3 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -2657,6 +2657,7 @@ Unused sets are archived when you add more."; "Channel.AdminLog.CaptionEdited" = "%@ edited caption:"; "Channel.AdminLog.MessageDeleted" = "%@ deleted message:"; "Channel.AdminLog.MessagePinned" = "%@ pinned message:"; +"Channel.AdminLog.MessageUnpinnedExtended" = "%@ unpinned message:"; "Channel.AdminLog.MessageInvitedName" = "invited %1$@"; "Channel.AdminLog.MessageInvitedNameUsername" = "invited %1$@ (%2$@)"; @@ -4848,6 +4849,7 @@ Sorry for the inconvenience."; "ChatList.Context.Mute" = "Mute"; "ChatList.Context.Unmute" = "Unmute"; "ChatList.Context.JoinChannel" = "Join Channel"; +"ChatList.Context.JoinChat" = "Join Chat"; "ChatList.Context.Delete" = "Delete"; "ContactList.Context.SendMessage" = "Send Message"; @@ -7051,3 +7053,5 @@ Sorry for the inconvenience."; "Channel.AdminLog.MessageToggleNoForwardsOff" = "%@ disabled no-forwards"; "VoiceChat.DiscussionGroup" = "discussion group"; + +"Group.Edit.PrivatePublicLinkAlert" = "Please note that if you choose a public link for your group, anyone will be able to find it in search and join.\n\nDo not create this link if you want your group to stay private."; diff --git a/submodules/ChatListUI/Sources/ChatContextMenus.swift b/submodules/ChatListUI/Sources/ChatContextMenus.swift index a5ebb5cc32..27c70dd60f 100644 --- a/submodules/ChatListUI/Sources/ChatContextMenus.swift +++ b/submodules/ChatListUI/Sources/ChatContextMenus.swift @@ -328,8 +328,14 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch } } else { if case .search = source { - if let _ = peer as? TelegramChannel { - items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_JoinChannel, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Add"), color: theme.contextMenu.primaryColor) }, action: { _, f in + if let peer = peer as? TelegramChannel { + let text: String + if case .broadcast = peer.info { + text = strings.ChatList_Context_JoinChannel + } else { + text = strings.ChatList_Context_JoinChat + } + items.append(.action(ContextMenuActionItem(text: text, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Add"), color: theme.contextMenu.primaryColor) }, action: { _, f in var createSignal = context.peerChannelMemberCategoriesContextsManager.join(engine: context.engine, peerId: peerId, hash: nil) var cancelImpl: (() -> Void)? let progressSignal = Signal { subscriber in diff --git a/submodules/ItemListPeerItem/Sources/ItemListPeerItem.swift b/submodules/ItemListPeerItem/Sources/ItemListPeerItem.swift index ff219bab35..dc4d38f2c5 100644 --- a/submodules/ItemListPeerItem/Sources/ItemListPeerItem.swift +++ b/submodules/ItemListPeerItem/Sources/ItemListPeerItem.swift @@ -1012,6 +1012,7 @@ public class ItemListPeerItemNode: ItemListRevealOptionsItemNode, ItemListItemNo case .sameSection(false): bottomStripeInset = leftInset + editingOffset bottomStripeOffset = -separatorHeight + strongSelf.bottomStripeNode.isHidden = !item.displayDecorations default: bottomStripeInset = 0.0 bottomStripeOffset = 0.0 diff --git a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift index 8ba9966cea..f022eff88a 100644 --- a/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelVisibilityController.swift @@ -1156,7 +1156,13 @@ public func channelVisibilityController(context: AccountContext, updatedPresenta _ = (ApplicationSpecificNotice.getSetPublicChannelLink(accountManager: context.sharedContext.accountManager) |> deliverOnMainQueue).start(next: { showAlert in if showAlert { - presentControllerImpl?(textAlertController(context: context, updatedPresentationData: updatedPresentationData, title: nil, text: presentationData.strings.Channel_Edit_PrivatePublicLinkAlert, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: invokeAction)]), nil) + let text: String + if case .broadcast = peer.info { + text = presentationData.strings.Channel_Edit_PrivatePublicLinkAlert + } else { + text = presentationData.strings.Group_Edit_PrivatePublicLinkAlert + } + presentControllerImpl?(textAlertController(context: context, updatedPresentationData: updatedPresentationData, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: invokeAction)]), nil) } else { invokeAction() } @@ -1242,7 +1248,7 @@ public func channelVisibilityController(context: AccountContext, updatedPresenta _ = (ApplicationSpecificNotice.getSetPublicChannelLink(accountManager: context.sharedContext.accountManager) |> deliverOnMainQueue).start(next: { showAlert in if showAlert { - presentControllerImpl?(textAlertController(context: context, updatedPresentationData: updatedPresentationData, title: nil, text: presentationData.strings.Channel_Edit_PrivatePublicLinkAlert, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: invokeAction)]), nil) + presentControllerImpl?(textAlertController(context: context, updatedPresentationData: updatedPresentationData, title: nil, text: presentationData.strings.Group_Edit_PrivatePublicLinkAlert, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: invokeAction)]), nil) } else { invokeAction() } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 2e2bac23bb..9afb9adbc4 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -5737,6 +5737,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G messagesCount = .single(1) } + let accountPeerId = strongSelf.context.account.peerId let items = combineLatest(forwardOptions, strongSelf.context.account.postbox.messagesAtIds(messageIds), messagesCount) |> map { forwardOptions, messages, messagesCount -> [ContextMenuItem] in var items: [ContextMenuItem] = [] @@ -5745,9 +5746,18 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var uniquePeerIds = Set() var hasOther = false + var hasNotOwnMessages = false for message in messages { - if let author = message.effectiveAuthor, !uniquePeerIds.contains(author.id) { - uniquePeerIds.insert(author.id) + if let author = message.effectiveAuthor { + if !uniquePeerIds.contains(author.id) { + uniquePeerIds.insert(author.id) + } + + if message.id.peerId == accountPeerId && author.id == accountPeerId { + + } else { + hasNotOwnMessages = true + } } var isDice = false @@ -5770,7 +5780,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } } - let canHideNames = hasOther + let canHideNames = hasNotOwnMessages && hasOther let hideNames = forwardOptions.hideNames let hideCaptions = forwardOptions.hideCaptions @@ -12015,11 +12025,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } } controller.peerSelected = { [weak self, weak controller] peer in - let peerId = peer.id - guard let strongSelf = self, let strongController = controller else { return } + let peerId = peer.id + let accountPeerId = strongSelf.context.account.peerId if resetCurrent { strongSelf.updateChatPresentationInterfaceState(animated: false, interactive: true, { $0.updatedInterfaceState({ $0.withUpdatedForwardMessageIds(nil).withUpdatedForwardOptionsState(nil) }) }) @@ -12030,8 +12040,18 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G isPinnedMessages = true } + var hasNotOwnMessages = false + for message in messages { + if let author = message.effectiveAuthor { + if message.id.peerId == accountPeerId && author.id == accountPeerId { + } else { + hasNotOwnMessages = true + } + } + } + if case .peer(peerId) = strongSelf.chatLocation, strongSelf.parentController == nil, !isPinnedMessages { - strongSelf.updateChatPresentationInterfaceState(animated: false, interactive: true, { $0.updatedInterfaceState({ $0.withUpdatedForwardMessageIds(messages.map { $0.id }).withoutSelectionState() }).updatedSearch(nil) }) + strongSelf.updateChatPresentationInterfaceState(animated: false, interactive: true, { $0.updatedInterfaceState({ $0.withUpdatedForwardMessageIds(messages.map { $0.id }).withUpdatedForwardOptionsState(ChatInterfaceForwardOptionsState(hideNames: !hasNotOwnMessages, hideCaptions: false, unhideNamesOnCaptionChange: false)).withoutSelectionState() }).updatedSearch(nil) }) strongSelf.updateItemNodesSearchTextHighlightStates() strongSelf.searchResultsController = nil strongController.dismiss() @@ -12094,7 +12114,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } let _ = (ChatInterfaceState.update(engine: strongSelf.context.engine, peerId: peerId, threadId: nil, { currentState in - return currentState.withUpdatedForwardMessageIds(messages.map { $0.id }) + return currentState.withUpdatedForwardMessageIds(messages.map { $0.id }).withUpdatedForwardOptionsState(ChatInterfaceForwardOptionsState(hideNames: !hasNotOwnMessages, hideCaptions: false, unhideNamesOnCaptionChange: false)) }) |> deliverOnMainQueue).start(completed: { if let strongSelf = self { diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index 20c49b6e8a..3bc912c7f7 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -278,10 +278,17 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { return true }) + var hideNames = options.hideNames + if let author = message.effectiveAuthor { + if message.id.peerId == accountPeer.id && author.id == accountPeer.id { + hideNames = true + } + } + var messageText = message.text var messageMedia = message.media var hasDice = false - if options.hideNames { + if hideNames { for media in message.media { if options.hideCaptions { if media is TelegramMediaImage || media is TelegramMediaFile { @@ -304,7 +311,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { if forwardInfo == nil { forwardInfo = MessageForwardInfo(author: message.author, source: nil, sourceMessageId: nil, date: 0, authorSignature: nil, psaType: nil, flags: []) } - if options.hideNames && !hasDice { + if hideNames && !hasDice { forwardInfo = nil } diff --git a/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift b/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift index 8321f74241..46c9fb0d25 100644 --- a/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift +++ b/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift @@ -1014,7 +1014,7 @@ func contextMenuForChatPresentationInterfaceState(chatPresentationInterfaceState break } } - if let file = media as? TelegramMediaFile { + if let file = media as? TelegramMediaFile, !message.isCopyProtected() { if file.isVideo { if file.isAnimated { actions.append(.action(ContextMenuActionItem(text: chatPresentationInterfaceState.strings.Conversation_LinkDialogSave, icon: { theme in diff --git a/submodules/TelegramUI/Sources/ChatRecentActionsHistoryTransition.swift b/submodules/TelegramUI/Sources/ChatRecentActionsHistoryTransition.swift index 09b5ee1dd0..c05de46afc 100644 --- a/submodules/TelegramUI/Sources/ChatRecentActionsHistoryTransition.swift +++ b/submodules/TelegramUI/Sources/ChatRecentActionsHistoryTransition.swift @@ -290,7 +290,14 @@ struct ChatRecentActionsEntry: Comparable, Identifiable { var text: String = "" var entities: [MessageTextEntity] = [] - appendAttributedText(text: self.presentationData.strings.Channel_AdminLog_MessagePinned(author.flatMap(EnginePeer.init)?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? ""), generateEntities: { index in + let textFormat: (String) -> PresentationStrings.FormattedString + if let message = message, message.tags.contains(.pinned) { + textFormat = self.presentationData.strings.Channel_AdminLog_MessagePinned + } else { + textFormat = self.presentationData.strings.Channel_AdminLog_MessageUnpinnedExtended + } + + appendAttributedText(text: textFormat(author.flatMap(EnginePeer.init)?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? ""), generateEntities: { index in if index == 0, let author = author { return [.TextMention(peerId: author.id)] } @@ -764,31 +771,48 @@ struct ChatRecentActionsEntry: Comparable, Identifiable { } } - for (flag, string) in order { - if prevFlags.contains(flag) != newFlags.contains(flag) { - if !appendedRightsHeader { - appendedRightsHeader = true - appendAttributedText(text: new.peer.addressName == nil ? self.presentationData.strings.Channel_AdminLog_MessagePromotedName(EnginePeer(new.peer).displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder)) : self.presentationData.strings.Channel_AdminLog_MessagePromotedNameUsername(EnginePeer(new.peer).displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder), "@" + new.peer.addressName!), generateEntities: { index in - var result: [MessageTextEntityType] = [] - if index == 0 { - result.append(.TextMention(peerId: new.peer.id)) - } else if index == 1 { - result.append(.Mention) - } else if index == 2 { - result.append(.Bold) - } - return result - }, to: &text, entities: &entities) + if !prevFlags.isEmpty && newFlags.isEmpty { + if !appendedRightsHeader { + appendedRightsHeader = true + appendAttributedText(text: new.peer.addressName == nil ? self.presentationData.strings.Channel_AdminLog_MessageRemovedAdminName(EnginePeer(new.peer).displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder)) : self.presentationData.strings.Channel_AdminLog_MessageRemovedAdminNameUsername(EnginePeer(new.peer).displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder), "@" + new.peer.addressName!), generateEntities: { index in + var result: [MessageTextEntityType] = [] + if index == 0 { + result.append(.TextMention(peerId: new.peer.id)) + } else if index == 1 { + result.append(.Mention) + } else if index == 2 { + result.append(.Bold) + } + return result + }, to: &text, entities: &entities) + } + } else { + for (flag, string) in order { + if prevFlags.contains(flag) != newFlags.contains(flag) { + if !appendedRightsHeader { + appendedRightsHeader = true + appendAttributedText(text: new.peer.addressName == nil ? self.presentationData.strings.Channel_AdminLog_MessagePromotedName(EnginePeer(new.peer).displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder)) : self.presentationData.strings.Channel_AdminLog_MessagePromotedNameUsername(EnginePeer(new.peer).displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder), "@" + new.peer.addressName!), generateEntities: { index in + var result: [MessageTextEntityType] = [] + if index == 0 { + result.append(.TextMention(peerId: new.peer.id)) + } else if index == 1 { + result.append(.Mention) + } else if index == 2 { + result.append(.Bold) + } + return result + }, to: &text, entities: &entities) + text += "\n" + } + text += "\n" + if !prevFlags.contains(flag) { + text += "+" + } else { + text += "-" + } + appendAttributedText(text: string, withEntities: [.Italic], to: &text, entities: &entities) } - - text += "\n" - if !prevFlags.contains(flag) { - text += "+" - } else { - text += "-" - } - appendAttributedText(text: string, withEntities: [.Italic], to: &text, entities: &entities) } } diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift index cbd2869fa1..05b55fd2d5 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoHeaderNode.swift @@ -916,10 +916,12 @@ final class PeerInfoAvatarListNode: ASDisplayNode { } final class PeerInfoHeaderNavigationButton: HighlightableButtonNode { + let containerNode: ContextControllerSourceNode let contextSourceNode: ContextReferenceContentNode private let regularTextNode: ImmediateTextNode private let whiteTextNode: ImmediateTextNode private let iconNode: ASImageNode + private var animationNode: AnimationNode? private var key: PeerInfoHeaderNavigationButtonKey? private var theme: PresentationTheme? @@ -933,11 +935,13 @@ final class PeerInfoHeaderNavigationButton: HighlightableButtonNode { } } - var action: (() -> Void)? + var action: ((ASDisplayNode, ContextGesture?) -> Void)? init() { self.contextSourceNode = ContextReferenceContentNode() - + self.containerNode = ContextControllerSourceNode() + self.containerNode.animateScale = false + self.regularTextNode = ImmediateTextNode() self.whiteTextNode = ImmediateTextNode() self.whiteTextNode.isHidden = true @@ -951,17 +955,25 @@ final class PeerInfoHeaderNavigationButton: HighlightableButtonNode { self.isAccessibilityElement = true self.accessibilityTraits = .button + self.containerNode.addSubnode(self.contextSourceNode) self.contextSourceNode.addSubnode(self.regularTextNode) self.contextSourceNode.addSubnode(self.whiteTextNode) self.contextSourceNode.addSubnode(self.iconNode) - self.addSubnode(self.contextSourceNode) + self.addSubnode(self.containerNode) + + self.containerNode.activated = { [weak self] gesture, _ in + guard let strongSelf = self else { + return + } + strongSelf.action?(strongSelf.contextSourceNode, gesture) + } self.addTarget(self, action: #selector(self.pressed), forControlEvents: .touchUpInside) } @objc private func pressed() { - self.action?() + self.action?(self.contextSourceNode, nil) } func update(key: PeerInfoHeaderNavigationButtonKey, presentationData: PresentationData, height: CGFloat) -> CGSize { @@ -973,6 +985,7 @@ final class PeerInfoHeaderNavigationButton: HighlightableButtonNode { let text: String var icon: UIImage? var isBold = false + var isGestureEnabled = false switch key { case .edit: text = presentationData.strings.Common_Edit @@ -991,8 +1004,10 @@ final class PeerInfoHeaderNavigationButton: HighlightableButtonNode { case .more: text = "" icon = PresentationResourcesRootController.navigationMoreCircledIcon(presentationData.theme) + isGestureEnabled = true } self.accessibilityLabel = text + self.containerNode.isGestureEnabled = isGestureEnabled let font: UIFont = isBold ? Font.semibold(17.0) : Font.regular(17.0) @@ -1016,10 +1031,12 @@ final class PeerInfoHeaderNavigationButton: HighlightableButtonNode { self.iconNode.frame = CGRect(origin: CGPoint(x: inset, y: floor((height - image.size.height) / 2.0)), size: image.size) let size = CGSize(width: image.size.width + inset * 2.0, height: height) + self.containerNode.frame = CGRect(origin: CGPoint(), size: size) self.contextSourceNode.frame = CGRect(origin: CGPoint(), size: size) return size } else { let size = CGSize(width: textSize.width + inset * 2.0, height: height) + self.containerNode.frame = CGRect(origin: CGPoint(), size: size) self.contextSourceNode.frame = CGRect(origin: CGPoint(), size: size) return size } @@ -1059,7 +1076,7 @@ final class PeerInfoHeaderNavigationButtonContainerNode: ASDisplayNode { } } - var performAction: ((PeerInfoHeaderNavigationButtonKey, ContextReferenceContentNode?) -> Void)? + var performAction: ((PeerInfoHeaderNavigationButtonKey, ContextReferenceContentNode?, ContextGesture?) -> Void)? func update(size: CGSize, presentationData: PresentationData, buttons: [PeerInfoHeaderNavigationButtonSpec], expandFraction: CGFloat, transition: ContainedViewLayoutTransition) { let maximumExpandOffset: CGFloat = 14.0 @@ -1080,11 +1097,11 @@ final class PeerInfoHeaderNavigationButtonContainerNode: ASDisplayNode { self.buttonNodes[spec.key] = buttonNode self.addSubnode(buttonNode) buttonNode.isWhite = self.isWhite - buttonNode.action = { [weak self] in + buttonNode.action = { [weak self] _, gesture in guard let strongSelf = self, let buttonNode = strongSelf.buttonNodes[spec.key] else { return } - strongSelf.performAction?(spec.key, buttonNode.contextSourceNode) + strongSelf.performAction?(spec.key, buttonNode.contextSourceNode, gesture) } } let buttonSize = buttonNode.update(key: spec.key, presentationData: presentationData, height: size.height) diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index b7808516e8..fdeb13b557 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -1884,7 +1884,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate if actions.options.contains(.deleteGlobally) { let globalTitle: String if isChannel { - globalTitle = presentationData.strings.Conversation_DeleteMessagesForMe + globalTitle = presentationData.strings.Conversation_DeleteMessagesForEveryone } else if let personalPeerName = personalPeerName { globalTitle = presentationData.strings.Conversation_DeleteMessagesFor(personalPeerName).string } else { @@ -1893,7 +1893,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate items.append(.action(ContextMenuActionItem(text: globalTitle, textColor: .destructive, icon: { _ in nil }, action: { c, f in c.dismiss(completion: { if let strongSelf = self { - strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil, nil) let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone).start() } }) @@ -1912,7 +1912,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate items.append(.action(ContextMenuActionItem(text: localOptionText, textColor: .destructive, icon: { _ in nil }, action: { c, f in c.dismiss(completion: { if let strongSelf = self { - strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil, nil) let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forLocalPeer).start() } }) @@ -2029,7 +2029,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate items.append(.action(ContextMenuActionItem(text: globalTitle, textColor: .destructive, icon: { _ in nil }, action: { c, f in c.dismiss(completion: { if let strongSelf = self { - strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil, nil) let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone).start() } }) @@ -2048,7 +2048,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate items.append(.action(ContextMenuActionItem(text: localOptionText, textColor: .destructive, icon: { _ in nil }, action: { c, f in c.dismiss(completion: { if let strongSelf = self { - strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil, nil) let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forLocalPeer).start() } }) @@ -2530,7 +2530,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate } } - self.headerNode.navigationButtonContainer.performAction = { [weak self] key, source in + self.headerNode.navigationButtonContainer.performAction = { [weak self] key, source, gesture in guard let strongSelf = self else { return } @@ -2571,7 +2571,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate strongSelf.view.endEditing(true) if case .done = key { guard let data = strongSelf.data else { - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) return } if let peer = data.peer as? TelegramUser { @@ -2614,10 +2614,10 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate guard let strongSelf = self else { return } - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) })) } else { - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) } } else if data.isContact { let firstName = strongSelf.headerNode.editingContentNode.editingTextForKey(.firstName) ?? "" @@ -2648,7 +2648,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate guard let strongSelf = self else { return } - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) }, completed: { dismissStatus?() @@ -2677,14 +2677,14 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate } } }).start() - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) })) } } else { - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) } } else { - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) } } else if let group = data.peer as? TelegramGroup, canEditPeerInfo(context: strongSelf.context, peer: group) { let title = strongSelf.headerNode.editingContentNode.editingTextForKey(.title) ?? "" @@ -2735,14 +2735,14 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate guard let strongSelf = self else { return } - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) }, completed: { dismissStatus?() guard let strongSelf = self else { return } - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) })) } } else if let channel = data.peer as? TelegramChannel, canEditPeerInfo(context: strongSelf.context, peer: channel) { @@ -2794,21 +2794,21 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate guard let strongSelf = self else { return } - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) }, completed: { dismissStatus?() guard let strongSelf = self else { return } - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) })) } } proceed() } else { - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) } } else { strongSelf.state = strongSelf.state.withIsEditing(false) @@ -2839,7 +2839,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate strongSelf.activateSearch() case .more: if let source = source { - strongSelf.displayMediaGalleryContextMenu(source: source) + strongSelf.displayMediaGalleryContextMenu(source: source, gesture: gesture) } case .editPhoto, .editVideo: break @@ -3120,7 +3120,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate } @objc private func editingCancelPressed() { - self.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + self.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) } private func openMessage(id: MessageId) -> Bool { @@ -4182,7 +4182,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate guard let strongSelf = self else { return } - strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.cancel, nil, nil) let text: String switch error { @@ -5526,7 +5526,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate case .avatar: self.openAvatarForEditing() case .edit: - self.headerNode.navigationButtonContainer.performAction?(.edit, nil) + self.headerNode.navigationButtonContainer.performAction?(.edit, nil, nil) case .proxy: self.controller?.push(proxySettingsController(context: self.context)) case .savedMessages: @@ -5785,7 +5785,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate items.append(ActionSheetButtonItem(title: globalTitle, color: .destructive, action: { [weak actionSheet] in actionSheet?.dismissAnimated() if let strongSelf = self { - strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil, nil) let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forEveryone).start() } })) @@ -5802,7 +5802,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate items.append(ActionSheetButtonItem(title: localOptionText, color: .destructive, action: { [weak actionSheet] in actionSheet?.dismissAnimated() if let strongSelf = self { - strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil, nil) let _ = strongSelf.context.engine.messages.deleteMessagesInteractively(messageIds: Array(messageIds), type: .forLocalPeer).start() } })) @@ -5918,7 +5918,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } strongSelf.controller?.present(UndoOverlayController(presentationData: presentationData, content: .forward(savedMessages: true, text: messageIds.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)) - strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil, nil) let _ = (enqueueMessages(account: strongSelf.context.account, peerId: peerId, messages: messageIds.map { id -> EnqueueMessage in return .forward(source: id, grouping: .auto, attributes: [], correlationId: nil) @@ -5952,7 +5952,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate }) |> deliverOnMainQueue).start(completed: { if let strongSelf = self { - strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil, nil) if let navigationController = strongSelf.controller?.navigationController as? NavigationController { let chatController = ChatControllerImpl(context: strongSelf.context, chatLocation: .peer(peerId)) @@ -6091,7 +6091,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate }), in: .current) } - private func displayMediaGalleryContextMenu(source: ContextReferenceContentNode) { + private func displayMediaGalleryContextMenu(source: ContextReferenceContentNode, gesture: ContextGesture?) { let summaryTags: [MessageTags] = [.photo, .video] let peerId = self.peerId let _ = (context.account.postbox.combinedView(keys: summaryTags.map { tag in @@ -6232,7 +6232,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate }))) } - let contextController = ContextController(account: strongSelf.context.account, presentationData: strongSelf.presentationData, source: .reference(PeerInfoContextReferenceContentSource(controller: controller, sourceNode: source)), items: .single(ContextController.Items(items: items)), gesture: nil) + let contextController = ContextController(account: strongSelf.context.account, presentationData: strongSelf.presentationData, source: .reference(PeerInfoContextReferenceContentSource(controller: controller, sourceNode: source)), items: .single(ContextController.Items(items: items)), gesture: gesture) contextController.passthroughTouchEvent = { sourceView, point in guard let strongSelf = self else { return .ignore @@ -6591,7 +6591,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate } |> deliverOnMainQueue).start(next: { messages in if let strongSelf = self, !messages.isEmpty { - strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil) + strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone, nil, nil) let shareController = ShareController(context: strongSelf.context, subject: .messages(messages.sorted(by: { lhs, rhs in return lhs.index < rhs.index From abfc1b54e58416dd06896b9e597c4a953b2127fd Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sun, 7 Nov 2021 01:50:47 +0400 Subject: [PATCH 4/4] Various Fixes --- submodules/Display/Source/DeviceMetrics.swift | 16 ++++++++++------ .../PasscodeUI/Sources/PasscodeLayout.swift | 4 ++-- .../Sources/PresentationGroupCall.swift | 9 ++------- .../TelegramEngine/Calls/GroupCalls.swift | 17 +++++++++++++++-- .../ChatInterfaceStateContextMenus.swift | 4 +--- .../Sources/NotificationItemContainerNode.swift | 9 +++++++-- 6 files changed, 37 insertions(+), 22 deletions(-) diff --git a/submodules/Display/Source/DeviceMetrics.swift b/submodules/Display/Source/DeviceMetrics.swift index 91b1eecca4..3886209b6d 100644 --- a/submodules/Display/Source/DeviceMetrics.swift +++ b/submodules/Display/Source/DeviceMetrics.swift @@ -17,6 +17,7 @@ public enum DeviceMetrics: CaseIterable, Equatable { case iPhone12 case iPhone12ProMax case iPad + case iPadMini case iPad102Inch case iPadPro10Inch case iPadPro11Inch @@ -37,6 +38,7 @@ public enum DeviceMetrics: CaseIterable, Equatable { .iPhone12, .iPhone12ProMax, .iPad, + .iPadMini, .iPad102Inch, .iPadPro10Inch, .iPadPro11Inch, @@ -111,6 +113,8 @@ public enum DeviceMetrics: CaseIterable, Equatable { return CGSize(width: 428.0, height: 926.0) case .iPad: return CGSize(width: 768.0, height: 1024.0) + case .iPadMini: + return CGSize(width: 744.0, height: 1133.0) case .iPad102Inch: return CGSize(width: 810.0, height: 1080.0) case .iPadPro10Inch: @@ -162,7 +166,7 @@ public enum DeviceMetrics: CaseIterable, Equatable { return inLandscape ? 21.0 : 34.0 case .iPadPro3rdGen, .iPadPro11Inch: return 21.0 - case .iPad, .iPadPro, .iPadPro10Inch: + case .iPad, .iPadPro, .iPadPro10Inch, .iPadMini: if let systemOnScreenNavigationHeight = systemOnScreenNavigationHeight, !systemOnScreenNavigationHeight.isZero { return 21.0 } else { @@ -192,7 +196,7 @@ public enum DeviceMetrics: CaseIterable, Equatable { switch self { case .iPhoneX, .iPhoneXSMax, .iPhoneXr, .iPhone12Mini, .iPhone12, .iPhone12ProMax: return 44.0 - case .iPadPro11Inch, .iPadPro3rdGen: + case .iPadPro11Inch, .iPadPro3rdGen, .iPadMini: return 24.0 case let .unknown(_, statusBarHeight, _): return statusBarHeight @@ -212,7 +216,7 @@ public enum DeviceMetrics: CaseIterable, Equatable { return 172.0 case .iPad, .iPad102Inch, .iPadPro10Inch: return 348.0 - case .iPadPro11Inch: + case .iPadPro11Inch, .iPadMini: return 368.0 case .iPadPro: return 421.0 @@ -235,7 +239,7 @@ public enum DeviceMetrics: CaseIterable, Equatable { return 263.0 case .iPadPro11Inch: return 283.0 - case .iPadPro: + case .iPadPro, .iPadMini: return 328.0 case .iPadPro3rdGen: return 348.0 @@ -250,7 +254,7 @@ public enum DeviceMetrics: CaseIterable, Equatable { switch self { case .iPhone4, .iPhone5, .iPhone6, .iPhone6Plus, .iPhoneX, .iPhoneXSMax, .iPhoneXr, .iPhone12Mini, .iPhone12, .iPhone12ProMax: return 37.0 - case .iPad, .iPad102Inch, .iPadPro10Inch, .iPadPro11Inch, .iPadPro, .iPadPro3rdGen: + case .iPad, .iPad102Inch, .iPadPro10Inch, .iPadPro11Inch, .iPadPro, .iPadPro3rdGen, .iPadMini: return 50.0 case .unknown: return 37.0 @@ -263,7 +267,7 @@ public enum DeviceMetrics: CaseIterable, Equatable { return 44.0 case .iPhone6Plus: return 45.0 - case .iPad, .iPad102Inch, .iPadPro10Inch, .iPadPro11Inch, .iPadPro, .iPadPro3rdGen: + case .iPad, .iPad102Inch, .iPadPro10Inch, .iPadPro11Inch, .iPadPro, .iPadPro3rdGen, .iPadMini: return 50.0 case .unknown: return 44.0 diff --git a/submodules/PasscodeUI/Sources/PasscodeLayout.swift b/submodules/PasscodeUI/Sources/PasscodeLayout.swift index e0b650f598..5b547304ab 100644 --- a/submodules/PasscodeUI/Sources/PasscodeLayout.swift +++ b/submodules/PasscodeUI/Sources/PasscodeLayout.swift @@ -89,7 +89,7 @@ struct PasscodeKeyboardLayout { self.topOffset = 329.0 self.biometricsOffset = 30.0 self.deleteOffset = 20.0 - case .iPad, .iPad102Inch, .iPadPro10Inch, .iPadPro11Inch, .iPadPro, .iPadPro3rdGen: + case .iPad, .iPad102Inch, .iPadPro10Inch, .iPadPro11Inch, .iPadPro, .iPadPro3rdGen, .iPadMini: self.buttonSize = 81.0 self.horizontalSecond = 106.0 self.horizontalThird = 212.0 @@ -159,7 +159,7 @@ public struct PasscodeLayout { self.titleOffset = 180.0 self.subtitleOffset = 0.0 self.inputFieldOffset = 226.0 - case .iPad, .iPad102Inch, .iPadPro10Inch, .iPadPro11Inch, .iPadPro, .iPadPro3rdGen: + case .iPad, .iPad102Inch, .iPadPro10Inch, .iPadPro11Inch, .iPadPro, .iPadPro3rdGen, .iPadMini: self.titleOffset = self.keyboard.topOffset - 120.0 self.subtitleOffset = -2.0 self.inputFieldOffset = self.keyboard.topOffset - 76.0 diff --git a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift index 8b33151b27..fc46e5daca 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationGroupCall.swift @@ -582,7 +582,6 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { private let screencastJoinDisposable = MetaDisposable() private let requestDisposable = MetaDisposable() private let startDisposable = MetaDisposable() - private let subscribeDisposable = MetaDisposable() private var groupCallParticipantUpdatesDisposable: Disposable? private let networkStateDisposable = MetaDisposable() @@ -937,7 +936,6 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { self.screencastJoinDisposable.dispose() self.requestDisposable.dispose() self.startDisposable.dispose() - self.subscribeDisposable.dispose() self.groupCallParticipantUpdatesDisposable?.dispose() self.leaveDisposable.dispose() self.isMutedDisposable.dispose() @@ -1311,6 +1309,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { strongSelf.stateValue.title = state.title strongSelf.stateValue.muteState = GroupCallParticipantsContext.Participant.MuteState(canUnmute: canManageCall || !state.defaultParticipantsAreMuted.isMuted, mutedByYou: false) + strongSelf.stateValue.subscribedToScheduled = state.subscribedToScheduled strongSelf.stateValue.scheduleTimestamp = strongSelf.isScheduledStarted ? nil : state.scheduleTimestamp if state.scheduleTimestamp == nil && !strongSelf.isScheduledStarted { strongSelf.updateSessionState(internalState: .active(GroupCallInfo(id: callInfo.id, accessHash: callInfo.accessHash, participantCount: state.totalCount, streamDcId: callInfo.streamDcId, title: state.title, scheduleTimestamp: nil, subscribedToScheduled: false, recordingStartTimestamp: nil, sortAscending: true, defaultParticipantsAreMuted: callInfo.defaultParticipantsAreMuted ?? state.defaultParticipantsAreMuted, isVideoEnabled: callInfo.isVideoEnabled, unmutedVideoLimit: callInfo.unmutedVideoLimit)), audioSessionControl: strongSelf.audioSessionControl) @@ -2383,11 +2382,7 @@ public final class PresentationGroupCallImpl: PresentationGroupCall { guard case let .active(callInfo) = self.internalState, callInfo.scheduleTimestamp != nil else { return } - - self.stateValue.subscribedToScheduled = subscribe - - self.subscribeDisposable.set((self.accountContext.engine.calls.toggleScheduledGroupCallSubscription(peerId: self.peerId, callId: callInfo.id, accessHash: callInfo.accessHash, subscribe: subscribe) - |> deliverOnMainQueue).start()) + self.participantsContext?.toggleScheduledSubscription(subscribe) } public func schedule(timestamp: Int32) { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Calls/GroupCalls.swift b/submodules/TelegramCore/Sources/TelegramEngine/Calls/GroupCalls.swift index f66890acae..e5f3af8f13 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Calls/GroupCalls.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Calls/GroupCalls.swift @@ -1194,6 +1194,7 @@ public final class GroupCallParticipantsContext { } private let account: Account + private let peerId: PeerId public let myPeerId: PeerId public let id: Int64 public let accessHash: Int64 @@ -1286,7 +1287,8 @@ public final class GroupCallParticipantsContext { private let updateDefaultMuteDisposable = MetaDisposable() private let resetInviteLinksDisposable = MetaDisposable() private let updateShouldBeRecordingDisposable = MetaDisposable() - + private let subscribeDisposable = MetaDisposable() + private var localVideoIsMuted: Bool? = nil private var localIsVideoPaused: Bool? = nil private var localIsPresentationPaused: Bool? = nil @@ -1298,6 +1300,7 @@ public final class GroupCallParticipantsContext { init(account: Account, peerId: PeerId, myPeerId: PeerId, id: Int64, accessHash: Int64, state: State, previousServiceState: ServiceState?) { self.account = account + self.peerId = peerId self.myPeerId = myPeerId self.id = id self.accessHash = accessHash @@ -1423,7 +1426,8 @@ public final class GroupCallParticipantsContext { self.updateDefaultMuteDisposable.dispose() self.updateShouldBeRecordingDisposable.dispose() self.activityRankResetTimer?.invalidate() - resetInviteLinksDisposable.dispose() + self.resetInviteLinksDisposable.dispose() + self.subscribeDisposable.dispose() } public func addUpdates(updates: [Update]) { @@ -2029,6 +2033,15 @@ public final class GroupCallParticipantsContext { })) } + public func toggleScheduledSubscription(_ subscribe: Bool) { + if subscribe == self.stateValue.state.subscribedToScheduled { + return + } + self.stateValue.state.subscribedToScheduled = subscribe + + self.subscribeDisposable.set(_internal_toggleScheduledGroupCallSubscription(account: self.account, peerId: self.peerId, callId: self.id, accessHash: self.accessHash, subscribe: subscribe).start()) + } + public func loadMore(token: String) { if token != self.stateValue.state.nextParticipantsFetchOffset { Logger.shared.log("GroupCallParticipantsContext", "loadMore called with an invalid token \(token) (the valid one is \(String(describing: self.stateValue.state.nextParticipantsFetchOffset)))") diff --git a/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift b/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift index 46c9fb0d25..8e365fa71a 100644 --- a/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift +++ b/submodules/TelegramUI/Sources/ChatInterfaceStateContextMenus.swift @@ -281,9 +281,7 @@ func messageMediaEditingOptions(message: Message) -> MessageMediaEditingOptions return [] } for attribute in message.attributes { - if attribute is AutoremoveTimeoutMessageAttribute { - return [] - } else if attribute is AutoclearTimeoutMessageAttribute { + if attribute is AutoclearTimeoutMessageAttribute { return [] } } diff --git a/submodules/TelegramUI/Sources/NotificationItemContainerNode.swift b/submodules/TelegramUI/Sources/NotificationItemContainerNode.swift index 8d0216626c..2d3b2b3864 100644 --- a/submodules/TelegramUI/Sources/NotificationItemContainerNode.swift +++ b/submodules/TelegramUI/Sources/NotificationItemContainerNode.swift @@ -89,8 +89,13 @@ final class NotificationItemContainerNode: ASDisplayNode { let inset: CGFloat = 8.0 var contentInsets = UIEdgeInsets(top: inset, left: inset + layout.safeInsets.left, bottom: inset, right: inset + layout.safeInsets.right) - if let statusBarHeight = layout.statusBarHeight, CGFloat(44.0).isLessThanOrEqualTo(statusBarHeight) { - contentInsets.top += 34.0 + + if let statusBarHeight = layout.statusBarHeight, statusBarHeight >= 39.0 { + if statusBarHeight >= 44.0 { + contentInsets.top += 34.0 + } else { + contentInsets.top += 29.0 + } } let containerWidth = horizontalContainerFillingSizeForLayout(layout: layout, sideInset: layout.safeInsets.left)