mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Update the SDK and use media filename and caption internally. (#3375)
Doesn't render captions (other than in fallback places).
This commit is contained in:
@@ -257,7 +257,7 @@ enum RoomTimelineItemFixtures {
|
||||
canBeRepliedTo: true,
|
||||
isThreaded: false,
|
||||
sender: .init(id: ""),
|
||||
content: .init(body: "video",
|
||||
content: .init(filename: "video.mp4",
|
||||
duration: 100,
|
||||
source: .init(url: .picturesDirectory, mimeType: nil),
|
||||
thumbnailSource: .init(url: .picturesDirectory, mimeType: nil),
|
||||
@@ -272,7 +272,7 @@ enum RoomTimelineItemFixtures {
|
||||
canBeRepliedTo: true,
|
||||
isThreaded: false,
|
||||
sender: .init(id: ""),
|
||||
content: .init(body: "image",
|
||||
content: .init(filename: "image.jpg",
|
||||
source: .init(url: .picturesDirectory, mimeType: nil),
|
||||
thumbnailSource: nil,
|
||||
width: 5120,
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ struct AudioRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Equatable {
|
||||
var properties = RoomTimelineItemProperties()
|
||||
|
||||
var body: String {
|
||||
content.body
|
||||
content.caption ?? content.filename
|
||||
}
|
||||
|
||||
var contentType: EventBasedMessageTimelineItemContentType {
|
||||
|
||||
+5
-1
@@ -9,7 +9,11 @@ import UIKit
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
struct AudioRoomTimelineItemContent: Hashable {
|
||||
let body: String
|
||||
let filename: String
|
||||
var caption: String?
|
||||
var formattedCaption: AttributedString?
|
||||
/// The original textual representation of the formatted caption directly from the event (usually HTML code)
|
||||
var formattedCaptionHTMLString: String?
|
||||
let duration: TimeInterval
|
||||
let waveform: EstimatedWaveform?
|
||||
let source: MediaSourceProxy?
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ struct FileRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Equatable {
|
||||
var properties = RoomTimelineItemProperties()
|
||||
|
||||
var body: String {
|
||||
content.body
|
||||
content.caption ?? content.filename
|
||||
}
|
||||
|
||||
var contentType: EventBasedMessageTimelineItemContentType {
|
||||
|
||||
+5
-1
@@ -9,7 +9,11 @@ import Foundation
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
struct FileRoomTimelineItemContent: Hashable {
|
||||
let body: String
|
||||
let filename: String
|
||||
var caption: String?
|
||||
var formattedCaption: AttributedString?
|
||||
/// The original textual representation of the formatted caption directly from the event (usually HTML code)
|
||||
var formattedCaptionHTMLString: String?
|
||||
let source: MediaSourceProxy?
|
||||
let thumbnailSource: MediaSourceProxy?
|
||||
let contentType: UTType?
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ struct ImageRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Equatable {
|
||||
var properties = RoomTimelineItemProperties()
|
||||
|
||||
var body: String {
|
||||
content.body
|
||||
content.caption ?? content.filename
|
||||
}
|
||||
|
||||
var contentType: EventBasedMessageTimelineItemContentType {
|
||||
|
||||
+5
-1
@@ -9,7 +9,11 @@ import Foundation
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
struct ImageRoomTimelineItemContent: Hashable {
|
||||
let body: String
|
||||
let filename: String
|
||||
var caption: String?
|
||||
var formattedCaption: AttributedString?
|
||||
/// 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?
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ struct VideoRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Equatable {
|
||||
var properties = RoomTimelineItemProperties()
|
||||
|
||||
var body: String {
|
||||
content.body
|
||||
content.caption ?? content.filename
|
||||
}
|
||||
|
||||
var contentType: EventBasedMessageTimelineItemContentType {
|
||||
|
||||
+5
-1
@@ -9,7 +9,11 @@ import Foundation
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
struct VideoRoomTimelineItemContent: Hashable {
|
||||
let body: String
|
||||
let filename: String
|
||||
var caption: String?
|
||||
var formattedCaption: AttributedString?
|
||||
/// 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?
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ struct VoiceMessageRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Equa
|
||||
var properties = RoomTimelineItemProperties()
|
||||
|
||||
var body: String {
|
||||
content.body
|
||||
content.caption ?? content.filename
|
||||
}
|
||||
|
||||
var contentType: EventBasedMessageTimelineItemContentType {
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ struct VoiceMessageRoomTimelineView_Previews: PreviewProvider, TestablePreview {
|
||||
canBeRepliedTo: true,
|
||||
isThreaded: false,
|
||||
sender: .init(id: "Bob"),
|
||||
content: .init(body: "audio.ogg",
|
||||
content: .init(filename: "audio.ogg",
|
||||
duration: 300,
|
||||
waveform: EstimatedWaveform.mockWaveform,
|
||||
source: nil,
|
||||
|
||||
@@ -490,12 +490,18 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
}
|
||||
|
||||
private func buildAudioTimelineItemContent(_ messageContent: AudioMessageContent) -> AudioRoomTimelineItemContent {
|
||||
let htmlCaption = messageContent.formattedCaption?.format == .html ? messageContent.formattedCaption?.body : nil
|
||||
let formattedCaption = htmlCaption != nil ? attributedStringBuilder.fromHTML(htmlCaption) : attributedStringBuilder.fromPlain(messageContent.caption)
|
||||
|
||||
var waveform: EstimatedWaveform?
|
||||
if let audioWaveform = messageContent.audio?.waveform {
|
||||
waveform = EstimatedWaveform(data: audioWaveform)
|
||||
}
|
||||
|
||||
return AudioRoomTimelineItemContent(body: messageContent.body,
|
||||
return AudioRoomTimelineItemContent(filename: messageContent.filename,
|
||||
caption: messageContent.caption,
|
||||
formattedCaption: formattedCaption,
|
||||
formattedCaptionHTMLString: htmlCaption,
|
||||
duration: messageContent.audio?.duration ?? 0,
|
||||
waveform: waveform,
|
||||
source: MediaSourceProxy(source: messageContent.source, mimeType: messageContent.info?.mimetype),
|
||||
@@ -503,6 +509,9 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -512,7 +521,10 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
aspectRatio = width / height
|
||||
}
|
||||
|
||||
return .init(body: messageContent.body,
|
||||
return .init(filename: messageContent.filename,
|
||||
caption: messageContent.caption,
|
||||
formattedCaption: formattedCaption,
|
||||
formattedCaptionHTMLString: htmlCaption,
|
||||
source: MediaSourceProxy(source: messageContent.source, mimeType: messageContent.info?.mimetype),
|
||||
thumbnailSource: thumbnailSource,
|
||||
width: width,
|
||||
@@ -523,6 +535,9 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
}
|
||||
|
||||
private func buildVideoTimelineItemContent(_ messageContent: VideoMessageContent) -> VideoRoomTimelineItemContent {
|
||||
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)
|
||||
@@ -532,7 +547,10 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
aspectRatio = width / height
|
||||
}
|
||||
|
||||
return .init(body: messageContent.body,
|
||||
return .init(filename: messageContent.filename,
|
||||
caption: messageContent.caption,
|
||||
formattedCaption: formattedCaption,
|
||||
formattedCaptionHTMLString: htmlCaption,
|
||||
duration: messageContent.info?.duration ?? 0,
|
||||
source: MediaSourceProxy(source: messageContent.source, mimeType: messageContent.info?.mimetype),
|
||||
thumbnailSource: thumbnailSource,
|
||||
@@ -550,9 +568,15 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||
}
|
||||
|
||||
private func buildFileTimelineItemContent(_ messageContent: FileMessageContent) -> FileRoomTimelineItemContent {
|
||||
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) }
|
||||
|
||||
return .init(body: messageContent.body,
|
||||
return .init(filename: messageContent.filename,
|
||||
caption: messageContent.caption,
|
||||
formattedCaption: formattedCaption,
|
||||
formattedCaptionHTMLString: htmlCaption,
|
||||
source: MediaSourceProxy(source: messageContent.source, mimeType: messageContent.info?.mimetype),
|
||||
thumbnailSource: thumbnailSource,
|
||||
contentType: UTType(mimeType: messageContent.info?.mimetype, fallbackFilename: messageContent.body))
|
||||
|
||||
Reference in New Issue
Block a user