Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a Date for the timestamp in all timeline items. #3590

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ElementX/Sources/Mocks/PollMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension PollRoomTimelineItem {
.init(id: .randomEvent,
poll: poll,
body: "poll",
timestamp: "Now",
timestamp: .mock,
isOutgoing: isOutgoing,
isEditable: isEditable,
canBeRepliedTo: true,
Expand Down
10 changes: 10 additions & 0 deletions ElementX/Sources/Other/Extensions/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ extension Date {
return formatted(.dateTime.year().day().month())
}
}

/// The date formatted as just the time, for use in timeline items specifically.
func formattedTime() -> String {
formatted(date: .omitted, time: .shortened)
}

/// A fixed date used for mocks, previews etc.
static var mock: Date {
Calendar.current.startOfDay(for: .now).addingTimeInterval((9 * 60 * 60) + (41 * 60)) // 9:41 am
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct TimelineItemMenu: View {

Spacer(minLength: 16.0)

Text(item.timestamp)
Text(item.timestamp.formattedTime())
.font(.compound.bodyXS)
.foregroundColor(.compound.textSecondary)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct SwipeToReplyView: View {

struct SwipeToReplyView_Previews: PreviewProvider, TestablePreview {
static let timelineItem = TextRoomTimelineItem(id: .randomEvent,
timestamp: "",
timestamp: .mock,
isOutgoing: true,
isEditable: true,
canBeRepliedTo: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
static var replies: some View {
VStack(spacing: 0) {
RoomTimelineItemView(viewState: .init(item: TextRoomTimelineItem(id: .randomEvent,
timestamp: "10:42",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -425,7 +425,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
groupStyle: .single))

RoomTimelineItemView(viewState: .init(item: TextRoomTimelineItem(id: .randomEvent,
timestamp: "10:42",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand Down Expand Up @@ -460,7 +460,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
static var encryptionAuthenticity: some View {
VStack(spacing: 0) {
RoomTimelineItemView(viewState: .init(item: TextRoomTimelineItem(id: .randomEvent,
timestamp: "10:42",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -471,7 +471,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
groupStyle: .single))

RoomTimelineItemView(viewState: .init(item: TextRoomTimelineItem(id: .randomEvent,
timestamp: "10:42",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -483,7 +483,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
groupStyle: .single))

RoomTimelineItemView(viewState: .init(item: TextRoomTimelineItem(id: .randomEvent,
timestamp: "10:42",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -494,7 +494,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
groupStyle: .first))

RoomTimelineItemView(viewState: .init(item: TextRoomTimelineItem(id: .randomEvent,
timestamp: "10:42",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -505,7 +505,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
groupStyle: .last))

ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -518,7 +518,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
properties: RoomTimelineItemProperties(encryptionAuthenticity: .notGuaranteed(color: .gray))))

VoiceMessageRoomTimelineView(timelineItem: .init(id: .randomEvent,
timestamp: "10:42",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand Down Expand Up @@ -547,7 +547,7 @@ private struct MockTimelineContent: View {

var body: some View {
RoomTimelineItemView(viewState: .init(item: TextRoomTimelineItem(id: makeItemIdentifier(),
timestamp: "10:42",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -558,7 +558,7 @@ private struct MockTimelineContent: View {
groupStyle: .single))

AudioRoomTimelineView(timelineItem: .init(id: makeItemIdentifier(),
timestamp: "10:42",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -573,7 +573,7 @@ private struct MockTimelineContent: View {
replyDetails: replyDetails))

FileRoomTimelineView(timelineItem: .init(id: makeItemIdentifier(),
timestamp: "10:42",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -588,7 +588,7 @@ private struct MockTimelineContent: View {
replyDetails: replyDetails))

ImageRoomTimelineView(timelineItem: .init(id: makeItemIdentifier(),
timestamp: "10:42",
timestamp: .mock,
isOutgoing: true,
isEditable: true,
canBeRepliedTo: true,
Expand All @@ -600,7 +600,7 @@ private struct MockTimelineContent: View {
replyDetails: replyDetails))

LocationRoomTimelineView(timelineItem: .init(id: makeItemIdentifier(),
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -613,7 +613,7 @@ private struct MockTimelineContent: View {
replyDetails: replyDetails))

LocationRoomTimelineView(timelineItem: .init(id: makeItemIdentifier(),
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -624,7 +624,7 @@ private struct MockTimelineContent: View {
replyDetails: replyDetails))

VoiceMessageRoomTimelineView(timelineItem: .init(id: makeItemIdentifier(),
timestamp: "10:42",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct TimelineItemStyler_Previews: PreviewProvider, TestablePreview {
static let viewModel = TimelineViewModel.mock

static let base = TextRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -81,7 +81,7 @@ struct TimelineItemStyler_Previews: PreviewProvider, TestablePreview {
static let sendingLast: TextRoomTimelineItem = {
let id = viewModel.state.timelineViewState.uniqueIDs.last ?? .init(id: UUID().uuidString)
var result = TextRoomTimelineItem(id: .event(uniqueID: id, eventOrTransactionID: .eventId(eventId: UUID().uuidString)),
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -101,7 +101,7 @@ struct TimelineItemStyler_Previews: PreviewProvider, TestablePreview {
static let sentLast: TextRoomTimelineItem = {
let id = viewModel.state.timelineViewState.uniqueIDs.last ?? .init(id: UUID().uuidString)
let result = TextRoomTimelineItem(id: .event(uniqueID: id, eventOrTransactionID: .eventId(eventId: UUID().uuidString)),
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -112,23 +112,23 @@ struct TimelineItemStyler_Previews: PreviewProvider, TestablePreview {
}()

static let ltrString = TextRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
isThreaded: false,
sender: .test, content: .init(body: "house!"))

static let rtlString = TextRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
isThreaded: false,
sender: .test, content: .init(body: "באמת!"))

static let ltrStringThatContainsRtl = TextRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -137,7 +137,7 @@ struct TimelineItemStyler_Previews: PreviewProvider, TestablePreview {
content: .init(body: "house! -- באמת‏! -- house!"))

static let rtlStringThatContainsLtr = TextRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -146,7 +146,7 @@ struct TimelineItemStyler_Previews: PreviewProvider, TestablePreview {
content: .init(body: "באמת‏! -- house! -- באמת!"))

static let ltrStringThatFinishesInRtl = TextRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand All @@ -155,7 +155,7 @@ struct TimelineItemStyler_Previews: PreviewProvider, TestablePreview {
content: .init(body: "house! -- באמת!"))

static let rtlStringThatFinishesInLtr = TextRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct TimelineReadReceiptsView_Previews: PreviewProvider, TestablePreview {

static func mockTimelineItem(with receipts: [ReadReceipt]) -> TextRoomTimelineItem {
TextRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct AudioRoomTimelineView_Previews: PreviewProvider, TestablePreview {

static func makeItem(filename: String, fileSize: UInt, caption: String? = nil) -> AudioRoomTimelineItem {
.init(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct CallInviteRoomTimelineView_Previews: PreviewProvider, TestablePreview {

static var body: some View {
CallInviteRoomTimelineView(timelineItem: .init(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isEditable: false,
canBeRepliedTo: false,
sender: .init(id: "Bob")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct CallNotificationRoomTimelineView: View {

Spacer()

Text(timelineItem.timestamp)
Text(timelineItem.timestamp.formattedTime())
.font(.compound.bodyXS)
.foregroundColor(.compound.textSecondary)
}
Expand All @@ -61,7 +61,7 @@ struct CallNotificationRoomTimelineView_Previews: PreviewProvider, TestablePrevi

static var body: some View {
CallNotificationRoomTimelineView(timelineItem: .init(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isEditable: false,
canBeRepliedTo: false,
sender: .init(id: "Bob")))
Expand Down
Loading
Loading