Various Fixes

This commit is contained in:
Ilya Laktyushin 2022-01-10 23:29:14 +03:00
parent 69b36c21f6
commit 9c42eebbbd
12 changed files with 56 additions and 21 deletions

View File

@ -1053,6 +1053,10 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
} else if let message = messages.last { } else if let message = messages.last {
var composedString: NSMutableAttributedString var composedString: NSMutableAttributedString
if let peerText = peerText {
authorAttributedString = NSAttributedString(string: peerText, font: textFont, textColor: theme.authorNameColor)
}
let entities = (message._asMessage().textEntitiesAttribute?.entities ?? []).filter { entity in let entities = (message._asMessage().textEntitiesAttribute?.entities ?? []).filter { entity in
if case .Spoiler = entity.type { if case .Spoiler = entity.type {
return true return true
@ -1062,7 +1066,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
} }
let messageString: NSAttributedString let messageString: NSAttributedString
if !message.text.isEmpty && entities.count > 0 { if !message.text.isEmpty && entities.count > 0 {
messageString = stringWithAppliedEntities(message.text, entities: entities, baseColor: theme.messageTextColor, linkColor: theme.messageTextColor, baseFont: textFont, linkFont: textFont, boldFont: textFont, italicFont: textFont, boldItalicFont: textFont, fixedFont: textFont, blockQuoteFont: textFont, underlineLinks: false) messageString = stringWithAppliedEntities(trimToLineCount(message.text, lineCount: authorAttributedString == nil ? 2 : 1), entities: entities, baseColor: theme.messageTextColor, linkColor: theme.messageTextColor, baseFont: textFont, linkFont: textFont, boldFont: textFont, italicFont: textFont, boldItalicFont: textFont, fixedFont: textFont, blockQuoteFont: textFont, underlineLinks: false)
} else { } else {
messageString = NSAttributedString(string: messageText, font: textFont, textColor: theme.messageTextColor) messageString = NSAttributedString(string: messageText, font: textFont, textColor: theme.messageTextColor)
} }
@ -1109,9 +1113,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
attributedText = composedString attributedText = composedString
if let peerText = peerText {
authorAttributedString = NSAttributedString(string: peerText, font: textFont, textColor: theme.authorNameColor)
}
var displayMediaPreviews = true var displayMediaPreviews = true
if message._asMessage().containsSecretMedia { if message._asMessage().containsSecretMedia {

View File

@ -409,8 +409,15 @@ open class NavigationController: UINavigationController, ContainableController,
let overlayContainerLayout = layout let overlayContainerLayout = layout
if let inCallStatusBar = self.inCallStatusBar { if let inCallStatusBar = self.inCallStatusBar {
var inCallStatusBarFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: max(layout.statusBarHeight ?? 0.0, max(40.0, layout.safeInsets.top)))) let isLandscape = layout.size.width > layout.size.height
if layout.deviceMetrics.hasTopNotch { var minHeight: CGFloat
if case .compact = layout.metrics.widthClass, isLandscape {
minHeight = 22.0
} else {
minHeight = 40.0
}
var inCallStatusBarFrame = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: max(layout.statusBarHeight ?? 0.0, max(minHeight, layout.safeInsets.top))))
if layout.deviceMetrics.hasTopNotch && !isLandscape {
inCallStatusBarFrame.size.height += 12.0 inCallStatusBarFrame.size.height += 12.0
} }
if inCallStatusBar.frame.isEmpty { if inCallStatusBar.frame.isEmpty {

View File

@ -200,17 +200,17 @@ private final class CallVideoNode: ASDisplayNode, PreviewVideoNode {
case .rotation90: case .rotation90:
rotationAngle = CGFloat.pi / 2.0 rotationAngle = CGFloat.pi / 2.0
case .rotation180: case .rotation180:
if isCompactLayout { // if isCompactLayout {
rotationAngle = CGFloat.pi rotationAngle = CGFloat.pi
} else { // } else {
rotationAngle = 0.0 // rotationAngle = 0.0
} // }
case .rotation270: case .rotation270:
if isCompactLayout { // if isCompactLayout {
rotationAngle = -CGFloat.pi / 2.0 rotationAngle = -CGFloat.pi / 2.0
} else { // } else {
rotationAngle = CGFloat.pi / 2.0 // rotationAngle = CGFloat.pi / 2.0
} // }
} }
var additionalAngle: CGFloat = 0.0 var additionalAngle: CGFloat = 0.0

View File

@ -253,3 +253,20 @@ public func foldLineBreaks(_ text: String) -> String {
} }
return result return result
} }
public func trimToLineCount(_ text: String, lineCount: Int) -> String {
if lineCount < 1 {
return ""
}
let lines = text.split { $0.isNewline }
var result = ""
for line in lines.prefix(lineCount) {
if !result.isEmpty {
result += "\n"
}
result += line
}
return result
}

View File

@ -8704,7 +8704,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
interfaceState = interfaceState.withUpdatedHistoryScrollState(scrollState) interfaceState = interfaceState.withUpdatedHistoryScrollState(scrollState)
} }
interfaceState = interfaceState.withUpdatedInputLanguage(self.chatDisplayNode.currentTextInputLanguage) interfaceState = interfaceState.withUpdatedInputLanguage(self.chatDisplayNode.currentTextInputLanguage)
if interfaceState.composeInputState.inputText.string.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { if interfaceState.composeInputState.inputText.string.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && interfaceState.replyMessageId == nil {
interfaceState = interfaceState.withUpdatedComposeInputState(ChatTextInputState(inputText: NSAttributedString(string: ""))) interfaceState = interfaceState.withUpdatedComposeInputState(ChatTextInputState(inputText: NSAttributedString(string: "")))
} }
let _ = ChatInterfaceState.update(engine: self.context.engine, peerId: peerId, threadId: threadId, { _ in let _ = ChatInterfaceState.update(engine: self.context.engine, peerId: peerId, threadId: threadId, { _ in

View File

@ -277,6 +277,12 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
if attribute is ViewCountMessageAttribute{ if attribute is ViewCountMessageAttribute{
return false return false
} }
if attribute is ForwardCountMessageAttribute {
return false
}
if attribute is ReactionsMessageAttribute {
return false
}
return true return true
}) })

View File

@ -876,6 +876,7 @@ class ChatMessagePollBubbleContentNode: ChatMessageBubbleContentNode {
self.votersNode.contentMode = .topLeft self.votersNode.contentMode = .topLeft
self.votersNode.contentsScale = UIScreenScale self.votersNode.contentsScale = UIScreenScale
self.votersNode.displaysAsynchronously = false self.votersNode.displaysAsynchronously = false
self.votersNode.clipsToBounds = true
var displaySolution: (() -> Void)? var displaySolution: (() -> Void)?
self.solutionButtonNode = SolutionButtonNode(pressed: { self.solutionButtonNode = SolutionButtonNode(pressed: {

View File

@ -106,7 +106,7 @@ class ChatMessageReplyInfoNode: ASDisplayNode {
} }
} }
if entities.count > 0 { if entities.count > 0 {
messageText = stringWithAppliedEntities(message.text, entities: entities, baseColor: textColor, linkColor: textColor, baseFont: textFont, linkFont: textFont, boldFont: textFont, italicFont: textFont, boldItalicFont: textFont, fixedFont: textFont, blockQuoteFont: textFont, underlineLinks: false) messageText = stringWithAppliedEntities(trimToLineCount(message.text, lineCount: 1), entities: entities, baseColor: textColor, linkColor: textColor, baseFont: textFont, linkFont: textFont, boldFont: textFont, italicFont: textFont, boldItalicFont: textFont, fixedFont: textFont, blockQuoteFont: textFont, underlineLinks: false)
} else { } else {
messageText = NSAttributedString(string: textString, font: textFont, textColor: textColor) messageText = NSAttributedString(string: textString, font: textFont, textColor: textColor)
} }

View File

@ -468,7 +468,7 @@ final class ChatPinnedMessageTitlePanelNode: ChatTitleAccessoryPanelNode {
} }
let textColor = theme.chat.inputPanel.primaryTextColor let textColor = theme.chat.inputPanel.primaryTextColor
if entities.count > 0 { if entities.count > 0 {
messageText = stringWithAppliedEntities(message.text, entities: entities, baseColor: textColor, linkColor: textColor, baseFont: textFont, linkFont: textFont, boldFont: textFont, italicFont: textFont, boldItalicFont: textFont, fixedFont: textFont, blockQuoteFont: textFont, underlineLinks: false) messageText = stringWithAppliedEntities(trimToLineCount(message.text, lineCount: 1), entities: entities, baseColor: textColor, linkColor: textColor, baseFont: textFont, linkFont: textFont, boldFont: textFont, italicFont: textFont, boldItalicFont: textFont, fixedFont: textFont, blockQuoteFont: textFont, underlineLinks: false)
} else { } else {
messageText = NSAttributedString(string: foldLineBreaks(textString), font: textFont, textColor: textColor) messageText = NSAttributedString(string: foldLineBreaks(textString), font: textFont, textColor: textColor)
} }

View File

@ -1597,9 +1597,9 @@ private class QrContentNode: ASDisplayNode, ContentNode {
self.codeTextNode.attributedText = NSAttributedString(string: self.codeTextNode.attributedText?.string ?? "", font: Font.with(size: fontSize, design: .round, weight: .bold, traits: []), textColor: .black) self.codeTextNode.attributedText = NSAttributedString(string: self.codeTextNode.attributedText?.string ?? "", font: Font.with(size: fontSize, design: .round, weight: .bold, traits: []), textColor: .black)
let codeBackgroundWidth = size.width - codeInset * 2.0 let codeBackgroundWidth = min(300.0, size.width - codeInset * 2.0)
let codeBackgroundHeight = floor(codeBackgroundWidth * 1.1) let codeBackgroundHeight = floor(codeBackgroundWidth * 1.1)
let codeBackgroundFrame = CGRect(x: codeInset, y: topInset + floor((size.height - bottomInset - codeBackgroundHeight) / 2.0), width: codeBackgroundWidth, height: codeBackgroundHeight) let codeBackgroundFrame = CGRect(x: floor((size.width - codeBackgroundWidth) / 2.0), y: topInset + floor((size.height - bottomInset - codeBackgroundHeight) / 2.0), width: codeBackgroundWidth, height: codeBackgroundHeight)
transition.updateFrame(node: self.codeBackgroundNode, frame: codeBackgroundFrame) transition.updateFrame(node: self.codeBackgroundNode, frame: codeBackgroundFrame)
transition.updateFrame(node: self.codeForegroundNode, frame: codeBackgroundFrame) transition.updateFrame(node: self.codeForegroundNode, frame: codeBackgroundFrame)
transition.updateFrame(node: self.codeMaskNode, frame: CGRect(origin: CGPoint(), size: codeBackgroundFrame.size)) transition.updateFrame(node: self.codeMaskNode, frame: CGRect(origin: CGPoint(), size: codeBackgroundFrame.size))

View File

@ -135,7 +135,7 @@ final class ReplyAccessoryPanelNode: AccessoryPanelNode {
} }
let textColor = strongSelf.theme.chat.inputPanel.primaryTextColor let textColor = strongSelf.theme.chat.inputPanel.primaryTextColor
if entities.count > 0 { if entities.count > 0 {
messageText = stringWithAppliedEntities(message.text, entities: entities, baseColor: textColor, linkColor: textColor, baseFont: textFont, linkFont: textFont, boldFont: textFont, italicFont: textFont, boldItalicFont: textFont, fixedFont: textFont, blockQuoteFont: textFont, underlineLinks: false) messageText = stringWithAppliedEntities(trimToLineCount(message.text, lineCount: 1), entities: entities, baseColor: textColor, linkColor: textColor, baseFont: textFont, linkFont: textFont, boldFont: textFont, italicFont: textFont, boldItalicFont: textFont, fixedFont: textFont, blockQuoteFont: textFont, underlineLinks: false)
} else { } else {
messageText = NSAttributedString(string: text, font: textFont, textColor: isMedia ? strongSelf.theme.chat.inputPanel.secondaryTextColor : strongSelf.theme.chat.inputPanel.primaryTextColor) messageText = NSAttributedString(string: text, font: textFont, textColor: isMedia ? strongSelf.theme.chat.inputPanel.secondaryTextColor : strongSelf.theme.chat.inputPanel.primaryTextColor)
} }

View File

@ -69,7 +69,9 @@ public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEnti
if nsString == nil { if nsString == nil {
nsString = text as NSString nsString = text as NSString
} }
if range.location + range.length > stringLength { if range.location > stringLength {
continue
} else if range.location + range.length > stringLength {
range.location = max(0, stringLength - range.length) range.location = max(0, stringLength - range.length)
range.length = stringLength - range.location range.length = stringLength - range.location
} }