mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
no message
This commit is contained in:
@@ -4,19 +4,88 @@ import Display
|
||||
import Postbox
|
||||
import TelegramCore
|
||||
import SwiftSignalKit
|
||||
import TelegramLegacyComponents
|
||||
|
||||
final class ChatTitleView: UIView {
|
||||
private let titleNode: ASTextNode
|
||||
private let infoNode: ASTextNode
|
||||
private let typingNode: ASTextNode
|
||||
private var typingIndicator: TGModernConversationTitleActivityIndicator?
|
||||
private let button: HighlightTrackingButton
|
||||
|
||||
private var presenceManager: PeerPresenceStatusManager?
|
||||
|
||||
var inputActivities: (PeerId, [(Peer, PeerInputActivity)])? {
|
||||
didSet {
|
||||
if let (peerId, inputActivities) = self.inputActivities, !inputActivities.isEmpty {
|
||||
self.typingNode.isHidden = false
|
||||
self.infoNode.isHidden = true
|
||||
var stringValue = ""
|
||||
var first = true
|
||||
var mergedActivity = inputActivities[0].1
|
||||
for (_, activity) in inputActivities {
|
||||
if activity != mergedActivity {
|
||||
mergedActivity = .typingText
|
||||
break
|
||||
}
|
||||
}
|
||||
if peerId.namespace == Namespaces.Peer.CloudUser || peerId.namespace == Namespaces.Peer.SecretChat {
|
||||
switch mergedActivity {
|
||||
case .recordingVoice:
|
||||
stringValue = "recording audio"
|
||||
default:
|
||||
stringValue = "typing..."
|
||||
}
|
||||
} else {
|
||||
for (peer, _) in inputActivities {
|
||||
let title = peer.compactDisplayTitle
|
||||
if !title.isEmpty {
|
||||
if first {
|
||||
first = false
|
||||
} else {
|
||||
stringValue += ", "
|
||||
}
|
||||
stringValue += title
|
||||
}
|
||||
}
|
||||
}
|
||||
let string = NSAttributedString(string: stringValue, font: Font.regular(13.0), textColor: UIColor(0x007ee5))
|
||||
if self.typingNode.attributedText == nil || !self.typingNode.attributedText!.isEqual(to: string) {
|
||||
self.typingNode.attributedText = string
|
||||
self.setNeedsLayout()
|
||||
}
|
||||
if self.typingIndicator == nil {
|
||||
let typingIndicator = TGModernConversationTitleActivityIndicator()
|
||||
self.addSubview(typingIndicator)
|
||||
self.typingIndicator = typingIndicator
|
||||
}
|
||||
switch mergedActivity {
|
||||
case .typingText:
|
||||
self.typingIndicator?.setTyping()
|
||||
case .recordingVoice:
|
||||
self.typingIndicator?.setAudioRecording()
|
||||
case .uploadingFile:
|
||||
self.typingIndicator?.setUploading()
|
||||
case .playingGame:
|
||||
self.typingIndicator?.setPlaying()
|
||||
}
|
||||
} else {
|
||||
self.typingNode.isHidden = true
|
||||
self.infoNode.isHidden = false
|
||||
self.typingNode.attributedText = nil
|
||||
if let typingIndicator = self.typingIndicator {
|
||||
typingIndicator.removeFromSuperview()
|
||||
self.typingIndicator = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var pressed: (() -> Void)?
|
||||
|
||||
var peerView: PeerView? {
|
||||
didSet {
|
||||
if let peerView = self.peerView, let peer = peerView.peers[peerView.peerId] {
|
||||
if let peerView = self.peerView, let peer = peerViewMainPeer(peerView) {
|
||||
let string = NSAttributedString(string: peer.displayTitle, font: Font.medium(17.0), textColor: UIColor.black)
|
||||
|
||||
if self.titleNode.attributedText == nil || !self.titleNode.attributedText!.isEqual(to: string) {
|
||||
@@ -31,7 +100,7 @@ final class ChatTitleView: UIView {
|
||||
|
||||
private func updateStatus() {
|
||||
var shouldUpdateLayout = false
|
||||
if let peerView = self.peerView, let peer = peerView.peers[peerView.peerId] {
|
||||
if let peerView = self.peerView, let peer = peerViewMainPeer(peerView) {
|
||||
if let user = peer as? TelegramUser {
|
||||
if let _ = user.botInfo {
|
||||
let string = NSAttributedString(string: "bot", font: Font.regular(13.0), textColor: UIColor(0x787878))
|
||||
@@ -39,7 +108,7 @@ final class ChatTitleView: UIView {
|
||||
self.infoNode.attributedText = string
|
||||
shouldUpdateLayout = true
|
||||
}
|
||||
} else if let presence = peerView.peerPresences[peerView.peerId] as? TelegramUserPresence {
|
||||
} else if let peer = peerViewMainPeer(peerView), let presence = peerView.peerPresences[peer.id] as? TelegramUserPresence {
|
||||
let timestamp = CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970
|
||||
let (string, activity) = stringAndActivityForUserPresence(presence, relativeTo: Int32(timestamp))
|
||||
let attributedString = NSAttributedString(string: string, font: Font.regular(13.0), textColor: activity ? UIColor(0x007ee5) : UIColor(0x787878))
|
||||
@@ -131,12 +200,19 @@ final class ChatTitleView: UIView {
|
||||
self.infoNode.truncationMode = .byTruncatingTail
|
||||
self.infoNode.isOpaque = false
|
||||
|
||||
self.typingNode = ASTextNode()
|
||||
self.typingNode.displaysAsynchronously = false
|
||||
self.typingNode.maximumNumberOfLines = 1
|
||||
self.typingNode.truncationMode = .byTruncatingTail
|
||||
self.typingNode.isOpaque = false
|
||||
|
||||
self.button = HighlightTrackingButton()
|
||||
|
||||
super.init(frame: frame)
|
||||
|
||||
self.addSubnode(self.titleNode)
|
||||
self.addSubnode(self.infoNode)
|
||||
self.addSubnode(self.typingNode)
|
||||
self.addSubview(self.button)
|
||||
|
||||
self.presenceManager = PeerPresenceStatusManager(update: { [weak self] in
|
||||
@@ -149,13 +225,17 @@ final class ChatTitleView: UIView {
|
||||
if highlighted {
|
||||
strongSelf.titleNode.layer.removeAnimation(forKey: "opacity")
|
||||
strongSelf.infoNode.layer.removeAnimation(forKey: "opacity")
|
||||
strongSelf.typingNode.layer.removeAnimation(forKey: "opacity")
|
||||
strongSelf.titleNode.alpha = 0.4
|
||||
strongSelf.infoNode.alpha = 0.4
|
||||
strongSelf.typingNode.alpha = 0.4
|
||||
} else {
|
||||
strongSelf.titleNode.alpha = 1.0
|
||||
strongSelf.infoNode.alpha = 1.0
|
||||
strongSelf.typingNode.alpha = 1.0
|
||||
strongSelf.titleNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
|
||||
strongSelf.infoNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
|
||||
strongSelf.typingNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,21 +255,29 @@ final class ChatTitleView: UIView {
|
||||
if size.height > 40.0 {
|
||||
let titleSize = self.titleNode.measure(size)
|
||||
let infoSize = self.infoNode.measure(size)
|
||||
let typingSize = self.typingNode.measure(size)
|
||||
let titleInfoSpacing: CGFloat = 0.0
|
||||
|
||||
let combinedHeight = titleSize.height + infoSize.height + titleInfoSpacing
|
||||
|
||||
self.titleNode.frame = CGRect(origin: CGPoint(x: floor((size.width - titleSize.width) / 2.0), y: floor((size.height - combinedHeight) / 2.0)), size: titleSize)
|
||||
self.infoNode.frame = CGRect(origin: CGPoint(x: floor((size.width - infoSize.width) / 2.0), y: floor((size.height - combinedHeight) / 2.0) + titleSize.height + titleInfoSpacing), size: infoSize)
|
||||
self.typingNode.frame = CGRect(origin: CGPoint(x: floor((size.width - typingSize.width + 14.0) / 2.0), y: floor((size.height - combinedHeight) / 2.0) + titleSize.height + titleInfoSpacing), size: typingSize)
|
||||
|
||||
if let typingIndicator = self.typingIndicator {
|
||||
typingIndicator.frame = CGRect(x: self.typingNode.frame.origin.x - 24.0, y: self.typingNode.frame.origin.y, width: 24.0, height: 16.0)
|
||||
}
|
||||
} else {
|
||||
let titleSize = self.titleNode.measure(CGSize(width: floor(size.width / 2.0), height: size.height))
|
||||
let infoSize = self.infoNode.measure(CGSize(width: floor(size.width / 2.0), height: size.height))
|
||||
let typingSize = self.typingNode.measure(CGSize(width: floor(size.width / 2.0), height: size.height))
|
||||
|
||||
let titleInfoSpacing: CGFloat = 8.0
|
||||
let combinedWidth = titleSize.width + infoSize.width + titleInfoSpacing
|
||||
|
||||
self.titleNode.frame = CGRect(origin: CGPoint(x: floor((size.width - combinedWidth) / 2.0), y: floor((size.height - titleSize.height) / 2.0)), size: titleSize)
|
||||
self.infoNode.frame = CGRect(origin: CGPoint(x: floor((size.width - combinedWidth) / 2.0 + titleSize.width + titleInfoSpacing), y: floor((size.height - infoSize.height) / 2.0)), size: infoSize)
|
||||
self.typingNode.frame = CGRect(origin: CGPoint(x: floor((size.width - combinedWidth) / 2.0 + titleSize.width + titleInfoSpacing), y: floor((size.height - typingSize.height) / 2.0)), size: typingSize)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user