Notification timestamps

This commit is contained in:
Justin Mazzocchi 2021-01-26 18:31:00 -08:00
parent 95845057c5
commit 1f590ddf09
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
6 changed files with 31 additions and 4 deletions

View file

@ -198,6 +198,7 @@ extension ContentDatabase {
t.column("id", .text).primaryKey(onConflict: .replace)
t.column("type", .text).notNull()
t.column("accountId", .text).notNull().references("accountRecord", onDelete: .cascade)
t.column("createdAt", .datetime).notNull()
t.column("statusId").references("statusRecord", onDelete: .cascade)
}

View file

@ -8,6 +8,7 @@ struct NotificationRecord: ContentDatabaseRecord, Hashable {
let id: String
let type: MastodonNotification.NotificationType
let accountId: Account.Id
let createdAt: Date
let statusId: Status.Id?
}
@ -16,6 +17,7 @@ extension NotificationRecord {
static let id = Column(CodingKeys.id)
static let type = Column(CodingKeys.type)
static let accountId = Column(CodingKeys.accountId)
static let createdAt = Column(CodingKeys.createdAt)
static let statusId = Column(CodingKeys.statusId)
}
@ -26,6 +28,7 @@ extension NotificationRecord {
id = notification.id
type = notification.type
accountId = notification.account.id
createdAt = notification.createdAt
statusId = notification.status?.id
}
}

View file

@ -24,6 +24,7 @@ extension MastodonNotification {
id: info.record.id,
type: info.record.type,
account: .init(info: info.accountInfo),
createdAt: info.record.createdAt,
status: status)
}
}

View file

@ -6,12 +6,18 @@ public struct MastodonNotification: Codable, Hashable {
public let id: Id
public let type: NotificationType
public let account: Account
public let createdAt: Date
public let status: Status?
public init(id: String, type: MastodonNotification.NotificationType, account: Account, status: Status?) {
public init(id: String,
type: MastodonNotification.NotificationType,
account: Account,
createdAt: Date,
status: Status?) {
self.id = id
self.type = type
self.account = account
self.createdAt = createdAt
self.status = status
}
}

View file

@ -39,6 +39,8 @@ public extension NotificationViewModel {
notificationService.notification.type
}
var time: String? { notificationService.notification.createdAt.timeAgo }
func accountSelected() {
eventsSubject.send(
Just(.navigation(

View file

@ -10,6 +10,7 @@ final class NotificationView: UIView {
private let avatarImageView = AnimatedImageView()
private let avatarButton = UIButton()
private let typeLabel = UILabel()
private let timeLabel = UILabel()
private let displayNameLabel = UILabel()
private let accountLabel = UILabel()
private let statusBodyView = StatusBodyView()
@ -75,24 +76,29 @@ private extension NotificationView {
func initialSetup() {
let containerStackView = UIStackView()
let sideStackView = UIStackView()
let typeTimeStackView = UIStackView()
let mainStackView = UIStackView()
addSubview(containerStackView)
containerStackView.translatesAutoresizingMaskIntoConstraints = false
containerStackView.spacing = .defaultSpacing
containerStackView.alignment = .top
sideStackView.axis = .vertical
sideStackView.alignment = .trailing
sideStackView.spacing = .compactSpacing
sideStackView.addArrangedSubview(iconImageView)
sideStackView.addArrangedSubview(avatarImageView)
sideStackView.addArrangedSubview(UIView())
containerStackView.addArrangedSubview(sideStackView)
typeTimeStackView.spacing = .compactSpacing
typeTimeStackView.alignment = .top
mainStackView.axis = .vertical
mainStackView.spacing = .compactSpacing
mainStackView.addArrangedSubview(typeLabel)
mainStackView.addSubview(UIView())
typeTimeStackView.addArrangedSubview(typeLabel)
typeTimeStackView.addArrangedSubview(timeLabel)
mainStackView.addArrangedSubview(typeTimeStackView)
mainStackView.addArrangedSubview(statusBodyView)
mainStackView.addArrangedSubview(displayNameLabel)
mainStackView.addArrangedSubview(accountLabel)
@ -121,6 +127,12 @@ private extension NotificationView {
typeLabel.adjustsFontForContentSizeCategory = true
typeLabel.numberOfLines = 0
timeLabel.font = .preferredFont(forTextStyle: .subheadline)
timeLabel.adjustsFontForContentSizeCategory = true
timeLabel.textColor = .secondaryLabel
timeLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
timeLabel.setContentHuggingPriority(.required, for: .horizontal)
statusBodyView.alpha = 0.5
statusBodyView.isUserInteractionEnabled = false
@ -205,6 +217,8 @@ private extension NotificationView {
accountLabel.isHidden = true
}
timeLabel.text = viewModel.time
iconImageView.image = UIImage(
systemName: viewModel.type.systemImageName,
withConfiguration: UIImage.SymbolConfiguration(scale: .medium))