Show edit timestamps on statuses

This commit is contained in:
Shadowfacts 2023-05-11 13:10:45 -04:00
parent 2157126332
commit f9a41fd4f3
5 changed files with 28 additions and 4 deletions

View File

@ -41,6 +41,7 @@ public final class Status: StatusProtocol, Decodable, Sendable {
public let poll: Poll? public let poll: Poll?
// Hometown, Glitch only // Hometown, Glitch only
public let localOnly: Bool? public let localOnly: Bool?
public let editedAt: Date?
public var applicationName: String? { application?.name } public var applicationName: String? { application?.name }
@ -92,6 +93,7 @@ public final class Status: StatusProtocol, Decodable, Sendable {
self.bookmarked = try container.decodeIfPresent(Bool.self, forKey: .bookmarked) self.bookmarked = try container.decodeIfPresent(Bool.self, forKey: .bookmarked)
self.card = try container.decodeIfPresent(Card.self, forKey: .card) self.card = try container.decodeIfPresent(Card.self, forKey: .card)
self.poll = try container.decodeIfPresent(Poll.self, forKey: .poll) self.poll = try container.decodeIfPresent(Poll.self, forKey: .poll)
self.editedAt = try container.decodeIfPresent(Date.self, forKey: .editedAt)
} }
public static func getContext(_ statusID: String) -> Request<ConversationContext> { public static func getContext(_ statusID: String) -> Request<ConversationContext> {
@ -197,6 +199,7 @@ public final class Status: StatusProtocol, Decodable, Sendable {
case card case card
case poll case poll
case localOnly = "local_only" case localOnly = "local_only"
case editedAt = "edited_at"
} }
} }

View File

@ -31,6 +31,7 @@ public final class StatusMO: NSManagedObject, StatusProtocol {
@NSManaged public var cardData: Data? @NSManaged public var cardData: Data?
@NSManaged public var content: String @NSManaged public var content: String
@NSManaged public var createdAt: Date @NSManaged public var createdAt: Date
@NSManaged public var editedAt: Date?
@NSManaged private var emojisData: Data? @NSManaged private var emojisData: Data?
@NSManaged public var favourited: Bool @NSManaged public var favourited: Bool
@NSManaged public var favouritesCount: Int @NSManaged public var favouritesCount: Int
@ -113,6 +114,7 @@ extension StatusMO {
self.card = status.card self.card = status.card
self.content = status.content self.content = status.content
self.createdAt = status.createdAt self.createdAt = status.createdAt
self.editedAt = status.editedAt
self.emojis = status.emojis self.emojis = status.emojis
self.favourited = status.favourited ?? false self.favourited = status.favourited ?? false
self.favouritesCount = status.favouritesCount self.favouritesCount = status.favouritesCount

View File

@ -89,6 +89,7 @@
<attribute name="cardData" optional="YES" attributeType="Binary"/> <attribute name="cardData" optional="YES" attributeType="Binary"/>
<attribute name="content" attributeType="String"/> <attribute name="content" attributeType="String"/>
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/> <attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="editedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="emojisData" attributeType="Binary" customClassName="[Data]"/> <attribute name="emojisData" attributeType="Binary" customClassName="[Data]"/>
<attribute name="favourited" attributeType="Boolean" usesScalarValueType="YES"/> <attribute name="favourited" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="favouritesCount" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/> <attribute name="favouritesCount" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>

View File

@ -154,6 +154,11 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status
$0.adjustsFontForContentSizeCategory = true $0.adjustsFontForContentSizeCategory = true
} }
private let editTimestampButton = UIButton().configure {
$0.titleLabel!.adjustsFontForContentSizeCategory = true
$0.isPointerInteractionEnabled = true
}
private let firstSeparator = UIView().configure { private let firstSeparator = UIView().configure {
$0.backgroundColor = .separator $0.backgroundColor = .separator
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
@ -171,6 +176,7 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status
firstSeparator, firstSeparator,
actionsCountHStack, actionsCountHStack,
timestampAndClientLabel, timestampAndClientLabel,
editTimestampButton,
secondSeparator, secondSeparator,
]).configure { ]).configure {
$0.axis = .vertical $0.axis = .vertical
@ -341,21 +347,21 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status
accountDetailAccessibilityElement.navigationDelegate = delegate accountDetailAccessibilityElement.navigationDelegate = delegate
accountDetailAccessibilityElement.accountID = accountID accountDetailAccessibilityElement.accountID = accountID
let favoriteAndReblogAttributes = AttributeContainer([ let metaButtonAttributes = AttributeContainer([
.font: ConversationMainStatusCollectionViewCell.metaFont .font: ConversationMainStatusCollectionViewCell.metaFont
]) ])
let favoritesFormat = NSLocalizedString("favorites count", comment: "conv main status favorites button label") let favoritesFormat = NSLocalizedString("favorites count", comment: "conv main status favorites button label")
var favoritesConfig = UIButton.Configuration.plain() var favoritesConfig = UIButton.Configuration.plain()
favoritesConfig.baseForegroundColor = .secondaryLabel favoritesConfig.baseForegroundColor = .secondaryLabel
favoritesConfig.attributedTitle = AttributedString(String.localizedStringWithFormat(favoritesFormat, status.favouritesCount), attributes: favoriteAndReblogAttributes) favoritesConfig.attributedTitle = AttributedString(String.localizedStringWithFormat(favoritesFormat, status.favouritesCount), attributes: metaButtonAttributes)
favoritesConfig.contentInsets = .zero favoritesConfig.contentInsets = .zero
favoritesCountButton.configuration = favoritesConfig favoritesCountButton.configuration = favoritesConfig
let reblogsFormat = NSLocalizedString("reblogs count", comment: "conv main status reblogs button label") let reblogsFormat = NSLocalizedString("reblogs count", comment: "conv main status reblogs button label")
var reblogsConfig = UIButton.Configuration.plain() var reblogsConfig = UIButton.Configuration.plain()
reblogsConfig.baseForegroundColor = .secondaryLabel reblogsConfig.baseForegroundColor = .secondaryLabel
reblogsConfig.attributedTitle = AttributedString(String.localizedStringWithFormat(reblogsFormat, status.reblogsCount), attributes: favoriteAndReblogAttributes) reblogsConfig.attributedTitle = AttributedString(String.localizedStringWithFormat(reblogsFormat, status.reblogsCount), attributes: metaButtonAttributes)
reblogsConfig.contentInsets = .zero reblogsConfig.contentInsets = .zero
reblogsCountButton.configuration = reblogsConfig reblogsCountButton.configuration = reblogsConfig
@ -364,6 +370,17 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status
timestampAndClientText += "\(application)" timestampAndClientText += "\(application)"
} }
timestampAndClientLabel.text = timestampAndClientText timestampAndClientLabel.text = timestampAndClientText
if let editedAt = status.editedAt {
editTimestampButton.isHidden = false
var config = UIButton.Configuration.plain()
config.baseForegroundColor = .secondaryLabel
config.attributedTitle = AttributedString("Edited on \(ConversationMainStatusCollectionViewCell.dateFormatter.string(from: editedAt))", attributes: metaButtonAttributes)
config.contentInsets = .zero
editTimestampButton.configuration = config
} else {
editTimestampButton.isHidden = true
}
} }
private func createObservers() { private func createObservers() {

View File

@ -637,7 +637,8 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
// if there's a pending update timestamp work item, cancel it // if there's a pending update timestamp work item, cancel it
updateTimestampWorkItem?.cancel() updateTimestampWorkItem?.cancel()
timestampLabel.text = status.createdAt.timeAgoString() let timeAgo = status.createdAt.timeAgoString()
timestampLabel.text = "\(timeAgo)\(status.editedAt != nil ? "*" : "")"
let delay: DispatchTimeInterval? let delay: DispatchTimeInterval?
switch status.createdAt.timeAgo().1 { switch status.createdAt.timeAgo().1 {