mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Various Improvements
This commit is contained in:
@@ -13,23 +13,24 @@ import AlertUI
|
||||
import PresentationDataUtils
|
||||
import TextFormat
|
||||
import Markdown
|
||||
import TelegramNotices
|
||||
|
||||
func textStringForForwardedMessage(_ message: Message, strings: PresentationStrings) -> (String, Bool) {
|
||||
for media in message.media {
|
||||
switch media {
|
||||
case _ as TelegramMediaImage:
|
||||
return (strings.ForwardedPhotos(1), true)
|
||||
return (strings.Message_Photo, true)
|
||||
case let file as TelegramMediaFile:
|
||||
var fileName: String = strings.ForwardedFiles(1)
|
||||
var fileName: String = strings.Message_File
|
||||
for attribute in file.attributes {
|
||||
switch attribute {
|
||||
case .Sticker:
|
||||
return (strings.ForwardedStickers(1), true)
|
||||
return (strings.Message_Sticker, true)
|
||||
case let .FileName(name):
|
||||
fileName = name
|
||||
case let .Audio(isVoice, _, title, performer, _):
|
||||
if isVoice {
|
||||
return (strings.ForwardedAudios(1), true)
|
||||
return (strings.Message_Audio, true)
|
||||
} else {
|
||||
if let title = title, let performer = performer, !title.isEmpty, !performer.isEmpty {
|
||||
return (title + " — " + performer, true)
|
||||
@@ -38,29 +39,29 @@ func textStringForForwardedMessage(_ message: Message, strings: PresentationStri
|
||||
} else if let performer = performer, !performer.isEmpty {
|
||||
return (performer, true)
|
||||
} else {
|
||||
return (strings.ForwardedAudios(1), true)
|
||||
return (strings.Message_Audio, true)
|
||||
}
|
||||
}
|
||||
case .Video:
|
||||
if file.isAnimated {
|
||||
return (strings.ForwardedGifs(1), true)
|
||||
return (strings.Message_Animation, true)
|
||||
} else {
|
||||
return (strings.ForwardedVideos(1), true)
|
||||
return (strings.Message_Video, true)
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
if file.isAnimatedSticker {
|
||||
return (strings.ForwardedStickers(1), true)
|
||||
return (strings.Message_Sticker, true)
|
||||
}
|
||||
return (fileName, true)
|
||||
case _ as TelegramMediaContact:
|
||||
return (strings.ForwardedContacts(1), true)
|
||||
return (strings.Message_Contact, true)
|
||||
case let game as TelegramMediaGame:
|
||||
return (game.title, true)
|
||||
case _ as TelegramMediaMap:
|
||||
return (strings.ForwardedLocations(1), true)
|
||||
return (strings.Message_Location, true)
|
||||
case _ as TelegramMediaAction:
|
||||
return ("", true)
|
||||
case _ as TelegramMediaPoll:
|
||||
@@ -79,11 +80,13 @@ func textStringForForwardedMessage(_ message: Message, strings: PresentationStri
|
||||
final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
private let messageDisposable = MetaDisposable()
|
||||
let messageIds: [MessageId]
|
||||
private var messages: [Message] = []
|
||||
private var authors: String?
|
||||
private var sourcePeer: (isPersonal: Bool, displayTitle: String)?
|
||||
|
||||
let closeButton: ASButtonNode
|
||||
let closeButton: HighlightableButtonNode
|
||||
let lineNode: ASImageNode
|
||||
let iconNode: ASImageNode
|
||||
let titleNode: ImmediateTextNode
|
||||
let textNode: ImmediateTextNode
|
||||
|
||||
@@ -94,20 +97,20 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
var strings: PresentationStrings
|
||||
var fontSize: PresentationFontSize
|
||||
var nameDisplayOrder: PresentationPersonNameOrder
|
||||
var hideSendersNames: Bool
|
||||
var forwardOptionsState: ChatInterfaceForwardOptionsState?
|
||||
|
||||
private var validLayout: (size: CGSize, interfaceState: ChatPresentationInterfaceState)?
|
||||
|
||||
init(context: AccountContext, messageIds: [MessageId], theme: PresentationTheme, strings: PresentationStrings, fontSize: PresentationFontSize, nameDisplayOrder: PresentationPersonNameOrder, hideSendersNames: Bool) {
|
||||
init(context: AccountContext, messageIds: [MessageId], theme: PresentationTheme, strings: PresentationStrings, fontSize: PresentationFontSize, nameDisplayOrder: PresentationPersonNameOrder, forwardOptionsState: ChatInterfaceForwardOptionsState?) {
|
||||
self.context = context
|
||||
self.messageIds = messageIds
|
||||
self.theme = theme
|
||||
self.strings = strings
|
||||
self.fontSize = fontSize
|
||||
self.nameDisplayOrder = nameDisplayOrder
|
||||
self.hideSendersNames = hideSendersNames
|
||||
self.forwardOptionsState = forwardOptionsState
|
||||
|
||||
self.closeButton = ASButtonNode()
|
||||
self.closeButton = HighlightableButtonNode()
|
||||
self.closeButton.accessibilityLabel = strings.VoiceOver_DiscardPreparedContent
|
||||
self.closeButton.setImage(PresentationResourcesChat.chatInputPanelCloseIconImage(theme), for: [])
|
||||
self.closeButton.hitTestSlop = UIEdgeInsets(top: -8.0, left: -8.0, bottom: -8.0, right: -8.0)
|
||||
@@ -118,6 +121,11 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
self.lineNode.displaysAsynchronously = false
|
||||
self.lineNode.image = PresentationResourcesChat.chatInputPanelVerticalSeparatorLineImage(theme)
|
||||
|
||||
self.iconNode = ASImageNode()
|
||||
self.iconNode.displayWithoutProcessing = false
|
||||
self.iconNode.displaysAsynchronously = false
|
||||
self.iconNode.image = PresentationResourcesChat.chatInputPanelForwardIconImage(theme)
|
||||
|
||||
self.titleNode = ImmediateTextNode()
|
||||
self.titleNode.maximumNumberOfLines = 1
|
||||
self.titleNode.displaysAsynchronously = false
|
||||
@@ -134,6 +142,7 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
self.addSubnode(self.closeButton)
|
||||
|
||||
self.addSubnode(self.lineNode)
|
||||
self.addSubnode(self.iconNode)
|
||||
self.addSubnode(self.titleNode)
|
||||
self.addSubnode(self.textNode)
|
||||
self.addSubnode(self.actionArea)
|
||||
@@ -143,6 +152,7 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
if let strongSelf = self {
|
||||
var authors = ""
|
||||
var uniquePeerIds = Set<PeerId>()
|
||||
var title = ""
|
||||
var text = ""
|
||||
var sourcePeer: (Bool, String)?
|
||||
for message in messages {
|
||||
@@ -157,22 +167,21 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
sourcePeer = (peer.id.namespace == Namespaces.Peer.CloudUser, peer.displayTitle(strings: strongSelf.strings, displayOrder: strongSelf.nameDisplayOrder))
|
||||
}
|
||||
}
|
||||
|
||||
if messages.count == 1 {
|
||||
title = strongSelf.strings.Conversation_ForwardOptions_ForwardTitleSingle
|
||||
let (string, _) = textStringForForwardedMessage(messages[0], strings: strings)
|
||||
text = string
|
||||
text = "\(authors): \(string)"
|
||||
} else {
|
||||
text = strings.ForwardedMessages(Int32(messages.count))
|
||||
title = strongSelf.strings.Conversation_ForwardOptions_ForwardTitle(Int32(messages.count))
|
||||
text = "From \(authors)"
|
||||
}
|
||||
|
||||
strongSelf.messages = messages
|
||||
strongSelf.sourcePeer = sourcePeer
|
||||
strongSelf.authors = authors
|
||||
|
||||
if strongSelf.hideSendersNames {
|
||||
strongSelf.titleNode.attributedText = NSAttributedString(string: strongSelf.strings.Conversation_ForwardOptions_You, font: Font.medium(15.0), textColor: strongSelf.theme.chat.inputPanel.panelControlAccentColor)
|
||||
} else {
|
||||
strongSelf.titleNode.attributedText = NSAttributedString(string: authors, font: Font.medium(15.0), textColor: strongSelf.theme.chat.inputPanel.panelControlAccentColor)
|
||||
}
|
||||
|
||||
strongSelf.titleNode.attributedText = NSAttributedString(string: title, font: Font.medium(15.0), textColor: strongSelf.theme.chat.inputPanel.panelControlAccentColor)
|
||||
strongSelf.textNode.attributedText = NSAttributedString(string: text, font: Font.regular(15.0), textColor: strongSelf.theme.chat.inputPanel.secondaryTextColor)
|
||||
|
||||
let headerString: String
|
||||
@@ -186,6 +195,30 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
if let (size, interfaceState) = strongSelf.validLayout {
|
||||
strongSelf.updateState(size: size, interfaceState: interfaceState)
|
||||
}
|
||||
|
||||
let _ = (ApplicationSpecificNotice.getChatForwardOptionsTip(accountManager: strongSelf.context.sharedContext.accountManager)
|
||||
|> deliverOnMainQueue).start(next: { [weak self] count in
|
||||
if let strongSelf = self, count < 3 {
|
||||
Queue.mainQueue().after(3.0) {
|
||||
if let snapshotView = strongSelf.textNode.view.snapshotContentTree() {
|
||||
strongSelf.textNode.attributedText = NSAttributedString(string: strongSelf.strings.Conversation_ForwardOptions_TapForOptions, font: Font.regular(15.0), textColor: strongSelf.theme.chat.inputPanel.secondaryTextColor)
|
||||
|
||||
strongSelf.view.addSubview(snapshotView)
|
||||
|
||||
if let (size, interfaceState) = strongSelf.validLayout {
|
||||
strongSelf.updateState(size: size, interfaceState: interfaceState)
|
||||
}
|
||||
|
||||
strongSelf.textNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.3)
|
||||
snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false, completion: { [weak snapshotView] _ in
|
||||
snapshotView?.removeFromSuperview()
|
||||
})
|
||||
}
|
||||
|
||||
let _ = ApplicationSpecificNotice.incrementChatForwardOptionsTip(accountManager: strongSelf.context.sharedContext.accountManager).start()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
@@ -201,29 +234,39 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
}
|
||||
|
||||
override func updateThemeAndStrings(theme: PresentationTheme, strings: PresentationStrings) {
|
||||
self.updateThemeAndStrings(theme: theme, strings: strings, hideSendersNames: self.hideSendersNames)
|
||||
self.updateThemeAndStrings(theme: theme, strings: strings, forwardOptionsState: self.forwardOptionsState)
|
||||
}
|
||||
|
||||
func updateThemeAndStrings(theme: PresentationTheme, strings: PresentationStrings, hideSendersNames: Bool) {
|
||||
if self.theme !== theme || self.strings !== strings || self.hideSendersNames != hideSendersNames {
|
||||
func updateThemeAndStrings(theme: PresentationTheme, strings: PresentationStrings, forwardOptionsState: ChatInterfaceForwardOptionsState?, force: Bool = false) {
|
||||
if force || self.theme !== theme || self.strings !== strings || self.forwardOptionsState != forwardOptionsState {
|
||||
self.theme = theme
|
||||
self.strings = strings
|
||||
self.hideSendersNames = hideSendersNames
|
||||
self.forwardOptionsState = forwardOptionsState
|
||||
|
||||
self.closeButton.setImage(PresentationResourcesChat.chatInputPanelCloseIconImage(theme), for: [])
|
||||
|
||||
self.lineNode.image = PresentationResourcesChat.chatInputPanelVerticalSeparatorLineImage(theme)
|
||||
|
||||
if hideSendersNames {
|
||||
self.titleNode.attributedText = NSAttributedString(string: strings.Conversation_ForwardOptions_You, font: Font.medium(15.0), textColor: self.theme.chat.inputPanel.panelControlAccentColor)
|
||||
} else if let authors = self.authors {
|
||||
self.titleNode.attributedText = NSAttributedString(string: authors, font: Font.medium(15.0), textColor: self.theme.chat.inputPanel.panelControlAccentColor)
|
||||
if self.theme !== theme {
|
||||
self.closeButton.setImage(PresentationResourcesChat.chatInputPanelCloseIconImage(theme), for: [])
|
||||
self.lineNode.image = PresentationResourcesChat.chatInputPanelVerticalSeparatorLineImage(theme)
|
||||
self.iconNode.image = PresentationResourcesChat.chatInputPanelForwardIconImage(theme)
|
||||
}
|
||||
|
||||
if let text = self.textNode.attributedText?.string {
|
||||
self.textNode.attributedText = NSAttributedString(string: text, font: Font.regular(15.0), textColor: self.theme.chat.inputPanel.secondaryTextColor)
|
||||
let deselectedIds = forwardOptionsState?.deselectedIds ?? Set()
|
||||
let filteredMessages = self.messages.filter { !deselectedIds.contains($0.id) }
|
||||
|
||||
var title = ""
|
||||
var text = ""
|
||||
if filteredMessages.count == 1, let message = filteredMessages.first {
|
||||
title = self.strings.Conversation_ForwardOptions_ForwardTitleSingle
|
||||
let (string, _) = textStringForForwardedMessage(message, strings: strings)
|
||||
text = "\(self.authors ?? ""): \(string)"
|
||||
} else {
|
||||
title = self.strings.Conversation_ForwardOptions_ForwardTitle(Int32(filteredMessages.count))
|
||||
text = "From \(self.authors ?? "")"
|
||||
}
|
||||
|
||||
self.titleNode.attributedText = NSAttributedString(string: title, font: Font.medium(15.0), textColor: self.theme.chat.inputPanel.panelControlAccentColor)
|
||||
|
||||
self.textNode.attributedText = NSAttributedString(string: text, font: Font.regular(15.0), textColor: self.theme.chat.inputPanel.secondaryTextColor)
|
||||
|
||||
if let (size, interfaceState) = self.validLayout {
|
||||
self.updateState(size: size, interfaceState: interfaceState)
|
||||
}
|
||||
@@ -245,7 +288,7 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
let textRightInset: CGFloat = 20.0
|
||||
|
||||
let closeButtonSize = CGSize(width: 44.0, height: bounds.height)
|
||||
let closeButtonFrame = CGRect(origin: CGPoint(x: bounds.width - rightInset - closeButtonSize.width + 12.0, y: 2.0), size: closeButtonSize)
|
||||
let closeButtonFrame = CGRect(origin: CGPoint(x: bounds.width - closeButtonSize.width, y: 2.0), size: closeButtonSize)
|
||||
self.closeButton.frame = closeButtonFrame
|
||||
self.closeButton.isHidden = interfaceState.renderedPeer == nil
|
||||
|
||||
@@ -253,6 +296,10 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
|
||||
self.lineNode.frame = CGRect(origin: CGPoint(x: leftInset, y: 8.0), size: CGSize(width: 2.0, height: bounds.size.height - 10.0))
|
||||
|
||||
if let icon = self.iconNode.image {
|
||||
self.iconNode.frame = CGRect(origin: CGPoint(x: 7.0, y: 9.0), size: icon.size)
|
||||
}
|
||||
|
||||
let titleSize = self.titleNode.updateLayout(CGSize(width: bounds.size.width - leftInset - textLineInset - rightInset - textRightInset, height: bounds.size.height))
|
||||
self.titleNode.frame = CGRect(origin: CGPoint(x: leftInset + textLineInset, y: 7.0), size: titleSize)
|
||||
|
||||
@@ -276,11 +323,14 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
let title = NSAttributedString(string: self.strings.Conversation_ForwardOptions_Title(messageCount), font: Font.semibold(floor(self.fontSize.baseDisplaySize)), textColor: self.theme.actionSheet.primaryTextColor, paragraphAlignment: .center)
|
||||
let text = addAttributesToStringWithRanges(string._tuple, body: body, argumentAttributes: [0: bold, 1: bold], textAlignment: .center)
|
||||
|
||||
let alertController = richTextAlertController(context: self.context, title: title, text: text, actions: [TextAlertAction(type: .genericAction, title: self.strings.Conversation_ForwardOptions_ForwardToAnotherChat, action: { [weak self] in
|
||||
self?.interfaceInteraction?.forwardCurrentForwardMessages()
|
||||
}), TextAlertAction(type: .genericAction, title: self.hideSendersNames ? self.strings.Conversation_ForwardOptions_ShowSendersNames : self.strings.Conversation_ForwardOptions_HideSendersNames, action: { [weak self] in
|
||||
let alertController = richTextAlertController(context: self.context, title: title, text: text, actions: [TextAlertAction(type: .genericAction, title: self.strings.Conversation_ForwardOptions_ShowOptions, action: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
strongSelf.interfaceInteraction?.updateForwardMessageHideSendersNames(!strongSelf.hideSendersNames)
|
||||
strongSelf.interfaceInteraction?.presentForwardOptions(strongSelf)
|
||||
Queue.mainQueue().after(1.5) {
|
||||
strongSelf.updateThemeAndStrings(theme: strongSelf.theme, strings: strongSelf.strings, forwardOptionsState: strongSelf.forwardOptionsState, force: true)
|
||||
}
|
||||
|
||||
let _ = ApplicationSpecificNotice.incrementChatForwardOptionsTip(accountManager: strongSelf.context.sharedContext.accountManager, count: 3).start()
|
||||
}
|
||||
}), TextAlertAction(type: .destructiveAction, title: self.strings.Conversation_ForwardOptions_CancelForwarding, action: { [weak self] in
|
||||
self?.dismiss?()
|
||||
@@ -290,11 +340,12 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
|
||||
|
||||
@objc func tapGesture(_ recognizer: UITapGestureRecognizer) {
|
||||
if case .ended = recognizer.state {
|
||||
if self.closeButton.isHidden {
|
||||
self.interfaceInteraction?.updateForwardMessageHideSendersNames(!self.hideSendersNames)
|
||||
} else {
|
||||
self.closePressed()
|
||||
self.interfaceInteraction?.presentForwardOptions(self)
|
||||
Queue.mainQueue().after(1.5) {
|
||||
self.updateThemeAndStrings(theme: self.theme, strings: self.strings, forwardOptionsState: self.forwardOptionsState, force: true)
|
||||
}
|
||||
|
||||
let _ = ApplicationSpecificNotice.incrementChatForwardOptionsTip(accountManager: self.context.sharedContext.accountManager, count: 3).start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user