mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-27 06:25:48 +00:00
ios: display year in chat for previous years (#4919)
* ios: display year in chat for previous years * fix chat time, show past years in the list * style --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
This commit is contained in:
@@ -622,7 +622,11 @@ struct ChatView: View {
|
||||
Text(String.localizedStringWithFormat(
|
||||
NSLocalizedString("%@, %@", comment: "format for date separator in chat"),
|
||||
date.formatted(.dateTime.weekday(.abbreviated)),
|
||||
date.formatted(.dateTime.day().month(.abbreviated))
|
||||
date.formatted(
|
||||
Calendar.current.isDate(date, equalTo: .now, toGranularity: .year)
|
||||
? .dateTime.day().month(.abbreviated)
|
||||
: .dateTime.day().month(.abbreviated).year()
|
||||
)
|
||||
))
|
||||
.font(.callout)
|
||||
.fontWeight(.medium)
|
||||
|
||||
@@ -35,11 +35,16 @@ struct ChatPreviewView: View {
|
||||
}
|
||||
.padding(.leading, 4)
|
||||
|
||||
let chatTs = if let cItem {
|
||||
cItem.meta.itemTs
|
||||
} else {
|
||||
chat.chatInfo.chatTs
|
||||
}
|
||||
VStack(spacing: 0) {
|
||||
HStack(alignment: .top) {
|
||||
chatPreviewTitle()
|
||||
Spacer()
|
||||
(cItem?.timestampText ?? formatTimestampText(chat.chatInfo.chatTs))
|
||||
(formatTimestampText(chatTs))
|
||||
.font(.subheadline)
|
||||
.frame(minWidth: 60, alignment: .trailing)
|
||||
.foregroundColor(theme.colors.secondary)
|
||||
|
||||
@@ -2765,9 +2765,16 @@ public struct CITimed: Decodable, Hashable {
|
||||
|
||||
let msgTimeFormat = Date.FormatStyle.dateTime.hour().minute()
|
||||
let msgDateFormat = Date.FormatStyle.dateTime.day(.twoDigits).month(.twoDigits)
|
||||
let msgDateYearFormat = Date.FormatStyle.dateTime.day(.twoDigits).month(.twoDigits).year(.twoDigits)
|
||||
|
||||
public func formatTimestampText(_ date: Date) -> Text {
|
||||
Text(verbatim: date.formatted(recent(date) ? msgTimeFormat : msgDateFormat))
|
||||
Text(verbatim: date.formatted(
|
||||
recent(date)
|
||||
? msgTimeFormat
|
||||
: Calendar.current.isDate(date, equalTo: .now, toGranularity: .year)
|
||||
? msgDateFormat
|
||||
: msgDateYearFormat
|
||||
))
|
||||
}
|
||||
|
||||
public func formatTimestampMeta(_ date: Date) -> String {
|
||||
|
||||
Reference in New Issue
Block a user