Add timestamp to follow notifications

This commit is contained in:
Shadowfacts 2019-09-05 19:53:08 -04:00
parent a363308147
commit a8ae559c9d
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 61 additions and 8 deletions

View File

@ -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()

View File

@ -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
}
}

View File

@ -16,17 +16,31 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="98"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" translatesAutoresizingMaskIntoConstraints="NO" id="g8L-M7-dD6">
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="g8L-M7-dD6">
<rect key="frame" x="74" y="11" width="230" height="76"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="xyB-aZ-YhR">
<stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="7lu-x4-ldA">
<rect key="frame" x="0.0" y="0.0" width="230" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="3ns-8D-P1Q"/>
</constraints>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="xyB-aZ-YhR">
<rect key="frame" x="0.0" y="0.0" width="205.5" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="3ns-8D-P1Q"/>
</constraints>
</stackView>
<view contentMode="scaleToFill" horizontalHuggingPriority="249" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="eEp-GR-rtF">
<rect key="frame" x="205.5" y="0.0" width="0.0" height="30"/>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="2m" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Iub-HC-orP">
<rect key="frame" x="205.5" y="0.0" width="24.5" height="30"/>
<fontDescription key="fontDescription" type="system" weight="light" pointSize="17"/>
<color key="textColor" systemColor="secondaryLabelColor" red="0.23529411759999999" green="0.23529411759999999" blue="0.26274509800000001" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Followed by Person 1 and Person 2" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bHA-9x-pcO">
<rect key="frame" x="0.0" y="30" width="198" height="46"/>
<rect key="frame" x="0.0" y="30" width="230" height="46"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
@ -54,6 +68,7 @@
<connections>
<outlet property="actionLabel" destination="bHA-9x-pcO" id="Woa-25-hgd"/>
<outlet property="avatarStackView" destination="xyB-aZ-YhR" id="DDp-5c-Qdo"/>
<outlet property="timestampLabel" destination="Iub-HC-orP" id="OCV-mm-LXF"/>
</connections>
<point key="canvasLocation" x="131.8840579710145" y="171.42857142857142"/>
</tableViewCell>