Add timestamp to follow notifications
This commit is contained in:
parent
a363308147
commit
a8ae559c9d
|
@ -94,7 +94,7 @@ class ActionNotificationGroupTableViewCell: UITableViewCell {
|
||||||
func updateTimestamp() {
|
func updateTimestamp() {
|
||||||
guard let id = group.notificationIDs.first,
|
guard let id = group.notificationIDs.first,
|
||||||
let notification = MastodonCache.notification(for: id) else {
|
let notification = MastodonCache.notification(for: id) else {
|
||||||
fatalError("Missing cached status")
|
fatalError("Missing cached notification")
|
||||||
}
|
}
|
||||||
|
|
||||||
timestampLabel.text = notification.createdAt.timeAgoString()
|
timestampLabel.text = notification.createdAt.timeAgoString()
|
||||||
|
|
|
@ -14,10 +14,13 @@ class FollowNotificationGroupTableViewCell: UITableViewCell {
|
||||||
var delegate: TuskerNavigationDelegate?
|
var delegate: TuskerNavigationDelegate?
|
||||||
|
|
||||||
@IBOutlet weak var avatarStackView: UIStackView!
|
@IBOutlet weak var avatarStackView: UIStackView!
|
||||||
|
@IBOutlet weak var timestampLabel: UILabel!
|
||||||
@IBOutlet weak var actionLabel: UILabel!
|
@IBOutlet weak var actionLabel: UILabel!
|
||||||
|
|
||||||
var group: NotificationGroup!
|
var group: NotificationGroup!
|
||||||
|
|
||||||
|
var updateTimestampWorkItem: DispatchWorkItem?
|
||||||
|
|
||||||
override func awakeFromNib() {
|
override func awakeFromNib() {
|
||||||
super.awakeFromNib()
|
super.awakeFromNib()
|
||||||
|
|
||||||
|
@ -39,6 +42,7 @@ class FollowNotificationGroupTableViewCell: UITableViewCell {
|
||||||
let people = group.notificationIDs.compactMap(MastodonCache.notification(for:)).map { $0.account }
|
let people = group.notificationIDs.compactMap(MastodonCache.notification(for:)).map { $0.account }
|
||||||
|
|
||||||
updateActionLabel(people: people)
|
updateActionLabel(people: people)
|
||||||
|
updateTimestamp()
|
||||||
|
|
||||||
avatarStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
avatarStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||||
for account in people {
|
for account in people {
|
||||||
|
@ -74,5 +78,39 @@ class FollowNotificationGroupTableViewCell: UITableViewCell {
|
||||||
}
|
}
|
||||||
actionLabel.text = "Followed by \(peopleStr)"
|
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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,31 @@
|
||||||
<rect key="frame" x="0.0" y="0.0" width="320" height="98"/>
|
<rect key="frame" x="0.0" y="0.0" width="320" height="98"/>
|
||||||
<autoresizingMask key="autoresizingMask"/>
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
<subviews>
|
<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"/>
|
<rect key="frame" x="74" y="11" width="230" height="76"/>
|
||||||
<subviews>
|
<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"/>
|
<rect key="frame" x="0.0" y="0.0" width="230" height="30"/>
|
||||||
<constraints>
|
<subviews>
|
||||||
<constraint firstAttribute="height" constant="30" id="3ns-8D-P1Q"/>
|
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="xyB-aZ-YhR">
|
||||||
</constraints>
|
<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>
|
</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">
|
<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"/>
|
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<nil key="highlightedColor"/>
|
<nil key="highlightedColor"/>
|
||||||
|
@ -54,6 +68,7 @@
|
||||||
<connections>
|
<connections>
|
||||||
<outlet property="actionLabel" destination="bHA-9x-pcO" id="Woa-25-hgd"/>
|
<outlet property="actionLabel" destination="bHA-9x-pcO" id="Woa-25-hgd"/>
|
||||||
<outlet property="avatarStackView" destination="xyB-aZ-YhR" id="DDp-5c-Qdo"/>
|
<outlet property="avatarStackView" destination="xyB-aZ-YhR" id="DDp-5c-Qdo"/>
|
||||||
|
<outlet property="timestampLabel" destination="Iub-HC-orP" id="OCV-mm-LXF"/>
|
||||||
</connections>
|
</connections>
|
||||||
<point key="canvasLocation" x="131.8840579710145" y="171.42857142857142"/>
|
<point key="canvasLocation" x="131.8840579710145" y="171.42857142857142"/>
|
||||||
</tableViewCell>
|
</tableViewCell>
|
||||||
|
|
Loading…
Reference in New Issue