mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2024-12-25 08:21:40 +01:00
feat: add timestamp updater
This commit is contained in:
parent
69a7517fde
commit
6f8666aaa8
@ -18,6 +18,8 @@ protocol StatusNodeDelegate: AnyObject {
|
||||
final class StatusNode: ASCellNode {
|
||||
|
||||
var disposeBag = Set<AnyCancellable>()
|
||||
var timestamp: Date
|
||||
var timestampSubscription: AnyCancellable?
|
||||
weak var delegate: StatusNodeDelegate? // needs assign on main queue
|
||||
|
||||
static let avatarImageSize = CGSize(width: 42, height: 42)
|
||||
@ -61,6 +63,7 @@ final class StatusNode: ASCellNode {
|
||||
}()
|
||||
|
||||
init(status: Status) {
|
||||
timestamp = (status.reblog ?? status).createdAt
|
||||
super.init()
|
||||
|
||||
automaticallyManagesSubnodes = true
|
||||
@ -78,23 +81,10 @@ final class StatusNode: ASCellNode {
|
||||
.font: UIFont.systemFont(ofSize: 13, weight: .regular)
|
||||
])
|
||||
// set date
|
||||
let createdAt = (status.reblog ?? status).createdAt
|
||||
dateTextNode.attributedText = NSAttributedString(string: createdAt.slowedTimeAgoSinceNow, attributes: [
|
||||
dateTextNode.attributedText = NSAttributedString(string: timestamp.slowedTimeAgoSinceNow, attributes: [
|
||||
.foregroundColor: Asset.Colors.Label.secondary.color,
|
||||
.font: UIFont.systemFont(ofSize: 13, weight: .regular)
|
||||
])
|
||||
// RunLoop.main.perform { [weak self] in
|
||||
// guard let self = self else { return }
|
||||
// AppContext.shared.timestampUpdatePublisher
|
||||
// .sink { [weak self] _ in
|
||||
// guard let self = self else { return }
|
||||
// self.dateTextNode.attributedText = NSAttributedString(string: createdAt.slowedTimeAgoSinceNow, attributes: [
|
||||
// .foregroundColor: Asset.Colors.Label.secondary.color,
|
||||
// .font: UIFont.systemFont(ofSize: 13, weight: .regular)
|
||||
// ])
|
||||
// }
|
||||
// .store(in: &self.disposeBag)
|
||||
// }
|
||||
|
||||
usernameTextNode.attributedText = NSAttributedString(string: "@" + status.author.acct, attributes: [
|
||||
.foregroundColor: Asset.Colors.Label.secondary.color,
|
||||
@ -113,6 +103,15 @@ final class StatusNode: ASCellNode {
|
||||
override func didEnterDisplayState() {
|
||||
super.didEnterDisplayState()
|
||||
|
||||
timestampSubscription = AppContext.shared.timestampUpdatePublisher
|
||||
.sink { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
self.dateTextNode.attributedText = NSAttributedString(string: self.timestamp.slowedTimeAgoSinceNow, attributes: [
|
||||
.foregroundColor: Asset.Colors.Label.secondary.color,
|
||||
.font: UIFont.systemFont(ofSize: 13, weight: .regular)
|
||||
])
|
||||
}
|
||||
|
||||
statusContentTextNode.textView.isEditable = false
|
||||
statusContentTextNode.textView.textDragInteraction?.isEnabled = false
|
||||
statusContentTextNode.textView.linkTextAttributes = [
|
||||
@ -120,6 +119,11 @@ final class StatusNode: ASCellNode {
|
||||
]
|
||||
}
|
||||
|
||||
override func didExitVisibleState() {
|
||||
super.didExitVisibleState()
|
||||
timestampSubscription = nil
|
||||
}
|
||||
|
||||
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
|
||||
let headerStack = ASStackLayoutSpec.horizontal()
|
||||
headerStack.alignItems = .center
|
||||
|
Loading…
Reference in New Issue
Block a user