diff --git a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift index 1febc504..e32e9cdf 100644 --- a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift +++ b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift @@ -94,7 +94,7 @@ class ActionNotificationGroupTableViewCell: UITableViewCell { func updateTimestamp() { guard let id = group.notificationIDs.first, let notification = MastodonCache.notification(for: id) else { - fatalError("Missing cached status") + fatalError("Missing cached notification") } timestampLabel.text = notification.createdAt.timeAgoString() diff --git a/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift b/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift index eb90024f..ab079911 100644 --- a/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift +++ b/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift @@ -14,10 +14,13 @@ class FollowNotificationGroupTableViewCell: UITableViewCell { var delegate: TuskerNavigationDelegate? @IBOutlet weak var avatarStackView: UIStackView! + @IBOutlet weak var timestampLabel: UILabel! @IBOutlet weak var actionLabel: UILabel! var group: NotificationGroup! + var updateTimestampWorkItem: DispatchWorkItem? + override func awakeFromNib() { super.awakeFromNib() @@ -39,6 +42,7 @@ class FollowNotificationGroupTableViewCell: UITableViewCell { let people = group.notificationIDs.compactMap(MastodonCache.notification(for:)).map { $0.account } updateActionLabel(people: people) + updateTimestamp() avatarStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } for account in people { @@ -74,5 +78,39 @@ class FollowNotificationGroupTableViewCell: UITableViewCell { } actionLabel.text = "Followed by \(peopleStr)" } - + + func updateTimestamp() { + guard let id = group.notificationIDs.first, + let notification = MastodonCache.notification(for: id) else { + fatalError("Missing cached notification") + } + + timestampLabel.text = notification.createdAt.timeAgoString() + + let delay: DispatchTimeInterval? + switch notification.createdAt.timeAgo().1 { + case .second: + delay = .seconds(10) + case .minute: + delay = .seconds(60) + default: + delay = nil + } + if let delay = delay { + updateTimestampWorkItem = DispatchWorkItem { + self.updateTimestamp() + } + DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: updateTimestampWorkItem!) + } else { + updateTimestampWorkItem = nil + } + } + + override func prepareForReuse() { + super.prepareForReuse() + + updateTimestampWorkItem?.cancel() + updateTimestampWorkItem = nil + } + } diff --git a/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.xib b/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.xib index c853d3e8..654c1f5f 100644 --- a/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.xib +++ b/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.xib @@ -16,17 +16,31 @@ - + - + - - - + + + + + + + + + + + +