Enable local echoes for media uploads on development builds. (#3514)

* Enable local echoes for media uploads on development builds.
* Use media sizes when loading timeline items so they can take advantage of the cached local echo data.
This commit is contained in:
Stefan Ceriu
2024-11-14 18:33:37 +02:00
committed by GitHub
parent 5aadf4e65b
commit 7e192b7571
14 changed files with 149 additions and 84 deletions
@@ -260,10 +260,9 @@ enum RoomTimelineItemFixtures {
content: .init(filename: "video.mp4",
duration: 100,
source: .init(url: .picturesDirectory, mimeType: nil),
thumbnailSource: .init(url: .picturesDirectory, mimeType: nil),
width: 1920,
height: 1080,
size: .init(width: 1920, height: 1080),
aspectRatio: 1.78,
thumbnailSource: .init(url: .picturesDirectory, mimeType: nil),
blurhash: "KtI~70X5V?yss9oyrYs:t6")),
ImageRoomTimelineItem(id: .randomEvent,
timestamp: "10:47 am",
@@ -274,10 +273,9 @@ enum RoomTimelineItemFixtures {
sender: .init(id: ""),
content: .init(filename: "image.jpg",
source: .init(url: .picturesDirectory, mimeType: nil),
thumbnailSource: nil,
width: 5120,
height: 3412,
size: .init(width: 5120, height: 3412),
aspectRatio: 1.5,
thumbnailSource: nil,
blurhash: "KpE4oyayR5|GbHb];3j@of"))
]
}
@@ -15,10 +15,13 @@ struct ImageRoomTimelineItemContent: Hashable {
/// The original textual representation of the formatted caption directly from the event (usually HTML code)
var formattedCaptionHTMLString: String?
let source: MediaSourceProxy
let thumbnailSource: MediaSourceProxy?
var width: CGFloat?
var height: CGFloat?
var size: CGSize?
var aspectRatio: CGFloat?
let thumbnailSource: MediaSourceProxy?
var thumbnailSize: CGSize?
var thumbnailAspectRatio: CGFloat?
var blurhash: String?
var contentType: UTType?
}
@@ -15,11 +15,15 @@ struct VideoRoomTimelineItemContent: Hashable {
/// The original textual representation of the formatted caption directly from the event (usually HTML code)
var formattedCaptionHTMLString: String?
let duration: TimeInterval
let source: MediaSourceProxy?
let thumbnailSource: MediaSourceProxy?
var width: CGFloat?
var height: CGFloat?
var size: CGSize?
var aspectRatio: CGFloat?
let thumbnailSource: MediaSourceProxy?
var thumbnailSize: CGSize?
var thumbnailAspectRatio: CGFloat?
var blurhash: String?
var contentType: UTType?
}
@@ -19,8 +19,7 @@ struct StickerRoomTimelineItem: EventBasedTimelineItemProtocol, Equatable {
let imageURL: URL
var width: CGFloat?
var height: CGFloat?
var size: CGSize?
var aspectRatio: CGFloat?
var blurhash: String?
@@ -121,11 +121,16 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
_ imageInfo: ImageInfo,
_ imageURL: URL,
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
var aspectRatio: CGFloat?
let width = imageInfo.width.map(CGFloat.init)
let height = imageInfo.height.map(CGFloat.init)
if let width, let height, width > 0, height > 0 {
aspectRatio = width / height
var imageSize: CGSize?
var imageAspectRatio: CGFloat?
if let height = imageInfo.height,
let width = imageInfo.width {
imageSize = .init(width: CGFloat(width), height: CGFloat(height))
if width > 0, height > 0 {
imageAspectRatio = CGFloat(width) / CGFloat(height)
}
}
return StickerRoomTimelineItem(id: eventItemProxy.id,
@@ -136,9 +141,8 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
canBeRepliedTo: eventItemProxy.canBeRepliedTo,
sender: eventItemProxy.sender,
imageURL: imageURL,
width: width,
height: height,
aspectRatio: aspectRatio,
size: imageSize,
aspectRatio: imageAspectRatio,
blurhash: imageInfo.blurhash,
properties: RoomTimelineItemProperties(reactions: aggregateReactions(eventItemProxy.reactions),
deliveryStatus: eventItemProxy.deliveryStatus,
@@ -513,18 +517,37 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
source: MediaSourceProxy(source: messageContent.source, mimeType: messageContent.info?.mimetype),
contentType: UTType(mimeType: messageContent.info?.mimetype, fallbackFilename: messageContent.filename))
}
private func buildImageTimelineItemContent(_ messageContent: ImageMessageContent) -> ImageRoomTimelineItemContent {
let htmlCaption = messageContent.formattedCaption?.format == .html ? messageContent.formattedCaption?.body : nil
let formattedCaption = htmlCaption != nil ? attributedStringBuilder.fromHTML(htmlCaption) : attributedStringBuilder.fromPlain(messageContent.caption)
let thumbnailSource = messageContent.info?.thumbnailSource.map { MediaSourceProxy(source: $0, mimeType: messageContent.info?.thumbnailInfo?.mimetype) }
let width = messageContent.info?.width.map(CGFloat.init)
let height = messageContent.info?.height.map(CGFloat.init)
var aspectRatio: CGFloat?
if let width, let height, width > 0, height > 0 {
aspectRatio = width / height
var thumbnailSize: CGSize?
var thumbnailAspectRatio: CGFloat?
if let thumbnailInfo = messageContent.info?.thumbnailInfo,
let height = thumbnailInfo.height,
let width = thumbnailInfo.width {
thumbnailSize = .init(width: CGFloat(width), height: CGFloat(height))
if width > 0, height > 0 {
thumbnailAspectRatio = CGFloat(width) / CGFloat(height)
}
}
var imageSize: CGSize?
var imageAspectRatio: CGFloat?
if let imageInfo = messageContent.info,
let height = imageInfo.height,
let width = imageInfo.width {
imageSize = .init(width: CGFloat(width), height: CGFloat(height))
if width > 0, height > 0 {
imageAspectRatio = CGFloat(width) / CGFloat(height)
}
}
return .init(filename: messageContent.filename,
@@ -532,10 +555,11 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
formattedCaption: formattedCaption,
formattedCaptionHTMLString: htmlCaption,
source: MediaSourceProxy(source: messageContent.source, mimeType: messageContent.info?.mimetype),
size: imageSize,
aspectRatio: imageAspectRatio,
thumbnailSource: thumbnailSource,
width: width,
height: height,
aspectRatio: aspectRatio,
thumbnailSize: thumbnailSize,
thumbnailAspectRatio: thumbnailAspectRatio,
blurhash: messageContent.info?.blurhash,
contentType: UTType(mimeType: messageContent.info?.mimetype, fallbackFilename: messageContent.filename))
}
@@ -545,12 +569,31 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
let formattedCaption = htmlCaption != nil ? attributedStringBuilder.fromHTML(htmlCaption) : attributedStringBuilder.fromPlain(messageContent.caption)
let thumbnailSource = messageContent.info?.thumbnailSource.map { MediaSourceProxy(source: $0, mimeType: messageContent.info?.thumbnailInfo?.mimetype) }
let width = messageContent.info?.width.map(CGFloat.init)
let height = messageContent.info?.height.map(CGFloat.init)
var thumbnailSize: CGSize?
var thumbnailAspectRatio: CGFloat?
var aspectRatio: CGFloat?
if let width, let height, width > 0, height > 0 {
aspectRatio = width / height
if let thumbnailInfo = messageContent.info?.thumbnailInfo,
let height = thumbnailInfo.height,
let width = thumbnailInfo.width {
thumbnailSize = .init(width: CGFloat(width), height: CGFloat(height))
if width > 0, height > 0 {
thumbnailAspectRatio = CGFloat(width) / CGFloat(height)
}
}
var videoSize: CGSize?
var videoAspectRatio: CGFloat?
if let videoInfo = messageContent.info,
let height = videoInfo.height,
let width = videoInfo.width {
videoSize = .init(width: CGFloat(width), height: CGFloat(height))
if width > 0, height > 0 {
videoAspectRatio = CGFloat(width) / CGFloat(height)
}
}
return .init(filename: messageContent.filename,
@@ -559,10 +602,11 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
formattedCaptionHTMLString: htmlCaption,
duration: messageContent.info?.duration ?? 0,
source: MediaSourceProxy(source: messageContent.source, mimeType: messageContent.info?.mimetype),
size: videoSize,
aspectRatio: videoAspectRatio,
thumbnailSource: thumbnailSource,
width: width,
height: height,
aspectRatio: aspectRatio,
thumbnailSize: thumbnailSize,
thumbnailAspectRatio: thumbnailAspectRatio,
blurhash: messageContent.info?.blurhash,
contentType: UTType(mimeType: messageContent.info?.mimetype, fallbackFilename: messageContent.filename))
}
@@ -234,7 +234,7 @@ final class TimelineProxy: TimelineProxyProtocol {
progressWatcher: UploadProgressListener { progress in
progressSubject?.send(progress)
},
useSendQueue: false)
useSendQueue: AppSettings.isDevelopmentBuild)
await requestHandle(handle)
@@ -260,7 +260,7 @@ final class TimelineProxy: TimelineProxyProtocol {
progressWatcher: UploadProgressListener { progress in
progressSubject?.send(progress)
},
useSendQueue: false)
useSendQueue: AppSettings.isDevelopmentBuild)
await requestHandle(handle)
@@ -290,7 +290,7 @@ final class TimelineProxy: TimelineProxyProtocol {
progressWatcher: UploadProgressListener { progress in
progressSubject?.send(progress)
},
useSendQueue: false)
useSendQueue: AppSettings.isDevelopmentBuild)
await requestHandle(handle)
@@ -338,7 +338,7 @@ final class TimelineProxy: TimelineProxyProtocol {
progressWatcher: UploadProgressListener { progress in
progressSubject?.send(progress)
},
useSendQueue: false)
useSendQueue: AppSettings.isDevelopmentBuild)
await requestHandle(handle)
@@ -368,7 +368,7 @@ final class TimelineProxy: TimelineProxyProtocol {
progressWatcher: UploadProgressListener { progress in
progressSubject?.send(progress)
},
useSendQueue: false)
useSendQueue: AppSettings.isDevelopmentBuild)
await requestHandle(handle)