forked from shadowfacts/Tusker
Show edit timestamps on statuses
This commit is contained in:
parent
2157126332
commit
f9a41fd4f3
|
@ -41,6 +41,7 @@ public final class Status: StatusProtocol, Decodable, Sendable {
|
|||
public let poll: Poll?
|
||||
// Hometown, Glitch only
|
||||
public let localOnly: Bool?
|
||||
public let editedAt: Date?
|
||||
|
||||
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.card = try container.decodeIfPresent(Card.self, forKey: .card)
|
||||
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> {
|
||||
|
@ -197,6 +199,7 @@ public final class Status: StatusProtocol, Decodable, Sendable {
|
|||
case card
|
||||
case poll
|
||||
case localOnly = "local_only"
|
||||
case editedAt = "edited_at"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ public final class StatusMO: NSManagedObject, StatusProtocol {
|
|||
@NSManaged public var cardData: Data?
|
||||
@NSManaged public var content: String
|
||||
@NSManaged public var createdAt: Date
|
||||
@NSManaged public var editedAt: Date?
|
||||
@NSManaged private var emojisData: Data?
|
||||
@NSManaged public var favourited: Bool
|
||||
@NSManaged public var favouritesCount: Int
|
||||
|
@ -113,6 +114,7 @@ extension StatusMO {
|
|||
self.card = status.card
|
||||
self.content = status.content
|
||||
self.createdAt = status.createdAt
|
||||
self.editedAt = status.editedAt
|
||||
self.emojis = status.emojis
|
||||
self.favourited = status.favourited ?? false
|
||||
self.favouritesCount = status.favouritesCount
|
||||
|
|
|
@ -89,6 +89,7 @@
|
|||
<attribute name="cardData" optional="YES" attributeType="Binary"/>
|
||||
<attribute name="content" attributeType="String"/>
|
||||
<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="favourited" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="favouritesCount" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
|
|
|
@ -154,6 +154,11 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status
|
|||
$0.adjustsFontForContentSizeCategory = true
|
||||
}
|
||||
|
||||
private let editTimestampButton = UIButton().configure {
|
||||
$0.titleLabel!.adjustsFontForContentSizeCategory = true
|
||||
$0.isPointerInteractionEnabled = true
|
||||
}
|
||||
|
||||
private let firstSeparator = UIView().configure {
|
||||
$0.backgroundColor = .separator
|
||||
NSLayoutConstraint.activate([
|
||||
|
@ -171,6 +176,7 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status
|
|||
firstSeparator,
|
||||
actionsCountHStack,
|
||||
timestampAndClientLabel,
|
||||
editTimestampButton,
|
||||
secondSeparator,
|
||||
]).configure {
|
||||
$0.axis = .vertical
|
||||
|
@ -341,21 +347,21 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status
|
|||
accountDetailAccessibilityElement.navigationDelegate = delegate
|
||||
accountDetailAccessibilityElement.accountID = accountID
|
||||
|
||||
let favoriteAndReblogAttributes = AttributeContainer([
|
||||
let metaButtonAttributes = AttributeContainer([
|
||||
.font: ConversationMainStatusCollectionViewCell.metaFont
|
||||
])
|
||||
|
||||
let favoritesFormat = NSLocalizedString("favorites count", comment: "conv main status favorites button label")
|
||||
var favoritesConfig = UIButton.Configuration.plain()
|
||||
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
|
||||
favoritesCountButton.configuration = favoritesConfig
|
||||
|
||||
let reblogsFormat = NSLocalizedString("reblogs count", comment: "conv main status reblogs button label")
|
||||
var reblogsConfig = UIButton.Configuration.plain()
|
||||
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
|
||||
reblogsCountButton.configuration = reblogsConfig
|
||||
|
||||
|
@ -364,6 +370,17 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status
|
|||
timestampAndClientText += " • \(application)"
|
||||
}
|
||||
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() {
|
||||
|
|
|
@ -637,7 +637,8 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti
|
|||
// if there's a pending update timestamp work item, cancel it
|
||||
updateTimestampWorkItem?.cancel()
|
||||
|
||||
timestampLabel.text = status.createdAt.timeAgoString()
|
||||
let timeAgo = status.createdAt.timeAgoString()
|
||||
timestampLabel.text = "\(timeAgo)\(status.editedAt != nil ? "*" : "")"
|
||||
|
||||
let delay: DispatchTimeInterval?
|
||||
switch status.createdAt.timeAgo().1 {
|
||||
|
|
Loading…
Reference in New Issue