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

* Use a Date for the timestamp in all timeline items.

* UI test snapshots.

* Update snapshots

---------

Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
This commit is contained in:
Doug 2024-12-06 13:55:29 +00:00 committed by GitHub
parent 176a8b880a
commit a9e4837b62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
235 changed files with 522 additions and 510 deletions

View File

@ -85,7 +85,7 @@ extension PollRoomTimelineItem {
.init(id: .randomEvent,
poll: poll,
body: "poll",
timestamp: "Now",
timestamp: .mock,
isOutgoing: isOutgoing,
isEditable: isEditable,
canBeRepliedTo: true,

View File

@ -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
}
}

View File

@ -85,7 +85,7 @@ struct TimelineItemMenu: View {
Spacer(minLength: 16.0)
Text(item.timestamp)
Text(item.timestamp.formattedTime())
.font(.compound.bodyXS)
.foregroundColor(.compound.textSecondary)
}

View File

@ -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,

View File

@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,

View File

@ -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,
@ -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,
@ -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,
@ -112,7 +112,7 @@ struct TimelineItemStyler_Previews: PreviewProvider, TestablePreview {
}()
static let ltrString = TextRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
@ -120,7 +120,7 @@ struct TimelineItemStyler_Previews: PreviewProvider, TestablePreview {
sender: .test, content: .init(body: "house!"))
static let rtlString = TextRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
@ -128,7 +128,7 @@ struct TimelineItemStyler_Previews: PreviewProvider, TestablePreview {
sender: .test, content: .init(body: "באמת!"))
static let ltrStringThatContainsRtl = TextRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
@ -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,
@ -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,
@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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")))

View File

@ -39,7 +39,7 @@ struct CallNotificationRoomTimelineView: View {
Spacer()
Text(timelineItem.timestamp)
Text(timelineItem.timestamp.formattedTime())
.font(.compound.bodyXS)
.foregroundColor(.compound.textSecondary)
}
@ -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")))

View File

@ -32,16 +32,16 @@ struct EmoteRoomTimelineView_Previews: PreviewProvider, TestablePreview {
static var body: some View {
VStack(alignment: .leading, spacing: 20.0) {
EmoteRoomTimelineView(timelineItem: itemWith(text: "Short loin ground round tongue hamburger, fatback salami shoulder. Beef turkey sausage kielbasa strip steak. Alcatra capicola pig tail pancetta chislic.",
timestamp: "Now",
timestamp: .mock,
senderId: "Bob"))
EmoteRoomTimelineView(timelineItem: itemWith(text: "Some other text",
timestamp: "Later",
timestamp: .mock,
senderId: "Anne"))
}
}
private static func itemWith(text: String, timestamp: String, senderId: String) -> EmoteRoomTimelineItem {
private static func itemWith(text: String, timestamp: Date, senderId: String) -> EmoteRoomTimelineItem {
EmoteRoomTimelineItem(id: .randomEvent,
timestamp: timestamp,
isOutgoing: false,

View File

@ -61,27 +61,27 @@ struct EncryptedRoomTimelineView_Previews: PreviewProvider, TestablePreview {
static var body: some View {
VStack(alignment: .leading, spacing: 20.0) {
EncryptedRoomTimelineView(timelineItem: itemWith(text: L10n.commonWaitingForDecryptionKey,
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
senderId: "Bob"))
EncryptedRoomTimelineView(timelineItem: itemWith(text: L10n.commonWaitingForDecryptionKey,
timestamp: "Later",
timestamp: .mock,
isOutgoing: true,
senderId: "Anne"))
EncryptedRoomTimelineView(timelineItem: itemWith(text: "Some other text that is very long and will wrap onto multiple lines.",
timestamp: "Later",
timestamp: .mock,
isOutgoing: true,
senderId: "Anne"))
EncryptedRoomTimelineView(timelineItem: expectedItemWith(timestamp: "Now",
EncryptedRoomTimelineView(timelineItem: expectedItemWith(timestamp: .mock,
isOutgoing: false,
senderId: "Bob"))
}
}
private static func itemWith(text: String, timestamp: String, isOutgoing: Bool, senderId: String) -> EncryptedRoomTimelineItem {
private static func itemWith(text: String, timestamp: Date, isOutgoing: Bool, senderId: String) -> EncryptedRoomTimelineItem {
EncryptedRoomTimelineItem(id: .randomEvent,
body: text,
encryptionType: .unknown,
@ -92,7 +92,7 @@ struct EncryptedRoomTimelineView_Previews: PreviewProvider, TestablePreview {
sender: .init(id: senderId))
}
private static func expectedItemWith(timestamp: String, isOutgoing: Bool, senderId: String) -> EncryptedRoomTimelineItem {
private static func expectedItemWith(timestamp: Date, isOutgoing: Bool, senderId: String) -> EncryptedRoomTimelineItem {
EncryptedRoomTimelineItem(id: .randomEvent,
body: L10n.commonUnableToDecryptNoAccess,
encryptionType: .megolmV1AesSha2(sessionID: "foo", cause: .sentBeforeWeJoined),

View File

@ -112,7 +112,7 @@ struct FileRoomTimelineView_Previews: PreviewProvider, TestablePreview {
caption: String? = nil,
formattedCaption: AttributedString? = nil) -> FileRoomTimelineItem {
.init(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,

View File

@ -94,7 +94,7 @@ struct ImageRoomTimelineView_Previews: PreviewProvider, TestablePreview {
private static func makeTimelineItem(caption: String? = nil, isEdited: Bool = false) -> ImageRoomTimelineItem {
ImageRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,

View File

@ -91,7 +91,7 @@ struct LocationRoomTimelineView_Previews: PreviewProvider, TestablePreview {
@ViewBuilder
static var states: some View {
LocationRoomTimelineView(timelineItem: .init(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
@ -100,7 +100,7 @@ struct LocationRoomTimelineView_Previews: PreviewProvider, TestablePreview {
content: .init(body: "Fallback geo uri description")))
LocationRoomTimelineView(timelineItem: .init(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
@ -109,7 +109,7 @@ struct LocationRoomTimelineView_Previews: PreviewProvider, TestablePreview {
content: .init(body: "Fallback geo uri description",
geoURI: .init(latitude: 41.902782, longitude: 12.496366), description: "Location description description description description description description description description")))
LocationRoomTimelineView(timelineItem: .init(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,

View File

@ -44,16 +44,16 @@ struct NoticeRoomTimelineView_Previews: PreviewProvider, TestablePreview {
static var body: some View {
VStack(alignment: .leading, spacing: 20.0) {
NoticeRoomTimelineView(timelineItem: itemWith(text: "Short loin ground round tongue hamburger, fatback salami shoulder. Beef turkey sausage kielbasa strip steak. Alcatra capicola pig tail pancetta chislic.",
timestamp: "Now",
timestamp: .mock,
senderId: "Bob"))
NoticeRoomTimelineView(timelineItem: itemWith(text: "Some other text",
timestamp: "Later",
timestamp: .mock,
senderId: "Anne"))
}
}
private static func itemWith(text: String, timestamp: String, senderId: String) -> NoticeRoomTimelineItem {
private static func itemWith(text: String, timestamp: Date, senderId: String) -> NoticeRoomTimelineItem {
NoticeRoomTimelineItem(id: .randomEvent,
timestamp: timestamp,
isOutgoing: false,

View File

@ -35,7 +35,7 @@ struct ReadMarkerRoomTimelineView_Previews: PreviewProvider, TestablePreview {
VStack(alignment: .leading, spacing: 0) {
RoomTimelineItemView(viewState: .init(type: .separator(.init(id: .virtual(uniqueID: .init(id: "Separator")), text: "Today")), groupStyle: .single))
RoomTimelineItemView(viewState: .init(type: .text(.init(id: .randomEvent,
timestamp: "",
timestamp: .mock,
isOutgoing: true,
isEditable: false,
canBeRepliedTo: true,
@ -47,7 +47,7 @@ struct ReadMarkerRoomTimelineView_Previews: PreviewProvider, TestablePreview {
RoomTimelineItemView(viewState: .init(type: .separator(.init(id: .virtual(uniqueID: .init(id: "Separator")), text: "Today")), groupStyle: .single))
RoomTimelineItemView(viewState: .init(type: .text(.init(id: .randomEvent,
timestamp: "",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,

View File

@ -26,13 +26,13 @@ struct RedactedRoomTimelineView_Previews: PreviewProvider, TestablePreview {
static var previews: some View {
VStack(alignment: .leading, spacing: 20.0) {
RedactedRoomTimelineView(timelineItem: itemWith(text: L10n.commonMessageRemoved,
timestamp: "Later",
timestamp: .mock,
senderId: "Anne"))
}
.environmentObject(viewModel.context)
}
private static func itemWith(text: String, timestamp: String, senderId: String) -> RedactedRoomTimelineItem {
private static func itemWith(text: String, timestamp: Date, senderId: String) -> RedactedRoomTimelineItem {
RedactedRoomTimelineItem(id: .randomEvent,
body: text,
timestamp: timestamp,

View File

@ -32,7 +32,7 @@ struct StateRoomTimelineView_Previews: PreviewProvider, TestablePreview {
static let item = StateRoomTimelineItem(id: .randomVirtual,
body: "Alice joined",
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,

View File

@ -44,7 +44,7 @@ struct StickerRoomTimelineView_Previews: PreviewProvider, TestablePreview {
VStack(spacing: 20.0) {
StickerRoomTimelineView(timelineItem: StickerRoomTimelineItem(id: .randomEvent,
body: "Some image",
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
@ -53,7 +53,7 @@ struct StickerRoomTimelineView_Previews: PreviewProvider, TestablePreview {
StickerRoomTimelineView(timelineItem: StickerRoomTimelineItem(id: .randomEvent,
body: "Blurhashed image",
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,

View File

@ -42,44 +42,44 @@ struct TextRoomTimelineView_Previews: PreviewProvider, TestablePreview {
ScrollView {
VStack(alignment: .leading, spacing: 20.0) {
TextRoomTimelineView(timelineItem: itemWith(text: "Short loin ground round tongue hamburger, fatback salami shoulder. Beef turkey sausage kielbasa strip steak. Alcatra capicola pig tail pancetta chislic.",
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
senderId: "Bob"))
TextRoomTimelineView(timelineItem: itemWith(text: "Some other text",
timestamp: "Later",
timestamp: .mock,
isOutgoing: true,
senderId: "Anne"))
TextRoomTimelineView(timelineItem: itemWith(text: "Short loin ground round tongue hamburger, fatback salami shoulder. Beef turkey sausage kielbasa strip steak. Alcatra capicola pig tail pancetta chislic.",
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
senderId: "Bob"))
TextRoomTimelineView(timelineItem: itemWith(text: "Some other text",
timestamp: "Later",
timestamp: .mock,
isOutgoing: true,
senderId: "Anne"))
TextRoomTimelineView(timelineItem: itemWith(text: "טקסט אחר",
timestamp: "Later",
timestamp: .mock,
isOutgoing: true,
senderId: "Anne"))
TextRoomTimelineView(timelineItem: itemWith(html: "<ol><li>First item</li><li>Second item</li><li>Third item</li></ol>",
timestamp: "Later",
timestamp: .mock,
isOutgoing: true,
senderId: "Anne"))
TextRoomTimelineView(timelineItem: itemWith(html: "<ol><li>פריט ראשון</li><li>הפריט השני</li><li>פריט שלישי</li></ol>",
timestamp: "Later",
timestamp: .mock,
isOutgoing: true,
senderId: "Anne"))
}
}
}
private static func itemWith(text: String, timestamp: String, isOutgoing: Bool, senderId: String) -> TextRoomTimelineItem {
private static func itemWith(text: String, timestamp: Date, isOutgoing: Bool, senderId: String) -> TextRoomTimelineItem {
TextRoomTimelineItem(id: .randomEvent,
timestamp: timestamp,
isOutgoing: isOutgoing,
@ -90,7 +90,7 @@ struct TextRoomTimelineView_Previews: PreviewProvider, TestablePreview {
content: .init(body: text))
}
private static func itemWith(html: String, timestamp: String, isOutgoing: Bool, senderId: String) -> TextRoomTimelineItem {
private static func itemWith(html: String, timestamp: Date, isOutgoing: Bool, senderId: String) -> TextRoomTimelineItem {
let builder = AttributedStringBuilder(cacheKey: "preview", mentionBuilder: MentionBuilder())
let attributedString = builder.fromHTML(html)

View File

@ -40,18 +40,18 @@ struct UnsupportedRoomTimelineView_Previews: PreviewProvider, TestablePreview {
static var body: some View {
VStack(alignment: .leading, spacing: 20.0) {
UnsupportedRoomTimelineView(timelineItem: itemWith(text: "Text",
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
senderId: "Bob"))
UnsupportedRoomTimelineView(timelineItem: itemWith(text: "Some other text",
timestamp: "Later",
timestamp: .mock,
isOutgoing: true,
senderId: "Anne"))
}
}
private static func itemWith(text: String, timestamp: String, isOutgoing: Bool, senderId: String) -> UnsupportedRoomTimelineItem {
private static func itemWith(text: String, timestamp: Date, isOutgoing: Bool, senderId: String) -> UnsupportedRoomTimelineItem {
UnsupportedRoomTimelineItem(id: .randomEvent,
body: text,
eventType: "Some Event Type",

View File

@ -98,7 +98,7 @@ struct VideoRoomTimelineView_Previews: PreviewProvider, TestablePreview {
private static func makeTimelineItem(caption: String? = nil, isEdited: Bool = false) -> VideoRoomTimelineItem {
VideoRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,

View File

@ -13,7 +13,7 @@ enum RoomTimelineItemFixtures {
SeparatorRoomTimelineItem(id: .virtual(uniqueID: .init(id: "Yesterday")), text: "Yesterday"),
TextRoomTimelineItem(id: .event(uniqueID: .init(id: ".RoomTimelineItemFixtures.default.0"),
eventOrTransactionID: .eventId(eventId: "RoomTimelineItemFixtures.default.0")),
timestamp: "10:10 AM",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
@ -23,7 +23,7 @@ enum RoomTimelineItemFixtures {
properties: RoomTimelineItemProperties(isEdited: true)),
TextRoomTimelineItem(id: .event(uniqueID: .init(id: "RoomTimelineItemFixtures.default.1"),
eventOrTransactionID: .eventId(eventId: "RoomTimelineItemFixtures.default.1")),
timestamp: "10:11 AM",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
@ -35,7 +35,7 @@ enum RoomTimelineItemFixtures {
])),
TextRoomTimelineItem(id: .event(uniqueID: .init(id: "RoomTimelineItemFixtures.default.2"),
eventOrTransactionID: .eventId(eventId: "RoomTimelineItemFixtures.default.2")),
timestamp: "10:11 AM",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
@ -55,7 +55,7 @@ enum RoomTimelineItemFixtures {
SeparatorRoomTimelineItem(id: .virtual(uniqueID: .init(id: "Today")), text: "Today"),
TextRoomTimelineItem(id: .event(uniqueID: .init(id: "RoomTimelineItemFixtures.default.3"),
eventOrTransactionID: .eventId(eventId: "RoomTimelineItemFixtures.default.3")),
timestamp: "5 PM",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
@ -65,7 +65,7 @@ enum RoomTimelineItemFixtures {
properties: RoomTimelineItemProperties(orderedReadReceipts: [ReadReceipt(userID: "alice", formattedTimestamp: nil)])),
TextRoomTimelineItem(id: .event(uniqueID: .init(id: "RoomTimelineItemFixtures.default.4"),
eventOrTransactionID: .eventId(eventId: "RoomTimelineItemFixtures.default.4")),
timestamp: "5 PM",
timestamp: .mock,
isOutgoing: true,
isEditable: true,
canBeRepliedTo: true,
@ -74,7 +74,7 @@ enum RoomTimelineItemFixtures {
content: .init(body: "And John's speech was amazing!")),
TextRoomTimelineItem(id: .event(uniqueID: .init(id: "RoomTimelineItemFixtures.default.5"),
eventOrTransactionID: .eventId(eventId: "RoomTimelineItemFixtures.default.5")),
timestamp: "5 PM",
timestamp: .mock,
isOutgoing: true,
isEditable: true,
canBeRepliedTo: true,
@ -88,7 +88,7 @@ enum RoomTimelineItemFixtures {
ReadReceipt(userID: "dan", formattedTimestamp: nil)])),
TextRoomTimelineItem(id: .event(uniqueID: .init(id: "RoomTimelineItemFixtures.default.6"),
eventOrTransactionID: .eventId(eventId: "RoomTimelineItemFixtures.default.6")),
timestamp: "5 PM",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,
@ -267,7 +267,7 @@ enum RoomTimelineItemFixtures {
private extension TextRoomTimelineItem {
init(id: TimelineItemIdentifier? = nil, text: String, senderDisplayName: String) {
self.init(id: id ?? .randomEvent,
timestamp: "10:47 am",
timestamp: .mock,
isOutgoing: senderDisplayName == "Alice",
isEditable: false,
canBeRepliedTo: true,
@ -286,7 +286,7 @@ private extension TextRoomTimelineItem {
private extension AudioRoomTimelineItem {
init(isOutgoing: Bool, caption: String? = nil) {
self.init(id: .randomEvent,
timestamp: "10:47 am",
timestamp: .mock,
isOutgoing: isOutgoing,
isEditable: isOutgoing,
canBeRepliedTo: true,
@ -305,7 +305,7 @@ private extension AudioRoomTimelineItem {
private extension FileRoomTimelineItem {
init(isOutgoing: Bool, caption: String? = nil) {
self.init(id: .randomEvent,
timestamp: "10:47 am",
timestamp: .mock,
isOutgoing: isOutgoing,
isEditable: isOutgoing,
canBeRepliedTo: true,
@ -323,7 +323,7 @@ private extension FileRoomTimelineItem {
private extension ImageRoomTimelineItem {
init(isOutgoing: Bool, caption: String? = nil) {
self.init(id: .randomEvent,
timestamp: "10:47 am",
timestamp: .mock,
isOutgoing: isOutgoing,
isEditable: isOutgoing,
canBeRepliedTo: true,
@ -340,7 +340,7 @@ private extension ImageRoomTimelineItem {
private extension VideoRoomTimelineItem {
init(isOutgoing: Bool, caption: String? = nil) {
self.init(id: .randomEvent,
timestamp: "10:47 am",
timestamp: .mock,
isOutgoing: isOutgoing,
isEditable: isOutgoing,
canBeRepliedTo: true,
@ -357,7 +357,7 @@ private extension VideoRoomTimelineItem {
private extension VoiceMessageRoomTimelineItem {
init(isOutgoing: Bool) {
self.init(id: .randomEvent,
timestamp: "10:47 am",
timestamp: .mock,
isOutgoing: isOutgoing,
isEditable: isOutgoing,
canBeRepliedTo: true,

View File

@ -9,7 +9,7 @@ import Foundation
import UIKit
protocol EventBasedTimelineItemProtocol: RoomTimelineItemProtocol, CustomStringConvertible {
var timestamp: String { get }
var timestamp: Date { get }
var isOutgoing: Bool { get }
var isEditable: Bool { get }
var canBeRepliedTo: Bool { get }
@ -84,7 +84,7 @@ extension EventBasedTimelineItemProtocol {
if properties.isEdited {
start = "\(L10n.commonEditedSuffix) "
}
return start + timestamp
return start + timestamp.formattedTime()
}
var isCopyable: Bool {

View File

@ -9,7 +9,7 @@ import Foundation
struct AudioRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -9,7 +9,7 @@ import UIKit
struct EmoteRoomTimelineItem: TextBasedRoomTimelineItem, Equatable {
let id: TimelineItemIdentifier
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -10,7 +10,7 @@ import UniformTypeIdentifiers
struct FileRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -10,7 +10,7 @@ import UniformTypeIdentifiers
struct ImageRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -5,10 +5,12 @@
// Please see LICENSE in the repository root for full details.
//
import Foundation
struct LocationRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -9,7 +9,7 @@ import UIKit
struct NoticeRoomTimelineItem: TextBasedRoomTimelineItem, Equatable {
let id: TimelineItemIdentifier
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -10,7 +10,7 @@ import UIKit
struct TextRoomTimelineItem: TextBasedRoomTimelineItem, Equatable {
let id: TimelineItemIdentifier
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -10,7 +10,7 @@ import UniformTypeIdentifiers
struct VideoRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -9,7 +9,7 @@ import Foundation
struct VoiceMessageRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -57,7 +57,7 @@ struct VoiceMessageRoomTimelineView_Previews: PreviewProvider, TestablePreview {
static let viewModel = TimelineViewModel.mock
static let timelineItemIdentifier = TimelineItemIdentifier.randomEvent
static let voiceRoomTimelineItem = VoiceMessageRoomTimelineItem(id: timelineItemIdentifier,
timestamp: "Now",
timestamp: .mock,
isOutgoing: false,
isEditable: false,
canBeRepliedTo: true,

View File

@ -9,7 +9,7 @@ import Foundation
struct CallInviteRoomTimelineItem: RoomTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let timestamp: String
let timestamp: Date
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -9,7 +9,7 @@ import Foundation
struct CallNotificationRoomTimelineItem: RoomTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let timestamp: String
let timestamp: Date
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -27,7 +27,7 @@ struct EncryptedRoomTimelineItem: EventBasedTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let body: String
let encryptionType: EncryptionType
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -11,7 +11,7 @@ struct PollRoomTimelineItem: Equatable, EventBasedTimelineItemProtocol {
let id: TimelineItemIdentifier
let poll: Poll
let body: String
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -11,7 +11,7 @@ import UIKit
struct RedactedRoomTimelineItem: EventBasedTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let body: String
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -10,7 +10,7 @@ import UIKit
struct StateRoomTimelineItem: EventBasedTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let body: String
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -10,7 +10,7 @@ import UIKit
struct StickerRoomTimelineItem: EventBasedTimelineItemProtocol, Equatable {
let id: TimelineItemIdentifier
let body: String
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -14,7 +14,7 @@ struct UnsupportedRoomTimelineItem: EventBasedTimelineItemProtocol, Equatable {
let eventType: String
let error: String
let timestamp: String
let timestamp: Date
let isOutgoing: Bool
let isEditable: Bool
let canBeRepliedTo: Bool

View File

@ -103,7 +103,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
body: L10n.commonUnsupportedEvent,
eventType: eventType,
error: error,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -120,7 +120,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
return StickerRoomTimelineItem(id: eventItemProxy.id,
body: body,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -172,7 +172,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
return EncryptedRoomTimelineItem(id: eventItemProxy.id,
body: errorLabel,
encryptionType: encryptionType,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -184,7 +184,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
RedactedRoomTimelineItem(id: eventItemProxy.id,
body: L10n.commonMessageRemoved,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -197,7 +197,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ textMessageContent: TextMessageContent,
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
TextRoomTimelineItem(id: eventItemProxy.id,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -217,7 +217,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ imageMessageContent: ImageMessageContent,
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
ImageRoomTimelineItem(id: eventItemProxy.id,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -237,7 +237,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ videoMessageContent: VideoMessageContent,
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
VideoRoomTimelineItem(id: eventItemProxy.id,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -257,7 +257,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ audioMessageContent: AudioMessageContent,
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
AudioRoomTimelineItem(id: eventItemProxy.id,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -277,7 +277,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ audioMessageContent: AudioMessageContent,
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
VoiceMessageRoomTimelineItem(id: eventItemProxy.id,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -297,7 +297,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ fileMessageContent: FileMessageContent,
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
FileRoomTimelineItem(id: eventItemProxy.id,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -317,7 +317,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ noticeMessageContent: NoticeMessageContent,
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
NoticeRoomTimelineItem(id: eventItemProxy.id,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -337,7 +337,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ emoteMessageContent: EmoteMessageContent,
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
EmoteRoomTimelineItem(id: eventItemProxy.id,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -357,7 +357,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ locationMessageContent: LocationContent,
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
LocationRoomTimelineItem(id: eventItemProxy.id,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -410,7 +410,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
return PollRoomTimelineItem(id: eventItemProxy.id,
poll: poll,
body: poll.question,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
@ -424,7 +424,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
private func buildCallInviteTimelineItem(for eventItemProxy: EventTimelineItemProxy) -> RoomTimelineItemProtocol {
CallInviteRoomTimelineItem(id: eventItemProxy.id,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
sender: eventItemProxy.sender)
@ -432,7 +432,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
private func buildCallNotificationTimelineItem(for eventItemProxy: EventTimelineItemProxy) -> RoomTimelineItemProtocol {
CallNotificationRoomTimelineItem(id: eventItemProxy.id,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isEditable: eventItemProxy.isEditable,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
sender: eventItemProxy.sender)
@ -652,7 +652,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
private func buildStateTimelineItem(for eventItemProxy: EventTimelineItemProxy, text: String, isOutgoing: Bool) -> RoomTimelineItemProtocol {
StateRoomTimelineItem(id: eventItemProxy.id,
body: text,
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
timestamp: eventItemProxy.timestamp,
isOutgoing: isOutgoing,
isEditable: false,
canBeRepliedTo: eventItemProxy.canBeRepliedTo,

Some files were not shown because too many files have changed in this diff Show More