forked from zelo72/mastodon-ios
chore: update "{time_abbr} ago" string
This commit is contained in:
parent
fea3b5d8b4
commit
ffea4b1438
|
@ -69,7 +69,17 @@ extension NotificationSection {
|
|||
|
||||
// configure author name, notification description, timestamp
|
||||
let nameText = notification.account.displayNameWithFallback
|
||||
let titleLabelText = "\(nameText) \(notification.notificationType.actionText)"
|
||||
let titleLabelText: String = {
|
||||
switch notification.notificationType {
|
||||
case .favourite: return L10n.Scene.Notification.userFavoritedYourPost(nameText)
|
||||
case .follow: return L10n.Scene.Notification.userFollowedYou(nameText)
|
||||
case .followRequest: return L10n.Scene.Notification.userRequestedToFollowYou(nameText)
|
||||
case .mention: return L10n.Scene.Notification.userMentionedYou(nameText)
|
||||
case .poll: return L10n.Scene.Notification.userYourPollHasEnded(nameText)
|
||||
case .reblog: return L10n.Scene.Notification.userRebloggedYourPost(nameText)
|
||||
default: return ""
|
||||
}
|
||||
}()
|
||||
|
||||
do {
|
||||
let nameContent = MastodonContent(content: nameText, emojis: notification.account.emojiMeta)
|
||||
|
@ -94,12 +104,12 @@ extension NotificationSection {
|
|||
}
|
||||
|
||||
let createAt = notification.createAt
|
||||
cell.timestampLabel.text = createAt.localizedTimeAgoSinceNow
|
||||
cell.timestampLabel.text = createAt.localizedSlowedTimeAgoSinceNow
|
||||
AppContext.shared.timestampUpdatePublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak cell] _ in
|
||||
guard let cell = cell else { return }
|
||||
cell.timestampLabel.text = createAt.localizedTimeAgoSinceNow
|
||||
cell.timestampLabel.text = createAt.localizedSlowedTimeAgoSinceNow
|
||||
}
|
||||
.store(in: &cell.disposeBag)
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ extension Date {
|
|||
return L10n.Common.Controls.Timeline.Timestamp.now
|
||||
} else {
|
||||
if isAbbreviated {
|
||||
return latestDate.shortTimeAgo(since: earlierDate)
|
||||
return latestDate.localizedShortTimeAgo(since: earlierDate)
|
||||
} else {
|
||||
return Date.relativeTimestampFormatter.localizedString(for: earlierDate, relativeTo: latestDate)
|
||||
}
|
||||
|
@ -44,6 +44,29 @@ extension Date {
|
|||
|
||||
extension Date {
|
||||
|
||||
func localizedShortTimeAgo(since date: Date) -> String {
|
||||
let earlierDate = date < self ? date : self
|
||||
let latestDate = earlierDate == date ? self : date
|
||||
|
||||
let components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: earlierDate, to: latestDate)
|
||||
|
||||
if components.year! > 0 {
|
||||
return L10n.Date.Year.Ago.abbr(components.year!)
|
||||
} else if components.month! > 0 {
|
||||
return L10n.Date.Month.Ago.abbr(components.month!)
|
||||
} else if components.day! > 0 {
|
||||
return L10n.Date.Day.Ago.abbr(components.day!)
|
||||
} else if components.hour! > 0 {
|
||||
return L10n.Date.Hour.Ago.abbr(components.hour!)
|
||||
} else if components.minute! > 0 {
|
||||
return L10n.Date.Minute.Ago.abbr(components.minute!)
|
||||
} else if components.second! > 0 {
|
||||
return L10n.Date.Year.Ago.abbr(components.second!)
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func localizedTimeLeft() -> String {
|
||||
let date = Date()
|
||||
let earlierDate = date < self ? date : self
|
||||
|
@ -52,7 +75,7 @@ extension Date {
|
|||
let components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: earlierDate, to: latestDate)
|
||||
|
||||
if components.year! > 0 {
|
||||
return L10n.Date.Year.left(components.second!)
|
||||
return L10n.Date.Year.left(components.year!)
|
||||
} else if components.month! > 0 {
|
||||
return L10n.Date.Month.left(components.month!)
|
||||
} else if components.day! > 0 {
|
||||
|
|
|
@ -33,28 +33,28 @@ extension Mastodon.Entity.Notification.NotificationType {
|
|||
}
|
||||
}
|
||||
|
||||
public var actionText: String {
|
||||
get {
|
||||
var actionText: String
|
||||
switch self {
|
||||
case .follow:
|
||||
actionText = L10n.Scene.Notification.Action.follow
|
||||
case .favourite:
|
||||
actionText = L10n.Scene.Notification.Action.favourite
|
||||
case .reblog:
|
||||
actionText = L10n.Scene.Notification.Action.reblog
|
||||
case .mention:
|
||||
actionText = L10n.Scene.Notification.Action.mention
|
||||
case .poll:
|
||||
actionText = L10n.Scene.Notification.Action.poll
|
||||
case .followRequest:
|
||||
actionText = L10n.Scene.Notification.Action.followRequest
|
||||
default:
|
||||
actionText = ""
|
||||
}
|
||||
return actionText
|
||||
}
|
||||
}
|
||||
// public var actionText: String {
|
||||
// get {
|
||||
// var actionText: String
|
||||
// switch self {
|
||||
// case .follow:
|
||||
// actionText = L10n.Scene.Notification.Action.follow
|
||||
// case .favourite:
|
||||
// actionText = L10n.Scene.Notification.Action.favourite
|
||||
// case .reblog:
|
||||
// actionText = L10n.Scene.Notification.Action.reblog
|
||||
// case .mention:
|
||||
// actionText = L10n.Scene.Notification.Action.mention
|
||||
// case .poll:
|
||||
// actionText = L10n.Scene.Notification.Action.poll
|
||||
// case .followRequest:
|
||||
// actionText = L10n.Scene.Notification.Action.followRequest
|
||||
// default:
|
||||
// actionText = ""
|
||||
// }
|
||||
// return actionText
|
||||
// }
|
||||
// }
|
||||
|
||||
public var actionImageName: String {
|
||||
get {
|
||||
|
|
Loading…
Reference in New Issue