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

Group image and video metadata in specialised structs #3518

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ struct MessageComposer_Previews: PreviewProvider, TestablePreview {
eventID: "123",
eventContent: .message(.image(.init(filename: "head.png",
caption: "Image: Pushead",
source: .init(url: .picturesDirectory, mimeType: nil),
thumbnailSource: .init(url: .picturesDirectory, mimeType: nil))))),
imageInfo: .mockImage,
thumbnailInfo: .mockThumbnail)))),
.loaded(sender: .init(id: "Jason"),
eventID: "123",
eventContent: .message(.notice(.init(body: "Notice: Too far gone?")))),
Expand All @@ -238,9 +238,8 @@ struct MessageComposer_Previews: PreviewProvider, TestablePreview {
eventID: "123",
eventContent: .message(.video(.init(filename: "never.mov",
caption: "Video: Through the never",
duration: 100,
source: nil,
thumbnailSource: .init(url: .picturesDirectory, mimeType: nil))))),
videoInfo: .mockVideo,
thumbnailInfo: .mockThumbnail)))),
.loading(eventID: "")
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,11 @@ class TimelineInteractionHandler {

switch timelineItem {
case let item as ImageRoomTimelineItem:
source = item.content.source
source = item.content.imageInfo.source
filename = item.content.filename
caption = item.content.caption
case let item as VideoRoomTimelineItem:
source = item.content.source
source = item.content.videoInfo.source
filename = item.content.filename
caption = item.content.caption
case let item as FileRoomTimelineItem:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct TimelineReplyView: View {
ReplyView(sender: sender,
plainBody: content.caption ?? content.filename,
formattedBody: content.formattedCaption,
icon: .init(kind: .mediaSource(content.thumbnailSource ?? content.source), cornerRadii: iconCornerRadii))
icon: .init(kind: .mediaSource(content.thumbnailInfo?.source ?? content.imageInfo.source), cornerRadii: iconCornerRadii))
case .notice(let content):
ReplyView(sender: sender,
plainBody: content.body,
Expand All @@ -55,7 +55,7 @@ struct TimelineReplyView: View {
ReplyView(sender: sender,
plainBody: content.caption ?? content.filename,
formattedBody: content.formattedCaption,
icon: content.thumbnailSource.map { .init(kind: .mediaSource($0), cornerRadii: iconCornerRadii) })
icon: content.thumbnailInfo.map { .init(kind: .mediaSource($0.source), cornerRadii: iconCornerRadii) })
case .voice:
ReplyView(sender: sender,
plainBody: L10n.commonVoiceMessage,
Expand Down Expand Up @@ -222,9 +222,7 @@ struct TimelineReplyView_Previews: PreviewProvider, TestablePreview {
}()

static var previewItems: [TimelineReplyView] {
let imageSource = MediaSourceProxy(url: "https://mock.com", mimeType: "image/png")

return [
[
TimelineReplyView(placement: .timeline, timelineItemReplyDetails: .notLoaded(eventID: "")),

TimelineReplyView(placement: .timeline, timelineItemReplyDetails: .loading(eventID: "")),
Expand Down Expand Up @@ -268,17 +266,16 @@ struct TimelineReplyView_Previews: PreviewProvider, TestablePreview {
eventID: "123",
eventContent: .message(.image(.init(filename: "image.jpg",
caption: "Some image",
source: imageSource,
thumbnailSource: imageSource))))),
imageInfo: .mockImage,
thumbnailInfo: .mockThumbnail))))),

TimelineReplyView(placement: .timeline,
timelineItemReplyDetails: .loaded(sender: .init(id: "", displayName: "Alice"),
eventID: "123",
eventContent: .message(.video(.init(filename: "video.mp4",
caption: "Some video",
duration: 0,
source: nil,
thumbnailSource: imageSource))))),
videoInfo: .mockVideo,
thumbnailInfo: .mockThumbnail))))),
TimelineReplyView(placement: .timeline,
timelineItemReplyDetails: .loaded(sender: .init(id: "", displayName: "Alice"),
eventID: "123",
Expand Down Expand Up @@ -321,7 +318,7 @@ struct TimelineReplyView_Previews: PreviewProvider, TestablePreview {
}
.padding()
.environmentObject(viewModel.context)
// Allow member names to load. Reduce precission as the `imageSource` randomly renders slightly differently
// Allow member names to load. Reduce precission as the `mockThumbnail` randomly renders slightly differently
.snapshotPreferences(delay: 0.2, precision: 0.98)
.previewLayout(.sizeThatFits)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
isThreaded: false,
sender: .init(id: "Bob"),
content: .init(filename: "other.png",
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/png"),
thumbnailSource: nil),
imageInfo: .mockImage,
thumbnailInfo: nil),

properties: RoomTimelineItemProperties(encryptionAuthenticity: .notGuaranteed(color: .gray))))

Expand Down Expand Up @@ -577,8 +577,8 @@ private struct MockTimelineContent: View {
isThreaded: isThreaded,
sender: .init(id: ""),
content: .init(filename: "image.jpg",
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/png"),
thumbnailSource: nil),
imageInfo: .mockImage,
thumbnailInfo: nil),
replyDetails: replyDetails))

LocationRoomTimelineView(timelineItem: .init(id: makeItemIdentifier(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ struct ImageRoomTimelineView: View {
@ViewBuilder
private var loadableImage: some View {
if timelineItem.content.contentType == .gif {
LoadableImage(mediaSource: timelineItem.content.source,
LoadableImage(mediaSource: timelineItem.content.imageInfo.source,
mediaType: .timelineItem,
blurhash: timelineItem.content.blurhash,
size: timelineItem.content.size,
size: timelineItem.content.imageInfo.size,
mediaProvider: context.mediaProvider) {
placeholder
}
.timelineMediaFrame(height: timelineItem.content.thumbnailSize?.height,
aspectRatio: timelineItem.content.aspectRatio)
.timelineMediaFrame(height: timelineItem.content.imageInfo.size?.height,
aspectRatio: timelineItem.content.imageInfo.aspectRatio)
} else {
LoadableImage(mediaSource: timelineItem.content.thumbnailSource ?? timelineItem.content.source,
LoadableImage(mediaSource: timelineItem.content.thumbnailInfo?.source ?? timelineItem.content.imageInfo.source,
mediaType: .timelineItem,
blurhash: timelineItem.content.blurhash,
size: timelineItem.content.thumbnailSize ?? timelineItem.content.size,
size: timelineItem.content.thumbnailInfo?.size ?? timelineItem.content.imageInfo.size,
mediaProvider: context.mediaProvider) {
placeholder
}
.timelineMediaFrame(height: timelineItem.content.thumbnailSize?.height ?? timelineItem.content.size?.height,
aspectRatio: timelineItem.content.thumbnailAspectRatio ?? timelineItem.content.aspectRatio)
.timelineMediaFrame(height: timelineItem.content.thumbnailInfo?.size?.height ?? timelineItem.content.imageInfo.size?.height,
aspectRatio: timelineItem.content.thumbnailInfo?.aspectRatio ?? timelineItem.content.imageInfo.aspectRatio)
}
}

Expand Down Expand Up @@ -87,8 +87,8 @@ struct ImageRoomTimelineView_Previews: PreviewProvider, TestablePreview {
isThreaded: false,
sender: .init(id: "Bob"),
content: .init(filename: "image.jpg",
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/jpg"),
thumbnailSource: nil)))
imageInfo: .mockImage,
thumbnailInfo: nil)))

ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
Expand All @@ -98,8 +98,8 @@ struct ImageRoomTimelineView_Previews: PreviewProvider, TestablePreview {
isThreaded: false,
sender: .init(id: "Bob"),
content: .init(filename: "other.png",
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/png"),
thumbnailSource: nil)))
imageInfo: .mockImage,
thumbnailInfo: nil)))

ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: .randomEvent,
timestamp: "Now",
Expand All @@ -109,9 +109,8 @@ struct ImageRoomTimelineView_Previews: PreviewProvider, TestablePreview {
isThreaded: false,
sender: .init(id: "Bob"),
content: .init(filename: "Blurhashed.jpg",
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/gif"),
aspectRatio: 0.7,
thumbnailSource: nil,
imageInfo: .mockImage,
thumbnailInfo: nil,
blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW",
contentType: .gif)))

Expand All @@ -124,10 +123,8 @@ struct ImageRoomTimelineView_Previews: PreviewProvider, TestablePreview {
sender: .init(id: "Bob"),
content: .init(filename: "Blurhashed.jpg",
caption: "This is a great image 😎",
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/png"),
size: .init(width: 50, height: 50),
aspectRatio: 1,
thumbnailSource: nil,
imageInfo: .mockImage,
thumbnailInfo: .mockThumbnail,
blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW",
contentType: .gif)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ struct StickerRoomTimelineView: View {

var body: some View {
TimelineStyler(timelineItem: timelineItem) {
LoadableImage(url: timelineItem.imageURL,
LoadableImage(url: timelineItem.imageInfo.source.url,
mediaType: .timelineItem,
blurhash: timelineItem.blurhash,
size: timelineItem.size,
size: timelineItem.imageInfo.size,
mediaProvider: context.mediaProvider) {
placeholder
}
.timelineMediaFrame(height: timelineItem.size?.height,
aspectRatio: timelineItem.aspectRatio)
.timelineMediaFrame(height: timelineItem.imageInfo.size?.height,
aspectRatio: timelineItem.imageInfo.aspectRatio)
.accessibilityElement(children: .ignore)
.accessibilityLabel("\(L10n.commonSticker), \(timelineItem.body)")
}
Expand Down Expand Up @@ -51,7 +51,7 @@ struct StickerRoomTimelineView_Previews: PreviewProvider, TestablePreview {
isEditable: false,
canBeRepliedTo: true,
sender: .init(id: "Bob"),
imageURL: URL.picturesDirectory))
imageInfo: .mockImage))

StickerRoomTimelineView(timelineItem: StickerRoomTimelineItem(id: .randomEvent,
body: "Some other image",
Expand All @@ -60,7 +60,7 @@ struct StickerRoomTimelineView_Previews: PreviewProvider, TestablePreview {
isEditable: false,
canBeRepliedTo: true,
sender: .init(id: "Bob"),
imageURL: URL.picturesDirectory))
imageInfo: .mockImage))

StickerRoomTimelineView(timelineItem: StickerRoomTimelineItem(id: .randomEvent,
body: "Blurhashed image",
Expand All @@ -69,8 +69,7 @@ struct StickerRoomTimelineView_Previews: PreviewProvider, TestablePreview {
isEditable: false,
canBeRepliedTo: true,
sender: .init(id: "Bob"),
imageURL: URL.picturesDirectory,
aspectRatio: 0.7,
imageInfo: .mockImage,
blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW"))
}
}
Expand Down
Loading
Loading