mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Reply rendering (#861)
* Cleanup how we use message timeline items in preparation for rich reply rendering * Expose reply details up to the UI level * Render replies in the timeline (textual for now). Remove now unused AttributedStringBuilderComponent isReply flag. * Move reply detail loading to when the item appears instead of when it's created. * Fix unit tests * Fetch event details also when the reply details are in the error state * Tweaks following code review * Localise emote bodies * Fix replies not loading sometimes, use the current event identifier instead of the one being replied to
This commit is contained in:
@@ -62,6 +62,7 @@
|
|||||||
"common_developer_options" = "Developer options";
|
"common_developer_options" = "Developer options";
|
||||||
"common_edited_suffix" = "(edited)";
|
"common_edited_suffix" = "(edited)";
|
||||||
"common_editing" = "Editing";
|
"common_editing" = "Editing";
|
||||||
|
"common_emote" = "* %1$@ %2$@";
|
||||||
"common_encryption_enabled" = "Encryption enabled";
|
"common_encryption_enabled" = "Encryption enabled";
|
||||||
"common_error" = "Error";
|
"common_error" = "Error";
|
||||||
"common_file" = "File";
|
"common_file" = "File";
|
||||||
|
|||||||
@@ -138,6 +138,10 @@ public enum L10n {
|
|||||||
public static var commonEditedSuffix: String { return L10n.tr("Localizable", "common_edited_suffix") }
|
public static var commonEditedSuffix: String { return L10n.tr("Localizable", "common_edited_suffix") }
|
||||||
/// Editing
|
/// Editing
|
||||||
public static var commonEditing: String { return L10n.tr("Localizable", "common_editing") }
|
public static var commonEditing: String { return L10n.tr("Localizable", "common_editing") }
|
||||||
|
/// * %1$@ %2$@
|
||||||
|
public static func commonEmote(_ p1: Any, _ p2: Any) -> String {
|
||||||
|
return L10n.tr("Localizable", "common_emote", String(describing: p1), String(describing: p2))
|
||||||
|
}
|
||||||
/// Encryption enabled
|
/// Encryption enabled
|
||||||
public static var commonEncryptionEnabled: String { return L10n.tr("Localizable", "common_encryption_enabled") }
|
public static var commonEncryptionEnabled: String { return L10n.tr("Localizable", "common_encryption_enabled") }
|
||||||
/// Error
|
/// Error
|
||||||
|
|||||||
@@ -838,6 +838,22 @@ class RoomProxyMock: RoomProxyProtocol {
|
|||||||
return acceptInvitationReturnValue
|
return acceptInvitationReturnValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//MARK: - fetchDetails
|
||||||
|
|
||||||
|
var fetchDetailsForCallsCount = 0
|
||||||
|
var fetchDetailsForCalled: Bool {
|
||||||
|
return fetchDetailsForCallsCount > 0
|
||||||
|
}
|
||||||
|
var fetchDetailsForReceivedEventID: String?
|
||||||
|
var fetchDetailsForReceivedInvocations: [String] = []
|
||||||
|
var fetchDetailsForClosure: ((String) -> Void)?
|
||||||
|
|
||||||
|
func fetchDetails(for eventID: String) {
|
||||||
|
fetchDetailsForCallsCount += 1
|
||||||
|
fetchDetailsForReceivedEventID = eventID
|
||||||
|
fetchDetailsForReceivedInvocations.append(eventID)
|
||||||
|
fetchDetailsForClosure?(eventID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
class SessionVerificationControllerProxyMock: SessionVerificationControllerProxyProtocol {
|
class SessionVerificationControllerProxyMock: SessionVerificationControllerProxyProtocol {
|
||||||
var callbacks: PassthroughSubject<SessionVerificationControllerProxyCallback, Never> {
|
var callbacks: PassthroughSubject<SessionVerificationControllerProxyCallback, Never> {
|
||||||
|
|||||||
@@ -28,10 +28,8 @@ extension AttributedString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let isBlockquote = value != nil
|
let isBlockquote = value != nil
|
||||||
/// This is a temporary workaround until replies are retrieved from the SDK.
|
|
||||||
let isReply = isBlockquote && attributedString.characters.starts(with: "In reply to @")
|
|
||||||
|
|
||||||
return AttributedStringBuilderComponent(attributedString: attributedString, isBlockquote: isBlockquote, isReply: isReply)
|
return AttributedStringBuilderComponent(attributedString: attributedString, isBlockquote: isBlockquote)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import Foundation
|
|||||||
struct AttributedStringBuilderComponent: Hashable {
|
struct AttributedStringBuilderComponent: Hashable {
|
||||||
let attributedString: AttributedString
|
let attributedString: AttributedString
|
||||||
let isBlockquote: Bool
|
let isBlockquote: Bool
|
||||||
let isReply: Bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol AttributedStringBuilderProtocol {
|
protocol AttributedStringBuilderProtocol {
|
||||||
|
|||||||
@@ -257,10 +257,12 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
}
|
}
|
||||||
|
|
||||||
var actions: [TimelineItemContextMenuAction] = [
|
var actions: [TimelineItemContextMenuAction] = [
|
||||||
.react, .copy, .reply
|
.react, .reply, .copyPermalink
|
||||||
// Disabled for FOSDEM
|
|
||||||
// .quote, .copyPermalink
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if timelineItem is EventBasedMessageTimelineItemProtocol {
|
||||||
|
actions.append(contentsOf: [.copy, .quote])
|
||||||
|
}
|
||||||
|
|
||||||
if item.isEditable {
|
if item.isEditable {
|
||||||
actions.append(.edit)
|
actions.append(.edit)
|
||||||
@@ -282,28 +284,40 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
return .init(actions: actions, debugActions: debugActions)
|
return .init(actions: actions, debugActions: debugActions)
|
||||||
}
|
}
|
||||||
|
|
||||||
// swiftlint:disable:next cyclomatic_complexity
|
// swiftlint:disable:next cyclomatic_complexity function_body_length
|
||||||
private func processContentMenuAction(_ action: TimelineItemContextMenuAction, itemID: String) {
|
private func processContentMenuAction(_ action: TimelineItemContextMenuAction, itemID: String) {
|
||||||
guard let timelineItem = timelineController.timelineItems.first(where: { $0.id == itemID }),
|
guard let timelineItem = timelineController.timelineItems.first(where: { $0.id == itemID }),
|
||||||
let item = timelineItem as? EventBasedTimelineItemProtocol else {
|
let eventTimelineItem = timelineItem as? EventBasedTimelineItemProtocol else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch action {
|
switch action {
|
||||||
case .react:
|
case .react:
|
||||||
callback?(.displayEmojiPicker(itemID: item.id))
|
callback?(.displayEmojiPicker(itemID: eventTimelineItem.id))
|
||||||
case .copy:
|
case .copy:
|
||||||
UIPasteboard.general.string = item.body
|
guard let messageTimelineItem = timelineItem as? EventBasedMessageTimelineItemProtocol else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
UIPasteboard.general.string = messageTimelineItem.body
|
||||||
case .edit:
|
case .edit:
|
||||||
|
guard let messageTimelineItem = timelineItem as? EventBasedMessageTimelineItemProtocol else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
state.bindings.composerFocused = true
|
state.bindings.composerFocused = true
|
||||||
state.bindings.composerText = item.body
|
state.bindings.composerText = messageTimelineItem.body
|
||||||
state.composerMode = .edit(originalItemId: item.id)
|
state.composerMode = .edit(originalItemId: messageTimelineItem.id)
|
||||||
case .quote:
|
case .quote:
|
||||||
|
guard let messageTimelineItem = timelineItem as? EventBasedMessageTimelineItemProtocol else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
state.bindings.composerFocused = true
|
state.bindings.composerFocused = true
|
||||||
state.bindings.composerText = "> \(item.body)"
|
state.bindings.composerText = "> \(messageTimelineItem.body)\n\n"
|
||||||
case .copyPermalink:
|
case .copyPermalink:
|
||||||
do {
|
do {
|
||||||
let permalink = try PermalinkBuilder.permalinkTo(eventIdentifier: item.id, roomIdentifier: timelineController.roomID)
|
let permalink = try PermalinkBuilder.permalinkTo(eventIdentifier: eventTimelineItem.id, roomIdentifier: timelineController.roomID)
|
||||||
UIPasteboard.general.url = permalink
|
UIPasteboard.general.url = permalink
|
||||||
} catch {
|
} catch {
|
||||||
displayError(.alert(L10n.errorFailedCreatingThePermalink))
|
displayError(.alert(L10n.errorFailedCreatingThePermalink))
|
||||||
@@ -314,9 +328,9 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
}
|
}
|
||||||
case .reply:
|
case .reply:
|
||||||
state.bindings.composerFocused = true
|
state.bindings.composerFocused = true
|
||||||
state.composerMode = .reply(id: item.id, displayName: item.sender.displayName ?? item.sender.id)
|
state.composerMode = .reply(id: eventTimelineItem.id, displayName: eventTimelineItem.sender.displayName ?? eventTimelineItem.sender.id)
|
||||||
case .viewSource:
|
case .viewSource:
|
||||||
let debugInfo = timelineController.debugInfo(for: item.id)
|
let debugInfo = timelineController.debugInfo(for: eventTimelineItem.id)
|
||||||
MXLog.info(debugInfo)
|
MXLog.info(debugInfo)
|
||||||
state.bindings.debugInfo = debugInfo
|
state.bindings.debugInfo = debugInfo
|
||||||
case .retryDecryption(let sessionID):
|
case .retryDecryption(let sessionID):
|
||||||
@@ -324,7 +338,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
await timelineController.retryDecryption(for: sessionID)
|
await timelineController.retryDecryption(for: sessionID)
|
||||||
}
|
}
|
||||||
case .report:
|
case .report:
|
||||||
callback?(.displayReportContent(itemID: itemID, senderID: item.sender.id))
|
callback?(.displayReportContent(itemID: itemID, senderID: eventTimelineItem.sender.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
if action.switchToDefaultComposer {
|
if action.switchToDefaultComposer {
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2023 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct TimelineReplyView: View {
|
||||||
|
let timelineItemReplyDetails: TimelineItemReplyDetails?
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if let timelineItemReplyDetails {
|
||||||
|
switch timelineItemReplyDetails {
|
||||||
|
case .loaded(let sender, let content):
|
||||||
|
switch content {
|
||||||
|
case .audio(let content):
|
||||||
|
TimelineTextReplyView(attributedText: attributedString(for: sender, body: content.body, formattedBody: nil))
|
||||||
|
case .emote(let content):
|
||||||
|
TimelineTextReplyView(attributedText: attributedString(for: sender, body: content.body, formattedBody: content.formattedBody))
|
||||||
|
case .file(let content):
|
||||||
|
TimelineTextReplyView(attributedText: attributedString(for: sender, body: content.body, formattedBody: nil))
|
||||||
|
case .image(let content):
|
||||||
|
TimelineTextReplyView(attributedText: attributedString(for: sender, body: content.body, formattedBody: nil))
|
||||||
|
case .notice(let content):
|
||||||
|
TimelineTextReplyView(attributedText: attributedString(for: sender, body: content.body, formattedBody: content.formattedBody))
|
||||||
|
case .text(let content):
|
||||||
|
TimelineTextReplyView(attributedText: attributedString(for: sender, body: content.body, formattedBody: content.formattedBody))
|
||||||
|
case .video(let content):
|
||||||
|
TimelineTextReplyView(attributedText: attributedString(for: sender, body: content.body, formattedBody: nil))
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
Text("Missing in-reply-to details")
|
||||||
|
.font(.compound.bodyMD)
|
||||||
|
.foregroundColor(.element.secondaryContent)
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func attributedString(for sender: TimelineItemSender, body: String, formattedBody: AttributedString?) -> AttributedString {
|
||||||
|
var attributedHeading = AttributedString("\(sender.displayName ?? sender.id)\n")
|
||||||
|
attributedHeading.font = .compound.bodyMD.bold()
|
||||||
|
attributedHeading.foregroundColor = .element.primaryContent
|
||||||
|
|
||||||
|
var formattedBody = formattedBody ?? AttributedString(body)
|
||||||
|
formattedBody.font = .compound.bodyMD
|
||||||
|
formattedBody.foregroundColor = .element.secondaryContent
|
||||||
|
|
||||||
|
attributedHeading += formattedBody
|
||||||
|
|
||||||
|
return attributedHeading
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct TimelineTextReplyView: View {
|
||||||
|
let attributedText: AttributedString
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
FormattedBodyText(attributedString: attributedText)
|
||||||
|
.lineLimit(3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -102,13 +102,13 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
|||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
var styledContent: some View {
|
var styledContent: some View {
|
||||||
if shouldAvoidBubbling {
|
if shouldAvoidBubbling {
|
||||||
content()
|
contentWithReply
|
||||||
.bubbleStyle(inset: false,
|
.bubbleStyle(inset: false,
|
||||||
cornerRadius: cornerRadius,
|
cornerRadius: cornerRadius,
|
||||||
corners: roundedCorners)
|
corners: roundedCorners)
|
||||||
} else {
|
} else {
|
||||||
VStack(alignment: .trailing, spacing: 4) {
|
VStack(alignment: .trailing, spacing: 4) {
|
||||||
content()
|
contentWithReply
|
||||||
|
|
||||||
if timelineItem.properties.isEdited {
|
if timelineItem.properties.isEdited {
|
||||||
Text(L10n.commonEditedSuffix)
|
Text(L10n.commonEditedSuffix)
|
||||||
@@ -123,6 +123,20 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
var contentWithReply: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 4.0) {
|
||||||
|
if let messageTimelineItem = timelineItem as? EventBasedMessageTimelineItemProtocol,
|
||||||
|
let replyDetails = messageTimelineItem.replyDetails {
|
||||||
|
TimelineReplyView(timelineItemReplyDetails: replyDetails)
|
||||||
|
.background(Color.element.background)
|
||||||
|
.cornerRadius(8)
|
||||||
|
}
|
||||||
|
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var messageBubbleTopPadding: CGFloat {
|
private var messageBubbleTopPadding: CGFloat {
|
||||||
guard timelineItem.isOutgoing else { return 0 }
|
guard timelineItem.isOutgoing else { return 0 }
|
||||||
return timelineGroupStyle == .single || timelineGroupStyle == .first ? 8 : 0
|
return timelineGroupStyle == .single || timelineGroupStyle == .first ? 8 : 0
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ struct TimelineItemPlainStylerView<Content: View>: View {
|
|||||||
|
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
HStack(alignment: .firstTextBaseline) {
|
HStack(alignment: .firstTextBaseline) {
|
||||||
content()
|
contentWithReply
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
@@ -42,7 +42,24 @@ struct TimelineItemPlainStylerView<Content: View>: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
var contentWithReply: some View {
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
if let messageTimelineItem = timelineItem as? EventBasedMessageTimelineItemProtocol,
|
||||||
|
let replyDetails = messageTimelineItem.replyDetails {
|
||||||
|
HStack(spacing: 4.0) {
|
||||||
|
Rectangle()
|
||||||
|
.foregroundColor(.element.accent)
|
||||||
|
.frame(width: 4.0)
|
||||||
|
TimelineReplyView(timelineItemReplyDetails: replyDetails)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var header: some View {
|
private var header: some View {
|
||||||
if shouldShowSenderDetails {
|
if shouldShowSenderDetails {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ struct AudioRoomTimelineView: View {
|
|||||||
HStack {
|
HStack {
|
||||||
Image(systemName: "waveform")
|
Image(systemName: "waveform")
|
||||||
.foregroundColor(.element.primaryContent)
|
.foregroundColor(.element.primaryContent)
|
||||||
FormattedBodyText(text: timelineItem.body)
|
FormattedBodyText(text: timelineItem.content.body)
|
||||||
}
|
}
|
||||||
.padding(.vertical, 12)
|
.padding(.vertical, 12)
|
||||||
.padding(.horizontal, 6)
|
.padding(.horizontal, 6)
|
||||||
@@ -35,20 +35,18 @@ struct AudioRoomTimelineView: View {
|
|||||||
|
|
||||||
struct AudioRoomTimelineView_Previews: PreviewProvider {
|
struct AudioRoomTimelineView_Previews: PreviewProvider {
|
||||||
static let viewModel = RoomScreenViewModel.mock
|
static let viewModel = RoomScreenViewModel.mock
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
body.environmentObject(viewModel.context)
|
body.environmentObject(viewModel.context)
|
||||||
body.timelineStyle(.plain).environmentObject(viewModel.context)
|
body.timelineStyle(.plain).environmentObject(viewModel.context)
|
||||||
}
|
}
|
||||||
|
|
||||||
static var body: some View {
|
static var body: some View {
|
||||||
AudioRoomTimelineView(timelineItem: AudioRoomTimelineItem(id: UUID().uuidString,
|
AudioRoomTimelineView(timelineItem: AudioRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "audio.ogg",
|
|
||||||
timestamp: "Now",
|
timestamp: "Now",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "Bob"),
|
sender: .init(id: "Bob"),
|
||||||
duration: 300,
|
content: .init(body: "audio.ogg", duration: 300, source: nil, contentType: nil)))
|
||||||
source: nil))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ struct EmoteRoomTimelineView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
TimelineStyler(timelineItem: timelineItem) {
|
TimelineStyler(timelineItem: timelineItem) {
|
||||||
if let attributedString = timelineItem.formattedBody {
|
if let attributedString = timelineItem.content.formattedBody {
|
||||||
FormattedBodyText(attributedString: attributedString)
|
FormattedBodyText(attributedString: attributedString)
|
||||||
} else {
|
} else {
|
||||||
FormattedBodyText(text: timelineItem.body)
|
FormattedBodyText(text: timelineItem.content.body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,10 +53,10 @@ struct EmoteRoomTimelineView_Previews: PreviewProvider {
|
|||||||
|
|
||||||
private static func itemWith(text: String, timestamp: String, senderId: String) -> EmoteRoomTimelineItem {
|
private static func itemWith(text: String, timestamp: String, senderId: String) -> EmoteRoomTimelineItem {
|
||||||
EmoteRoomTimelineItem(id: UUID().uuidString,
|
EmoteRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: text,
|
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: senderId))
|
sender: .init(id: senderId),
|
||||||
|
content: .init(body: text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ struct FileRoomTimelineView: View {
|
|||||||
HStack {
|
HStack {
|
||||||
Image(systemName: "doc.text.fill")
|
Image(systemName: "doc.text.fill")
|
||||||
.foregroundColor(.element.primaryContent)
|
.foregroundColor(.element.primaryContent)
|
||||||
FormattedBodyText(text: timelineItem.body)
|
FormattedBodyText(text: timelineItem.content.body)
|
||||||
}
|
}
|
||||||
.padding(.vertical, 12)
|
.padding(.vertical, 12)
|
||||||
.padding(.horizontal, 6)
|
.padding(.horizontal, 6)
|
||||||
@@ -44,31 +44,25 @@ struct FileRoomTimelineView_Previews: PreviewProvider {
|
|||||||
static var body: some View {
|
static var body: some View {
|
||||||
VStack(spacing: 20.0) {
|
VStack(spacing: 20.0) {
|
||||||
FileRoomTimelineView(timelineItem: FileRoomTimelineItem(id: UUID().uuidString,
|
FileRoomTimelineView(timelineItem: FileRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "document.pdf",
|
|
||||||
timestamp: "Now",
|
timestamp: "Now",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "Bob"),
|
sender: .init(id: "Bob"),
|
||||||
source: nil,
|
content: .init(body: "document.pdf", source: nil, thumbnailSource: nil, contentType: nil)))
|
||||||
thumbnailSource: nil))
|
|
||||||
|
|
||||||
FileRoomTimelineView(timelineItem: FileRoomTimelineItem(id: UUID().uuidString,
|
FileRoomTimelineView(timelineItem: FileRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "document.docx",
|
|
||||||
timestamp: "Now",
|
timestamp: "Now",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "Bob"),
|
sender: .init(id: "Bob"),
|
||||||
source: nil,
|
content: .init(body: "document.docx", source: nil, thumbnailSource: nil, contentType: nil)))
|
||||||
thumbnailSource: nil))
|
|
||||||
|
|
||||||
FileRoomTimelineView(timelineItem: FileRoomTimelineItem(id: UUID().uuidString,
|
FileRoomTimelineView(timelineItem: FileRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "document.txt",
|
|
||||||
timestamp: "Now",
|
timestamp: "Now",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "Bob"),
|
sender: .init(id: "Bob"),
|
||||||
source: nil,
|
content: .init(body: "document.txt", source: nil, thumbnailSource: nil, contentType: nil)))
|
||||||
thumbnailSource: nil))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ struct FormattedBodyText: View {
|
|||||||
// The rendered blockquote with a greedy width. The custom layout prevents the
|
// The rendered blockquote with a greedy width. The custom layout prevents the
|
||||||
// infinite width from increasing the overall width of the view.
|
// infinite width from increasing the overall width of the view.
|
||||||
Text(component.attributedString.mergingAttributes(blockquoteAttributes))
|
Text(component.attributedString.mergingAttributes(blockquoteAttributes))
|
||||||
.blockquoteFormatting(isReply: component.isReply)
|
.blockquoteFormatting()
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
.background(Color.element.background)
|
.background(Color.element.background)
|
||||||
.cornerRadius(8)
|
.cornerRadius(8)
|
||||||
@@ -119,7 +119,7 @@ struct FormattedBodyText: View {
|
|||||||
ForEach(attributedComponents, id: \.self) { component in
|
ForEach(attributedComponents, id: \.self) { component in
|
||||||
if component.isBlockquote {
|
if component.isBlockquote {
|
||||||
Text(component.attributedString.mergingAttributes(blockquoteAttributes))
|
Text(component.attributedString.mergingAttributes(blockquoteAttributes))
|
||||||
.blockquoteFormatting(isReply: component.isReply)
|
.blockquoteFormatting()
|
||||||
.layoutPriority(LayoutPriority.hiddenBlockquote)
|
.layoutPriority(LayoutPriority.hiddenBlockquote)
|
||||||
.hidden()
|
.hidden()
|
||||||
}
|
}
|
||||||
@@ -164,9 +164,8 @@ extension FormattedBodyText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private extension View {
|
private extension View {
|
||||||
func blockquoteFormatting(isReply: Bool) -> some View {
|
func blockquoteFormatting() -> some View {
|
||||||
lineLimit(isReply ? 3 : nil)
|
foregroundColor(.element.tertiaryContent)
|
||||||
.foregroundColor(.element.tertiaryContent)
|
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
.fixedSize(horizontal: false, vertical: true)
|
||||||
.padding(EdgeInsets(top: 4, leading: 12, bottom: 4, trailing: 12))
|
.padding(EdgeInsets(top: 4, leading: 12, bottom: 4, trailing: 12))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,16 +23,24 @@ struct ImageRoomTimelineView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
TimelineStyler(timelineItem: timelineItem) {
|
TimelineStyler(timelineItem: timelineItem) {
|
||||||
LoadableImage(mediaSource: timelineItem.source,
|
LoadableImage(mediaSource: source,
|
||||||
blurhash: timelineItem.blurhash,
|
blurhash: timelineItem.content.blurhash,
|
||||||
imageProvider: context.imageProvider) {
|
imageProvider: context.imageProvider) {
|
||||||
placeholder
|
placeholder
|
||||||
}
|
}
|
||||||
.frame(maxHeight: min(300, max(100, timelineItem.height ?? .infinity)))
|
.frame(maxHeight: min(300, max(100, timelineItem.content.height ?? .infinity)))
|
||||||
.aspectRatio(timelineItem.aspectRatio, contentMode: .fit)
|
.aspectRatio(timelineItem.content.aspectRatio, contentMode: .fit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var source: MediaSourceProxy {
|
||||||
|
guard timelineItem.content.contentType != .gif, let thumbnailSource = timelineItem.content.thumbnailSource else {
|
||||||
|
return timelineItem.content.source
|
||||||
|
}
|
||||||
|
|
||||||
|
return thumbnailSource
|
||||||
|
}
|
||||||
|
|
||||||
var placeholder: some View {
|
var placeholder: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
Rectangle()
|
Rectangle()
|
||||||
@@ -56,31 +64,30 @@ struct ImageRoomTimelineView_Previews: PreviewProvider {
|
|||||||
static var body: some View {
|
static var body: some View {
|
||||||
VStack(spacing: 20.0) {
|
VStack(spacing: 20.0) {
|
||||||
ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: UUID().uuidString,
|
ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "Some image",
|
|
||||||
timestamp: "Now",
|
timestamp: "Now",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "Bob"),
|
sender: .init(id: "Bob"),
|
||||||
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/png")))
|
content: .init(body: "Some image", source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/png"), thumbnailSource: nil)))
|
||||||
|
|
||||||
ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: UUID().uuidString,
|
|
||||||
body: "Some other image",
|
|
||||||
timestamp: "Now",
|
|
||||||
isOutgoing: false,
|
|
||||||
isEditable: false,
|
|
||||||
sender: .init(id: "Bob"),
|
|
||||||
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/png")))
|
|
||||||
|
|
||||||
ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: UUID().uuidString,
|
ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "Blurhashed image",
|
|
||||||
timestamp: "Now",
|
timestamp: "Now",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "Bob"),
|
sender: .init(id: "Bob"),
|
||||||
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/gif"),
|
content: .init(body: "Some other image", source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/png"), thumbnailSource: nil)))
|
||||||
aspectRatio: 0.7,
|
|
||||||
blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW",
|
ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: UUID().uuidString,
|
||||||
contentType: .gif))
|
timestamp: "Now",
|
||||||
|
isOutgoing: false,
|
||||||
|
isEditable: false,
|
||||||
|
sender: .init(id: "Bob"),
|
||||||
|
content: .init(body: "Blurhashed image",
|
||||||
|
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/gif"),
|
||||||
|
thumbnailSource: nil,
|
||||||
|
aspectRatio: 0.7,
|
||||||
|
blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW",
|
||||||
|
contentType: .gif)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ struct NoticeRoomTimelineView: View {
|
|||||||
Image(systemName: "info.bubble").padding(.top, 2.0)
|
Image(systemName: "info.bubble").padding(.top, 2.0)
|
||||||
.foregroundColor(.element.secondaryContent)
|
.foregroundColor(.element.secondaryContent)
|
||||||
|
|
||||||
if let attributedString = timelineItem.formattedBody {
|
if let attributedString = timelineItem.content.formattedBody {
|
||||||
FormattedBodyText(attributedString: attributedString)
|
FormattedBodyText(attributedString: attributedString)
|
||||||
} else {
|
} else {
|
||||||
FormattedBodyText(text: timelineItem.body)
|
FormattedBodyText(text: timelineItem.content.body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.leading, 4) // Trailing padding is provided by FormattedBodyText
|
.padding(.leading, 4) // Trailing padding is provided by FormattedBodyText
|
||||||
@@ -64,10 +64,10 @@ struct NoticeRoomTimelineView_Previews: PreviewProvider {
|
|||||||
|
|
||||||
private static func itemWith(text: String, timestamp: String, senderId: String) -> NoticeRoomTimelineItem {
|
private static func itemWith(text: String, timestamp: String, senderId: String) -> NoticeRoomTimelineItem {
|
||||||
NoticeRoomTimelineItem(id: UUID().uuidString,
|
NoticeRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: text,
|
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: senderId))
|
sender: .init(id: senderId),
|
||||||
|
content: .init(body: text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,21 +43,21 @@ struct ReadMarkerRoomTimelineView_Previews: PreviewProvider {
|
|||||||
VStack(alignment: .leading, spacing: 0) {
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
RoomTimelineViewProvider.separator(.init(text: "Today"), .single)
|
RoomTimelineViewProvider.separator(.init(text: "Today"), .single)
|
||||||
RoomTimelineViewProvider.text(.init(id: "",
|
RoomTimelineViewProvider.text(.init(id: "",
|
||||||
body: "This is another message",
|
|
||||||
timestamp: "",
|
timestamp: "",
|
||||||
isOutgoing: true,
|
isOutgoing: true,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "1", displayName: "Bob")), .single)
|
sender: .init(id: "1", displayName: "Bob"),
|
||||||
|
content: .init(body: "This is another message")), .single)
|
||||||
|
|
||||||
ReadMarkerRoomTimelineView(timelineItem: item)
|
ReadMarkerRoomTimelineView(timelineItem: item)
|
||||||
|
|
||||||
RoomTimelineViewProvider.separator(.init(text: "Today"), .single)
|
RoomTimelineViewProvider.separator(.init(text: "Today"), .single)
|
||||||
RoomTimelineViewProvider.text(.init(id: "",
|
RoomTimelineViewProvider.text(.init(id: "",
|
||||||
body: "This is a message",
|
|
||||||
timestamp: "",
|
timestamp: "",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "", displayName: "Alice")), .single)
|
sender: .init(id: "", displayName: "Alice"),
|
||||||
|
content: .init(body: "This is a message")), .single)
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 8)
|
.padding(.horizontal, 8)
|
||||||
.environmentObject(viewModel.context)
|
.environmentObject(viewModel.context)
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ struct TextRoomTimelineView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
TimelineStyler(timelineItem: timelineItem) {
|
TimelineStyler(timelineItem: timelineItem) {
|
||||||
if let attributedString = timelineItem.formattedBody {
|
if let attributedString = timelineItem.content.formattedBody {
|
||||||
FormattedBodyText(attributedString: attributedString)
|
FormattedBodyText(attributedString: attributedString)
|
||||||
} else {
|
} else {
|
||||||
FormattedBodyText(text: timelineItem.body)
|
FormattedBodyText(text: timelineItem.content.body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,10 +65,10 @@ struct TextRoomTimelineView_Previews: PreviewProvider {
|
|||||||
|
|
||||||
private static func itemWith(text: String, timestamp: String, isOutgoing: Bool, senderId: String) -> TextRoomTimelineItem {
|
private static func itemWith(text: String, timestamp: String, isOutgoing: Bool, senderId: String) -> TextRoomTimelineItem {
|
||||||
TextRoomTimelineItem(id: UUID().uuidString,
|
TextRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: text,
|
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
isOutgoing: isOutgoing,
|
isOutgoing: isOutgoing,
|
||||||
isEditable: isOutgoing,
|
isEditable: isOutgoing,
|
||||||
sender: .init(id: senderId))
|
sender: .init(id: senderId),
|
||||||
|
content: .init(body: text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,16 +24,16 @@ struct VideoRoomTimelineView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
TimelineStyler(timelineItem: timelineItem) {
|
TimelineStyler(timelineItem: timelineItem) {
|
||||||
thumbnail
|
thumbnail
|
||||||
.frame(maxHeight: min(300, max(100, timelineItem.height ?? .infinity)))
|
.frame(maxHeight: min(300, max(100, timelineItem.content.height ?? .infinity)))
|
||||||
.aspectRatio(timelineItem.aspectRatio, contentMode: .fit)
|
.aspectRatio(timelineItem.content.aspectRatio, contentMode: .fit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
var thumbnail: some View {
|
var thumbnail: some View {
|
||||||
if let thumbnailSource = timelineItem.thumbnailSource {
|
if let thumbnailSource = timelineItem.content.thumbnailSource {
|
||||||
LoadableImage(mediaSource: thumbnailSource,
|
LoadableImage(mediaSource: thumbnailSource,
|
||||||
blurhash: timelineItem.blurhash,
|
blurhash: timelineItem.content.blurhash,
|
||||||
imageProvider: context.imageProvider) { imageView in
|
imageProvider: context.imageProvider) { imageView in
|
||||||
imageView
|
imageView
|
||||||
.overlay { playIcon }
|
.overlay { playIcon }
|
||||||
@@ -76,36 +76,25 @@ struct VideoRoomTimelineView_Previews: PreviewProvider {
|
|||||||
static var body: some View {
|
static var body: some View {
|
||||||
VStack(spacing: 20.0) {
|
VStack(spacing: 20.0) {
|
||||||
VideoRoomTimelineView(timelineItem: VideoRoomTimelineItem(id: UUID().uuidString,
|
VideoRoomTimelineView(timelineItem: VideoRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "Some video",
|
|
||||||
timestamp: "Now",
|
timestamp: "Now",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "Bob"),
|
sender: .init(id: "Bob"),
|
||||||
duration: 21,
|
content: .init(body: "Some video", duration: 21, source: nil, thumbnailSource: nil)))
|
||||||
source: nil,
|
|
||||||
thumbnailSource: nil))
|
|
||||||
|
|
||||||
VideoRoomTimelineView(timelineItem: VideoRoomTimelineItem(id: UUID().uuidString,
|
VideoRoomTimelineView(timelineItem: VideoRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "Some other video",
|
|
||||||
timestamp: "Now",
|
timestamp: "Now",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "Bob"),
|
sender: .init(id: "Bob"),
|
||||||
duration: 22,
|
content: .init(body: "Some other video", duration: 22, source: nil, thumbnailSource: nil)))
|
||||||
source: nil,
|
|
||||||
thumbnailSource: nil))
|
|
||||||
|
|
||||||
VideoRoomTimelineView(timelineItem: VideoRoomTimelineItem(id: UUID().uuidString,
|
VideoRoomTimelineView(timelineItem: VideoRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "Blurhashed video",
|
|
||||||
timestamp: "Now",
|
timestamp: "Now",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "Bob"),
|
sender: .init(id: "Bob"),
|
||||||
duration: 23,
|
content: .init(body: "Blurhashed video", duration: 23, source: nil, thumbnailSource: nil, aspectRatio: 0.7, blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW")))
|
||||||
source: nil,
|
|
||||||
thumbnailSource: nil,
|
|
||||||
aspectRatio: 0.7,
|
|
||||||
blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -428,6 +428,19 @@ class RoomProxy: RoomProxyProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchDetails(for eventID: String) {
|
||||||
|
Task {
|
||||||
|
await Task.dispatch(on: .global()) {
|
||||||
|
do {
|
||||||
|
MXLog.info("Fetching event details for \(eventID)")
|
||||||
|
try self.room.fetchEventDetails(eventId: eventID)
|
||||||
|
} catch {
|
||||||
|
MXLog.error("Failed fetching event details for \(eventID) with error: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
/// Force the timeline to load member details so it can populate sender profiles whenever we add a timeline listener
|
/// Force the timeline to load member details so it can populate sender profiles whenever we add a timeline listener
|
||||||
|
|||||||
@@ -102,6 +102,8 @@ protocol RoomProxyProtocol {
|
|||||||
func rejectInvitation() async -> Result<Void, RoomProxyError>
|
func rejectInvitation() async -> Result<Void, RoomProxyError>
|
||||||
|
|
||||||
func acceptInvitation() async -> Result<Void, RoomProxyError>
|
func acceptInvitation() async -> Result<Void, RoomProxyError>
|
||||||
|
|
||||||
|
func fetchDetails(for eventID: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
extension RoomProxyProtocol {
|
extension RoomProxyProtocol {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ struct RoomEventStringBuilder {
|
|||||||
// Message types that don't need a prefix.
|
// Message types that don't need a prefix.
|
||||||
case .emote(content: let content):
|
case .emote(content: let content):
|
||||||
let senderDisplayName = sender.displayName ?? sender.id
|
let senderDisplayName = sender.displayName ?? sender.id
|
||||||
return AttributedString("* \(senderDisplayName) \(content.body)")
|
return AttributedString(L10n.commonEmote(senderDisplayName, content.body))
|
||||||
// Message types that should be prefixed with the sender's name.
|
// Message types that should be prefixed with the sender's name.
|
||||||
case .image:
|
case .image:
|
||||||
message = L10n.commonImage
|
message = L10n.commonImage
|
||||||
|
|||||||
@@ -21,61 +21,61 @@ enum RoomTimelineItemFixtures {
|
|||||||
static var `default`: [RoomTimelineItemProtocol] = [
|
static var `default`: [RoomTimelineItemProtocol] = [
|
||||||
SeparatorRoomTimelineItem(text: "Yesterday"),
|
SeparatorRoomTimelineItem(text: "Yesterday"),
|
||||||
TextRoomTimelineItem(id: UUID().uuidString,
|
TextRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "That looks so good!",
|
|
||||||
timestamp: "10:10 AM",
|
timestamp: "10:10 AM",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "", displayName: "Jacob"),
|
sender: .init(id: "", displayName: "Jacob"),
|
||||||
|
content: .init(body: "That looks so good!"),
|
||||||
properties: RoomTimelineItemProperties(isEdited: true)),
|
properties: RoomTimelineItemProperties(isEdited: true)),
|
||||||
TextRoomTimelineItem(id: UUID().uuidString,
|
TextRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "Let’s get lunch soon! New salad place opened up 🥗. When are y’all free? 🤗",
|
|
||||||
timestamp: "10:11 AM",
|
timestamp: "10:11 AM",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "", displayName: "Helena"),
|
sender: .init(id: "", displayName: "Helena"),
|
||||||
|
content: .init(body: "Let’s get lunch soon! New salad place opened up 🥗. When are y’all free? 🤗"),
|
||||||
properties: RoomTimelineItemProperties(reactions: [
|
properties: RoomTimelineItemProperties(reactions: [
|
||||||
AggregatedReaction(key: "🙌", count: 1, isHighlighted: true)
|
AggregatedReaction(key: "🙌", count: 1, isHighlighted: true)
|
||||||
])),
|
])),
|
||||||
TextRoomTimelineItem(id: UUID().uuidString,
|
TextRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "I can be around on Wednesday. How about some 🌮 instead? Like https://www.tortilla.co.uk/",
|
|
||||||
timestamp: "10:11 AM",
|
timestamp: "10:11 AM",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "", displayName: "Helena"),
|
sender: .init(id: "", displayName: "Helena"),
|
||||||
|
content: .init(body: "I can be around on Wednesday. How about some 🌮 instead? Like https://www.tortilla.co.uk/"),
|
||||||
properties: RoomTimelineItemProperties(reactions: [
|
properties: RoomTimelineItemProperties(reactions: [
|
||||||
AggregatedReaction(key: "🙏", count: 1, isHighlighted: false),
|
AggregatedReaction(key: "🙏", count: 1, isHighlighted: false),
|
||||||
AggregatedReaction(key: "🙌", count: 2, isHighlighted: true)
|
AggregatedReaction(key: "🙌", count: 2, isHighlighted: true)
|
||||||
])),
|
])),
|
||||||
SeparatorRoomTimelineItem(text: "Today"),
|
SeparatorRoomTimelineItem(text: "Today"),
|
||||||
TextRoomTimelineItem(id: UUID().uuidString,
|
TextRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "Wow, cool. Ok, lets go the usual place tomorrow?! Is that too soon? Here’s the menu, let me know what you want it’s on me!",
|
|
||||||
timestamp: "5 PM",
|
timestamp: "5 PM",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "", displayName: "Helena")),
|
sender: .init(id: "", displayName: "Helena"),
|
||||||
|
content: .init(body: "Wow, cool. Ok, lets go the usual place tomorrow?! Is that too soon? Here’s the menu, let me know what you want it’s on me!")),
|
||||||
TextRoomTimelineItem(id: UUID().uuidString,
|
TextRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "And John's speech was amazing!",
|
|
||||||
timestamp: "5 PM",
|
|
||||||
isOutgoing: true,
|
|
||||||
isEditable: true,
|
|
||||||
sender: .init(id: "", displayName: "Bob")),
|
|
||||||
TextRoomTimelineItem(id: UUID().uuidString,
|
|
||||||
body: "New home office set up!",
|
|
||||||
timestamp: "5 PM",
|
timestamp: "5 PM",
|
||||||
isOutgoing: true,
|
isOutgoing: true,
|
||||||
isEditable: true,
|
isEditable: true,
|
||||||
sender: .init(id: "", displayName: "Bob"),
|
sender: .init(id: "", displayName: "Bob"),
|
||||||
|
content: .init(body: "And John's speech was amazing!")),
|
||||||
|
TextRoomTimelineItem(id: UUID().uuidString,
|
||||||
|
timestamp: "5 PM",
|
||||||
|
isOutgoing: true,
|
||||||
|
isEditable: true,
|
||||||
|
sender: .init(id: "", displayName: "Bob"),
|
||||||
|
content: .init(body: "New home office set up!"),
|
||||||
properties: RoomTimelineItemProperties(reactions: [
|
properties: RoomTimelineItemProperties(reactions: [
|
||||||
AggregatedReaction(key: "🙏", count: 1, isHighlighted: false),
|
AggregatedReaction(key: "🙏", count: 1, isHighlighted: false),
|
||||||
AggregatedReaction(key: "😁", count: 3, isHighlighted: false)
|
AggregatedReaction(key: "😁", count: 3, isHighlighted: false)
|
||||||
])),
|
])),
|
||||||
TextRoomTimelineItem(id: UUID().uuidString,
|
TextRoomTimelineItem(id: UUID().uuidString,
|
||||||
body: "",
|
|
||||||
formattedBody: AttributedStringBuilder().fromHTML("Hol' up <blockquote>New home office set up!</blockquote>That's amazing! Congrats 🥳"),
|
|
||||||
timestamp: "5 PM",
|
timestamp: "5 PM",
|
||||||
isOutgoing: false,
|
isOutgoing: false,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "", displayName: "Helena"))
|
sender: .init(id: "", displayName: "Helena"),
|
||||||
|
content: .init(body: "",
|
||||||
|
formattedBody: AttributedStringBuilder().fromHTML("Hol' up <blockquote>New home office set up!</blockquote>That's amazing! Congrats 🥳")))
|
||||||
]
|
]
|
||||||
|
|
||||||
/// A small chunk of events, containing 2 text items.
|
/// A small chunk of events, containing 2 text items.
|
||||||
@@ -187,10 +187,10 @@ enum RoomTimelineItemFixtures {
|
|||||||
private extension TextRoomTimelineItem {
|
private extension TextRoomTimelineItem {
|
||||||
init(text: String, senderDisplayName: String) {
|
init(text: String, senderDisplayName: String) {
|
||||||
self.init(id: UUID().uuidString,
|
self.init(id: UUID().uuidString,
|
||||||
body: text,
|
|
||||||
timestamp: "10:47 am",
|
timestamp: "10:47 am",
|
||||||
isOutgoing: senderDisplayName == "Alice",
|
isOutgoing: senderDisplayName == "Alice",
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: .init(id: "", displayName: senderDisplayName))
|
sender: .init(id: "", displayName: senderDisplayName),
|
||||||
|
content: .init(body: text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-13
@@ -96,7 +96,21 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func processItemAppearance(_ itemID: String) async { }
|
func processItemAppearance(_ itemID: String) async {
|
||||||
|
guard let timelineItem = timelineItems.first(where: { $0.id == itemID }) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch replied-to event details if unavailable at the point of displaying it in the timeline
|
||||||
|
if let messageTimelineItem = timelineItem as? EventBasedMessageTimelineItemProtocol {
|
||||||
|
switch messageTimelineItem.replyDetails {
|
||||||
|
case .notLoaded, .error:
|
||||||
|
roomProxy.fetchDetails(for: timelineItem.id)
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func processItemDisappearance(_ itemID: String) { }
|
func processItemDisappearance(_ itemID: String) { }
|
||||||
|
|
||||||
@@ -109,18 +123,18 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
|||||||
var body: String
|
var body: String
|
||||||
switch timelineItem {
|
switch timelineItem {
|
||||||
case let item as ImageRoomTimelineItem:
|
case let item as ImageRoomTimelineItem:
|
||||||
source = item.source
|
source = item.content.source
|
||||||
body = item.body
|
body = item.content.body
|
||||||
case let item as VideoRoomTimelineItem:
|
case let item as VideoRoomTimelineItem:
|
||||||
source = item.source
|
source = item.content.source
|
||||||
body = item.body
|
body = item.content.body
|
||||||
case let item as FileRoomTimelineItem:
|
case let item as FileRoomTimelineItem:
|
||||||
source = item.source
|
source = item.content.source
|
||||||
body = item.body
|
body = item.content.body
|
||||||
case let item as AudioRoomTimelineItem:
|
case let item as AudioRoomTimelineItem:
|
||||||
// For now we are just displaying audio messages with the File preview until we create a timeline player for them.
|
// For now we are just displaying audio messages with the File preview until we create a timeline player for them.
|
||||||
source = item.source
|
source = item.content.source
|
||||||
body = item.body
|
body = item.content.body
|
||||||
default:
|
default:
|
||||||
return .none
|
return .none
|
||||||
}
|
}
|
||||||
@@ -218,7 +232,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
|||||||
let isLastItem = index == collapsibleChunks.indices.last
|
let isLastItem = index == collapsibleChunks.indices.last
|
||||||
|
|
||||||
let items = collapsibleChunk.compactMap { itemProxy in
|
let items = collapsibleChunk.compactMap { itemProxy in
|
||||||
let timelineItem = buildTimelineItemFor(itemProxy: itemProxy)
|
let timelineItem = buildTimelineItem(for: itemProxy)
|
||||||
|
|
||||||
if timelineItem is PaginationIndicatorRoomTimelineItem {
|
if timelineItem is PaginationIndicatorRoomTimelineItem {
|
||||||
isBackPaginating = true
|
isBackPaginating = true
|
||||||
@@ -253,10 +267,10 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
|||||||
callbacks.send(.isBackPaginating(isBackPaginating))
|
callbacks.send(.isBackPaginating(isBackPaginating))
|
||||||
}
|
}
|
||||||
|
|
||||||
private func buildTimelineItemFor(itemProxy: TimelineItemProxy) -> RoomTimelineItemProtocol? {
|
private func buildTimelineItem(for itemProxy: TimelineItemProxy) -> RoomTimelineItemProtocol? {
|
||||||
switch itemProxy {
|
switch itemProxy {
|
||||||
case .event(let eventItemProxy):
|
case .event(let eventTimelineItem):
|
||||||
return timelineItemFactory.buildTimelineItemFor(eventItemProxy: eventItemProxy)
|
return timelineItemFactory.buildTimelineItem(for: eventTimelineItem)
|
||||||
case .virtual(let virtualItem):
|
case .virtual(let virtualItem):
|
||||||
switch virtualItem {
|
switch virtualItem {
|
||||||
case .dayDivider(let timestamp):
|
case .dayDivider(let timestamp):
|
||||||
|
|||||||
@@ -1,172 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright 2022 New Vector Ltd
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
//
|
|
||||||
|
|
||||||
import CoreGraphics
|
|
||||||
import Foundation
|
|
||||||
import MatrixRustSDK
|
|
||||||
import UniformTypeIdentifiers
|
|
||||||
|
|
||||||
/// A protocol that contains the base `m.room.message` event content properties.
|
|
||||||
/// The `CustomStringConvertible` conformance is to redact specific properties from the logs.
|
|
||||||
protocol MessageContentProtocol: RoomMessageEventContentProtocol, CustomStringConvertible {
|
|
||||||
var body: String { get }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A timeline item that represents an `m.room.message` event.
|
|
||||||
struct MessageTimelineItem<Content: MessageContentProtocol> {
|
|
||||||
let item: MatrixRustSDK.EventTimelineItemProtocol
|
|
||||||
let content: Content
|
|
||||||
|
|
||||||
var id: String {
|
|
||||||
item.uniqueIdentifier()
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: String {
|
|
||||||
content.body
|
|
||||||
}
|
|
||||||
|
|
||||||
var isEdited: Bool {
|
|
||||||
item.content().asMessage()?.isEdited() == true
|
|
||||||
}
|
|
||||||
|
|
||||||
var sender: String {
|
|
||||||
item.sender()
|
|
||||||
}
|
|
||||||
|
|
||||||
var timestamp: Date {
|
|
||||||
Date(timeIntervalSince1970: TimeInterval(item.timestamp() / 1000))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Formatted Text
|
|
||||||
|
|
||||||
/// A protocol that contains the expected event content properties for a formatted message.
|
|
||||||
protocol FormattedMessageContentProtocol: MessageContentProtocol {
|
|
||||||
var formatted: FormattedBody? { get }
|
|
||||||
}
|
|
||||||
|
|
||||||
extension MatrixRustSDK.TextMessageContent: FormattedMessageContentProtocol { }
|
|
||||||
extension MatrixRustSDK.EmoteMessageContent: FormattedMessageContentProtocol { }
|
|
||||||
extension MatrixRustSDK.NoticeMessageContent: FormattedMessageContentProtocol { }
|
|
||||||
|
|
||||||
/// A timeline item that represents an `m.room.message` event where
|
|
||||||
/// the `msgtype` would likely contain a formatted body.
|
|
||||||
extension MessageTimelineItem where Content: FormattedMessageContentProtocol {
|
|
||||||
var htmlBody: String? {
|
|
||||||
guard content.formatted?.format == .html else { return nil }
|
|
||||||
return content.formatted?.body
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Media
|
|
||||||
|
|
||||||
extension MatrixRustSDK.ImageMessageContent: MessageContentProtocol { }
|
|
||||||
|
|
||||||
/// A timeline item that represents an `m.room.message` event with a `msgtype` of `m.image`.
|
|
||||||
extension MessageTimelineItem where Content == MatrixRustSDK.ImageMessageContent {
|
|
||||||
var source: MediaSourceProxy {
|
|
||||||
.init(source: content.source, mimeType: content.info?.mimetype)
|
|
||||||
}
|
|
||||||
|
|
||||||
var width: CGFloat? {
|
|
||||||
content.info?.width.map(CGFloat.init)
|
|
||||||
}
|
|
||||||
|
|
||||||
var height: CGFloat? {
|
|
||||||
content.info?.height.map(CGFloat.init)
|
|
||||||
}
|
|
||||||
|
|
||||||
var blurhash: String? {
|
|
||||||
content.info?.blurhash
|
|
||||||
}
|
|
||||||
|
|
||||||
var contentType: UTType? {
|
|
||||||
UTType(mimeType: content.info?.mimetype, fallbackFilename: content.body)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension MatrixRustSDK.VideoMessageContent: MessageContentProtocol { }
|
|
||||||
|
|
||||||
/// A timeline item that represents an `m.room.message` event with a `msgtype` of `m.video`.
|
|
||||||
extension MessageTimelineItem where Content == MatrixRustSDK.VideoMessageContent {
|
|
||||||
var source: MediaSourceProxy {
|
|
||||||
.init(source: content.source, mimeType: content.info?.mimetype)
|
|
||||||
}
|
|
||||||
|
|
||||||
var thumbnailSource: MediaSourceProxy? {
|
|
||||||
guard let src = content.info?.thumbnailSource else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return .init(source: src, mimeType: content.info?.thumbnailInfo?.mimetype)
|
|
||||||
}
|
|
||||||
|
|
||||||
var duration: UInt64 {
|
|
||||||
content.info?.duration ?? 0
|
|
||||||
}
|
|
||||||
|
|
||||||
var width: CGFloat? {
|
|
||||||
content.info?.width.map(CGFloat.init)
|
|
||||||
}
|
|
||||||
|
|
||||||
var height: CGFloat? {
|
|
||||||
content.info?.height.map(CGFloat.init)
|
|
||||||
}
|
|
||||||
|
|
||||||
var blurhash: String? {
|
|
||||||
content.info?.blurhash
|
|
||||||
}
|
|
||||||
|
|
||||||
var contentType: UTType? {
|
|
||||||
UTType(mimeType: content.info?.mimetype, fallbackFilename: content.body)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension MatrixRustSDK.FileMessageContent: MessageContentProtocol { }
|
|
||||||
|
|
||||||
/// A timeline item that represents an `m.room.message` event with a `msgtype` of `m.file`.
|
|
||||||
extension MessageTimelineItem where Content == MatrixRustSDK.FileMessageContent {
|
|
||||||
var source: MediaSourceProxy {
|
|
||||||
.init(source: content.source, mimeType: content.info?.mimetype)
|
|
||||||
}
|
|
||||||
|
|
||||||
var thumbnailSource: MediaSourceProxy? {
|
|
||||||
guard let src = content.info?.thumbnailSource else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return .init(source: src, mimeType: content.info?.thumbnailInfo?.mimetype)
|
|
||||||
}
|
|
||||||
|
|
||||||
var contentType: UTType? {
|
|
||||||
UTType(mimeType: content.info?.mimetype, fallbackFilename: content.body)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension MatrixRustSDK.AudioMessageContent: MessageContentProtocol { }
|
|
||||||
|
|
||||||
/// A timeline item that represents an `m.room.message` event with a `msgtype` of `m.audio`.
|
|
||||||
extension MessageTimelineItem where Content == MatrixRustSDK.AudioMessageContent {
|
|
||||||
var source: MediaSourceProxy {
|
|
||||||
.init(source: content.source, mimeType: content.info?.mimetype)
|
|
||||||
}
|
|
||||||
|
|
||||||
var duration: UInt64 {
|
|
||||||
content.info?.duration ?? 0
|
|
||||||
}
|
|
||||||
|
|
||||||
var contentType: UTType? {
|
|
||||||
UTType(mimeType: content.info?.mimetype, fallbackFilename: content.body)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2023 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
enum TimelineItemReplyContent: Hashable {
|
||||||
|
case audio(AudioRoomTimelineItemContent)
|
||||||
|
case emote(EmoteRoomTimelineItemContent)
|
||||||
|
case file(FileRoomTimelineItemContent)
|
||||||
|
case image(ImageRoomTimelineItemContent)
|
||||||
|
case notice(NoticeRoomTimelineItemContent)
|
||||||
|
case text(TextRoomTimelineItemContent)
|
||||||
|
case video(VideoRoomTimelineItemContent)
|
||||||
|
}
|
||||||
|
|
||||||
|
enum TimelineItemReplyDetails: Hashable {
|
||||||
|
case notLoaded(eventID: String)
|
||||||
|
case loading(eventID: String)
|
||||||
|
case loaded(sender: TimelineItemSender, content: TimelineItemReplyContent)
|
||||||
|
case error(eventID: String, message: String)
|
||||||
|
}
|
||||||
@@ -65,15 +65,7 @@ struct EventTimelineItemProxy {
|
|||||||
return .sent(elapsedTime: Date().timeIntervalSince1970 - timestamp.timeIntervalSince1970)
|
return .sent(elapsedTime: Date().timeIntervalSince1970 - timestamp.timeIntervalSince1970)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: String? {
|
|
||||||
content.asMessage()?.body()
|
|
||||||
}
|
|
||||||
|
|
||||||
var isMessage: Bool {
|
|
||||||
content.asMessage() != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var isRoomState: Bool {
|
var isRoomState: Bool {
|
||||||
content.kind().isRoomState
|
content.kind().isRoomState
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2023 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
protocol EventBasedMessageTimelineItemProtocol: EventBasedTimelineItemProtocol {
|
||||||
|
var body: String { get }
|
||||||
|
var replyDetails: TimelineItemReplyDetails? { get }
|
||||||
|
}
|
||||||
@@ -18,7 +18,6 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
protocol EventBasedTimelineItemProtocol: RoomTimelineItemProtocol, CustomStringConvertible {
|
protocol EventBasedTimelineItemProtocol: RoomTimelineItemProtocol, CustomStringConvertible {
|
||||||
var body: String { get }
|
|
||||||
var timestamp: String { get }
|
var timestamp: String { get }
|
||||||
var isOutgoing: Bool { get }
|
var isOutgoing: Bool { get }
|
||||||
var isEditable: Bool { get }
|
var isEditable: Bool { get }
|
||||||
|
|||||||
+9
-7
@@ -15,19 +15,21 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import UniformTypeIdentifiers
|
|
||||||
|
|
||||||
struct AudioRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
|
struct AudioRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Identifiable, Hashable {
|
||||||
let id: String
|
let id: String
|
||||||
let body: String
|
|
||||||
let timestamp: String
|
let timestamp: String
|
||||||
let isOutgoing: Bool
|
let isOutgoing: Bool
|
||||||
let isEditable: Bool
|
let isEditable: Bool
|
||||||
let sender: TimelineItemSender
|
let sender: TimelineItemSender
|
||||||
|
|
||||||
let duration: UInt64
|
let content: AudioRoomTimelineItemContent
|
||||||
let source: MediaSourceProxy?
|
|
||||||
var contentType: UTType?
|
var replyDetails: TimelineItemReplyDetails?
|
||||||
|
|
||||||
var properties = RoomTimelineItemProperties()
|
var properties = RoomTimelineItemProperties()
|
||||||
|
|
||||||
|
var body: String {
|
||||||
|
content.body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2023 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
|
struct AudioRoomTimelineItemContent: Hashable {
|
||||||
|
let body: String
|
||||||
|
let duration: UInt64
|
||||||
|
let source: MediaSourceProxy?
|
||||||
|
let contentType: UTType?
|
||||||
|
}
|
||||||
+9
-3
@@ -16,15 +16,21 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
struct EmoteRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
|
struct EmoteRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Identifiable, Hashable {
|
||||||
let id: String
|
let id: String
|
||||||
let body: String
|
|
||||||
var formattedBody: AttributedString?
|
|
||||||
let timestamp: String
|
let timestamp: String
|
||||||
let isOutgoing: Bool
|
let isOutgoing: Bool
|
||||||
let isEditable: Bool
|
let isEditable: Bool
|
||||||
|
|
||||||
let sender: TimelineItemSender
|
let sender: TimelineItemSender
|
||||||
|
|
||||||
|
let content: EmoteRoomTimelineItemContent
|
||||||
|
|
||||||
|
var replyDetails: TimelineItemReplyDetails?
|
||||||
|
|
||||||
var properties = RoomTimelineItemProperties()
|
var properties = RoomTimelineItemProperties()
|
||||||
|
|
||||||
|
var body: String {
|
||||||
|
content.body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2023 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
struct EmoteRoomTimelineItemContent: Hashable {
|
||||||
|
let body: String
|
||||||
|
var formattedBody: AttributedString?
|
||||||
|
}
|
||||||
+9
-6
@@ -17,18 +17,21 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import UniformTypeIdentifiers
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
struct FileRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
|
struct FileRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Identifiable, Hashable {
|
||||||
let id: String
|
let id: String
|
||||||
let body: String
|
|
||||||
let timestamp: String
|
let timestamp: String
|
||||||
let isOutgoing: Bool
|
let isOutgoing: Bool
|
||||||
let isEditable: Bool
|
let isEditable: Bool
|
||||||
|
|
||||||
let sender: TimelineItemSender
|
let sender: TimelineItemSender
|
||||||
|
|
||||||
let source: MediaSourceProxy?
|
let content: FileRoomTimelineItemContent
|
||||||
let thumbnailSource: MediaSourceProxy?
|
|
||||||
var contentType: UTType?
|
var replyDetails: TimelineItemReplyDetails?
|
||||||
|
|
||||||
var properties = RoomTimelineItemProperties()
|
var properties = RoomTimelineItemProperties()
|
||||||
|
|
||||||
|
var body: String {
|
||||||
|
content.body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2023 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
|
struct FileRoomTimelineItemContent: Hashable {
|
||||||
|
let body: String
|
||||||
|
let source: MediaSourceProxy?
|
||||||
|
let thumbnailSource: MediaSourceProxy?
|
||||||
|
let contentType: UTType?
|
||||||
|
}
|
||||||
+7
-8
@@ -17,22 +17,21 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import UniformTypeIdentifiers
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
struct ImageRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
|
struct ImageRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Identifiable, Hashable {
|
||||||
let id: String
|
let id: String
|
||||||
let body: String
|
|
||||||
let timestamp: String
|
let timestamp: String
|
||||||
let isOutgoing: Bool
|
let isOutgoing: Bool
|
||||||
let isEditable: Bool
|
let isEditable: Bool
|
||||||
|
|
||||||
let sender: TimelineItemSender
|
let sender: TimelineItemSender
|
||||||
|
|
||||||
let source: MediaSourceProxy
|
let content: ImageRoomTimelineItemContent
|
||||||
|
|
||||||
var width: CGFloat?
|
var replyDetails: TimelineItemReplyDetails?
|
||||||
var height: CGFloat?
|
|
||||||
var aspectRatio: CGFloat?
|
|
||||||
var blurhash: String?
|
|
||||||
var contentType: UTType?
|
|
||||||
|
|
||||||
var properties = RoomTimelineItemProperties()
|
var properties = RoomTimelineItemProperties()
|
||||||
|
|
||||||
|
var body: String {
|
||||||
|
content.body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2023 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
|
struct ImageRoomTimelineItemContent: Hashable {
|
||||||
|
let body: String
|
||||||
|
let source: MediaSourceProxy
|
||||||
|
let thumbnailSource: MediaSourceProxy?
|
||||||
|
var width: CGFloat?
|
||||||
|
var height: CGFloat?
|
||||||
|
var aspectRatio: CGFloat?
|
||||||
|
var blurhash: String?
|
||||||
|
var contentType: UTType?
|
||||||
|
}
|
||||||
+9
-3
@@ -16,15 +16,21 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
struct NoticeRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
|
struct NoticeRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Identifiable, Hashable {
|
||||||
let id: String
|
let id: String
|
||||||
let body: String
|
|
||||||
var formattedBody: AttributedString?
|
|
||||||
let timestamp: String
|
let timestamp: String
|
||||||
let isOutgoing: Bool
|
let isOutgoing: Bool
|
||||||
let isEditable: Bool
|
let isEditable: Bool
|
||||||
|
|
||||||
let sender: TimelineItemSender
|
let sender: TimelineItemSender
|
||||||
|
|
||||||
|
let content: NoticeRoomTimelineItemContent
|
||||||
|
|
||||||
|
var replyDetails: TimelineItemReplyDetails?
|
||||||
|
|
||||||
var properties = RoomTimelineItemProperties()
|
var properties = RoomTimelineItemProperties()
|
||||||
|
|
||||||
|
var body: String {
|
||||||
|
content.body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2023 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
struct NoticeRoomTimelineItemContent: Hashable {
|
||||||
|
let body: String
|
||||||
|
var formattedBody: AttributedString?
|
||||||
|
}
|
||||||
+10
-3
@@ -16,15 +16,22 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
struct TextRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
|
struct TextRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Identifiable, Hashable {
|
||||||
let id: String
|
let id: String
|
||||||
let body: String
|
|
||||||
var formattedBody: AttributedString?
|
|
||||||
let timestamp: String
|
let timestamp: String
|
||||||
let isOutgoing: Bool
|
let isOutgoing: Bool
|
||||||
let isEditable: Bool
|
let isEditable: Bool
|
||||||
|
|
||||||
let sender: TimelineItemSender
|
let sender: TimelineItemSender
|
||||||
|
|
||||||
|
let content: TextRoomTimelineItemContent
|
||||||
|
|
||||||
|
var replyDetails: TimelineItemReplyDetails?
|
||||||
|
|
||||||
var properties = RoomTimelineItemProperties()
|
var properties = RoomTimelineItemProperties()
|
||||||
|
|
||||||
|
var body: String {
|
||||||
|
content.body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2023 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
struct TextRoomTimelineItemContent: Hashable {
|
||||||
|
let body: String
|
||||||
|
var formattedBody: AttributedString?
|
||||||
|
}
|
||||||
+7
-10
@@ -17,24 +17,21 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import UniformTypeIdentifiers
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
struct VideoRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Hashable {
|
struct VideoRoomTimelineItem: EventBasedMessageTimelineItemProtocol, Identifiable, Hashable {
|
||||||
let id: String
|
let id: String
|
||||||
let body: String
|
|
||||||
let timestamp: String
|
let timestamp: String
|
||||||
let isOutgoing: Bool
|
let isOutgoing: Bool
|
||||||
let isEditable: Bool
|
let isEditable: Bool
|
||||||
|
|
||||||
let sender: TimelineItemSender
|
let sender: TimelineItemSender
|
||||||
|
|
||||||
let duration: UInt64
|
let content: VideoRoomTimelineItemContent
|
||||||
let source: MediaSourceProxy?
|
|
||||||
let thumbnailSource: MediaSourceProxy?
|
|
||||||
|
|
||||||
var width: CGFloat?
|
var replyDetails: TimelineItemReplyDetails?
|
||||||
var height: CGFloat?
|
|
||||||
var aspectRatio: CGFloat?
|
|
||||||
var blurhash: String?
|
|
||||||
var contentType: UTType?
|
|
||||||
|
|
||||||
var properties = RoomTimelineItemProperties()
|
var properties = RoomTimelineItemProperties()
|
||||||
|
|
||||||
|
var body: String {
|
||||||
|
content.body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2023 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
|
struct VideoRoomTimelineItemContent: Hashable {
|
||||||
|
let body: String
|
||||||
|
let duration: UInt64
|
||||||
|
let source: MediaSourceProxy?
|
||||||
|
let thumbnailSource: MediaSourceProxy?
|
||||||
|
var width: CGFloat?
|
||||||
|
var height: CGFloat?
|
||||||
|
var aspectRatio: CGFloat?
|
||||||
|
var blurhash: String?
|
||||||
|
var contentType: UTType?
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
import MatrixRustSDK
|
import MatrixRustSDK
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
||||||
private let mediaProvider: MediaProviderProtocol
|
private let mediaProvider: MediaProviderProtocol
|
||||||
@@ -36,7 +37,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// swiftlint:disable:next cyclomatic_complexity
|
// swiftlint:disable:next cyclomatic_complexity
|
||||||
func buildTimelineItemFor(eventItemProxy: EventTimelineItemProxy) -> RoomTimelineItemProtocol? {
|
func buildTimelineItem(for eventItemProxy: EventTimelineItemProxy) -> RoomTimelineItemProtocol? {
|
||||||
let isOutgoing = eventItemProxy.isOwn
|
let isOutgoing = eventItemProxy.isOwn
|
||||||
|
|
||||||
switch eventItemProxy.content.kind() {
|
switch eventItemProxy.content.kind() {
|
||||||
@@ -56,39 +57,37 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
|||||||
case .failedToParseState(let eventType, _, let error):
|
case .failedToParseState(let eventType, _, let error):
|
||||||
return buildUnsupportedTimelineItem(eventItemProxy, eventType, error, isOutgoing)
|
return buildUnsupportedTimelineItem(eventItemProxy, eventType, error, isOutgoing)
|
||||||
case .message:
|
case .message:
|
||||||
guard let messageContent = eventItemProxy.content.asMessage() else { fatalError("Invalid message timeline item: \(eventItemProxy)") }
|
guard let messageTimelineItem = eventItemProxy.content.asMessage() else { fatalError("Invalid message timeline item: \(eventItemProxy)") }
|
||||||
|
|
||||||
switch messageContent.msgtype() {
|
switch messageTimelineItem.msgtype() {
|
||||||
case .text(content: let content):
|
case .text(content: let content):
|
||||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
return buildTextTimelineItem(for: eventItemProxy, messageTimelineItem, content, isOutgoing)
|
||||||
return buildTextTimelineItemFromMessage(eventItemProxy, message, isOutgoing)
|
|
||||||
case .image(content: let content):
|
case .image(content: let content):
|
||||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
return buildImageTimelineItem(for: eventItemProxy, messageTimelineItem, content, isOutgoing)
|
||||||
return buildImageTimelineItemFromMessage(eventItemProxy, message, isOutgoing)
|
|
||||||
case .video(let content):
|
case .video(let content):
|
||||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
return buildVideoTimelineItem(for: eventItemProxy, messageTimelineItem, content, isOutgoing)
|
||||||
return buildVideoTimelineItemFromMessage(eventItemProxy, message, isOutgoing)
|
|
||||||
case .file(let content):
|
case .file(let content):
|
||||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
return buildFileTimelineItem(for: eventItemProxy, messageTimelineItem, content, isOutgoing)
|
||||||
return buildFileTimelineItemFromMessage(eventItemProxy, message, isOutgoing)
|
|
||||||
case .notice(content: let content):
|
case .notice(content: let content):
|
||||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
return buildNoticeTimelineItem(for: eventItemProxy, messageTimelineItem, content, isOutgoing)
|
||||||
return buildNoticeTimelineItemFromMessage(eventItemProxy, message, isOutgoing)
|
|
||||||
case .emote(content: let content):
|
case .emote(content: let content):
|
||||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
return buildEmoteTimelineItem(for: eventItemProxy, messageTimelineItem, content, isOutgoing)
|
||||||
return buildEmoteTimelineItemFromMessage(eventItemProxy, message, isOutgoing)
|
|
||||||
case .audio(let content):
|
case .audio(let content):
|
||||||
let message = MessageTimelineItem(item: eventItemProxy.item, content: content)
|
return buildAudioTimelineItem(for: eventItemProxy, messageTimelineItem, content, isOutgoing)
|
||||||
return buildAudioTimelineItem(eventItemProxy, message, isOutgoing)
|
|
||||||
case .none:
|
case .none:
|
||||||
return buildFallbackTimelineItem(eventItemProxy, isOutgoing)
|
return nil
|
||||||
}
|
}
|
||||||
case .state(let stateKey, let content):
|
case .state(let stateKey, let content):
|
||||||
return buildStateTimelineItemFor(eventItemProxy: eventItemProxy, state: content, stateKey: stateKey, isOutgoing: isOutgoing)
|
return buildStateTimelineItem(for: eventItemProxy, state: content, stateKey: stateKey, isOutgoing: isOutgoing)
|
||||||
case .roomMembership(userId: let userID, change: let change):
|
case .roomMembership(userId: let userID, change: let change):
|
||||||
return buildStateMembershipChangeTimelineItemFor(eventItemProxy: eventItemProxy, member: userID, membershipChange: change, isOutgoing: isOutgoing)
|
return buildStateMembershipChangeTimelineItem(for: eventItemProxy, member: userID, membershipChange: change, isOutgoing: isOutgoing)
|
||||||
case .profileChange(let displayName, let prevDisplayName, let avatarUrl, let prevAvatarUrl):
|
case .profileChange(let displayName, let prevDisplayName, let avatarUrl, let prevAvatarUrl):
|
||||||
return buildStateProfileChangeTimelineItemFor(eventItemProxy: eventItemProxy, displayName: displayName, previousDisplayName: prevDisplayName, avatarURLString: avatarUrl, previousAvatarURLString: prevAvatarUrl, isOutgoing: isOutgoing)
|
return buildStateProfileChangeTimelineItem(for: eventItemProxy,
|
||||||
|
displayName: displayName,
|
||||||
|
previousDisplayName: prevDisplayName,
|
||||||
|
avatarURLString: avatarUrl,
|
||||||
|
previousAvatarURLString: prevAvatarUrl,
|
||||||
|
isOutgoing: isOutgoing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,166 +168,117 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
|||||||
sender: eventItemProxy.sender,
|
sender: eventItemProxy.sender,
|
||||||
properties: RoomTimelineItemProperties())
|
properties: RoomTimelineItemProperties())
|
||||||
}
|
}
|
||||||
|
|
||||||
private func buildFallbackTimelineItem(_ eventItemProxy: EventTimelineItemProxy,
|
|
||||||
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
|
||||||
let formattedBody = attributedStringBuilder.fromPlain(eventItemProxy.body)
|
|
||||||
|
|
||||||
return TextRoomTimelineItem(id: eventItemProxy.id,
|
|
||||||
body: eventItemProxy.body ?? "",
|
|
||||||
formattedBody: formattedBody,
|
|
||||||
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
|
||||||
isOutgoing: isOutgoing,
|
|
||||||
isEditable: eventItemProxy.isEditable,
|
|
||||||
sender: eventItemProxy.sender,
|
|
||||||
properties: RoomTimelineItemProperties(isEdited: eventItemProxy.content.asMessage()?.isEdited() ?? false,
|
|
||||||
reactions: aggregateReactions(eventItemProxy.reactions)))
|
|
||||||
}
|
|
||||||
|
|
||||||
private func buildTextTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
private func buildTextTimelineItem(for eventItemProxy: EventTimelineItemProxy,
|
||||||
_ message: MessageTimelineItem<TextMessageContent>,
|
_ messageTimelineItem: Message,
|
||||||
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
_ messageContent: TextMessageContent,
|
||||||
let formattedBody = (message.htmlBody != nil ? attributedStringBuilder.fromHTML(message.htmlBody) : attributedStringBuilder.fromPlain(message.body))
|
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
||||||
|
TextRoomTimelineItem(id: eventItemProxy.id,
|
||||||
return TextRoomTimelineItem(id: message.id,
|
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||||
body: message.body,
|
|
||||||
formattedBody: formattedBody,
|
|
||||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
|
||||||
isOutgoing: isOutgoing,
|
|
||||||
isEditable: eventItemProxy.isEditable,
|
|
||||||
sender: eventItemProxy.sender,
|
|
||||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
|
||||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
|
||||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
|
||||||
}
|
|
||||||
|
|
||||||
private func buildImageTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
|
||||||
_ message: MessageTimelineItem<ImageMessageContent>,
|
|
||||||
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
|
||||||
var aspectRatio: CGFloat?
|
|
||||||
if let width = message.width,
|
|
||||||
let height = message.height {
|
|
||||||
aspectRatio = width / height
|
|
||||||
}
|
|
||||||
|
|
||||||
return ImageRoomTimelineItem(id: message.id,
|
|
||||||
body: message.body,
|
|
||||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
|
||||||
isOutgoing: isOutgoing,
|
|
||||||
isEditable: eventItemProxy.isEditable,
|
|
||||||
sender: eventItemProxy.sender,
|
|
||||||
source: message.source,
|
|
||||||
width: message.width,
|
|
||||||
height: message.height,
|
|
||||||
aspectRatio: aspectRatio,
|
|
||||||
blurhash: message.blurhash,
|
|
||||||
contentType: message.contentType,
|
|
||||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
|
||||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
|
||||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
|
||||||
}
|
|
||||||
|
|
||||||
private func buildVideoTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
|
||||||
_ message: MessageTimelineItem<VideoMessageContent>,
|
|
||||||
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
|
||||||
var aspectRatio: CGFloat?
|
|
||||||
if let width = message.width,
|
|
||||||
let height = message.height {
|
|
||||||
aspectRatio = width / height
|
|
||||||
}
|
|
||||||
|
|
||||||
return VideoRoomTimelineItem(id: message.id,
|
|
||||||
body: message.body,
|
|
||||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
|
||||||
isOutgoing: isOutgoing,
|
|
||||||
isEditable: eventItemProxy.isEditable,
|
|
||||||
sender: eventItemProxy.sender,
|
|
||||||
duration: message.duration,
|
|
||||||
source: message.source,
|
|
||||||
thumbnailSource: message.thumbnailSource,
|
|
||||||
width: message.width,
|
|
||||||
height: message.height,
|
|
||||||
aspectRatio: aspectRatio,
|
|
||||||
blurhash: message.blurhash,
|
|
||||||
contentType: message.contentType,
|
|
||||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
|
||||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
|
||||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
|
||||||
}
|
|
||||||
|
|
||||||
private func buildAudioTimelineItem(_ eventItemProxy: EventTimelineItemProxy,
|
|
||||||
_ message: MessageTimelineItem<AudioMessageContent>,
|
|
||||||
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
|
||||||
AudioRoomTimelineItem(id: eventItemProxy.id,
|
|
||||||
body: message.body,
|
|
||||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
|
||||||
isOutgoing: isOutgoing,
|
|
||||||
isEditable: eventItemProxy.isEditable,
|
|
||||||
sender: eventItemProxy.sender,
|
|
||||||
duration: message.duration,
|
|
||||||
source: message.source,
|
|
||||||
contentType: message.contentType,
|
|
||||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
|
||||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
|
||||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
|
||||||
}
|
|
||||||
|
|
||||||
private func buildFileTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
|
||||||
_ message: MessageTimelineItem<FileMessageContent>,
|
|
||||||
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
|
||||||
FileRoomTimelineItem(id: message.id,
|
|
||||||
body: message.body,
|
|
||||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
|
||||||
isOutgoing: isOutgoing,
|
isOutgoing: isOutgoing,
|
||||||
isEditable: eventItemProxy.isEditable,
|
isEditable: eventItemProxy.isEditable,
|
||||||
sender: eventItemProxy.sender,
|
sender: eventItemProxy.sender,
|
||||||
source: message.source,
|
content: buildTextTimelineItemContent(messageContent),
|
||||||
thumbnailSource: message.thumbnailSource,
|
replyDetails: buildReplyToDetailsFrom(details: messageTimelineItem.inReplyTo()),
|
||||||
contentType: message.contentType,
|
properties: RoomTimelineItemProperties(isEdited: messageTimelineItem.isEdited(),
|
||||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
|
||||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||||
}
|
}
|
||||||
|
|
||||||
private func buildNoticeTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
private func buildImageTimelineItem(for eventItemProxy: EventTimelineItemProxy,
|
||||||
_ message: MessageTimelineItem<NoticeMessageContent>,
|
_ messageTimelineItem: Message,
|
||||||
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
_ messageContent: ImageMessageContent,
|
||||||
let formattedBody = (message.htmlBody != nil ? attributedStringBuilder.fromHTML(message.htmlBody) : attributedStringBuilder.fromPlain(message.body))
|
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
||||||
|
ImageRoomTimelineItem(id: eventItemProxy.id,
|
||||||
return NoticeRoomTimelineItem(id: message.id,
|
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||||
body: message.body,
|
isOutgoing: isOutgoing,
|
||||||
formattedBody: formattedBody,
|
isEditable: eventItemProxy.isEditable,
|
||||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
sender: eventItemProxy.sender,
|
||||||
isOutgoing: isOutgoing,
|
content: buildImageTimelineItemContent(messageContent),
|
||||||
isEditable: eventItemProxy.isEditable,
|
replyDetails: buildReplyToDetailsFrom(details: messageTimelineItem.inReplyTo()),
|
||||||
sender: eventItemProxy.sender,
|
properties: RoomTimelineItemProperties(isEdited: messageTimelineItem.isEdited(),
|
||||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func buildEmoteTimelineItemFromMessage(_ eventItemProxy: EventTimelineItemProxy,
|
private func buildVideoTimelineItem(for eventItemProxy: EventTimelineItemProxy,
|
||||||
_ message: MessageTimelineItem<EmoteMessageContent>,
|
_ messageTimelineItem: Message,
|
||||||
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
_ messageContent: VideoMessageContent,
|
||||||
let name = eventItemProxy.sender.displayName ?? eventItemProxy.sender.id
|
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
||||||
|
VideoRoomTimelineItem(id: eventItemProxy.id,
|
||||||
var formattedBody: AttributedString?
|
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||||
if let htmlBody = message.htmlBody {
|
isOutgoing: isOutgoing,
|
||||||
formattedBody = attributedStringBuilder.fromHTML("* \(name) \(htmlBody)")
|
isEditable: eventItemProxy.isEditable,
|
||||||
} else {
|
sender: eventItemProxy.sender,
|
||||||
formattedBody = attributedStringBuilder.fromPlain("* \(name) \(message.body)")
|
content: buildVideoTimelineItemContent(messageContent),
|
||||||
}
|
replyDetails: buildReplyToDetailsFrom(details: messageTimelineItem.inReplyTo()),
|
||||||
|
properties: RoomTimelineItemProperties(isEdited: messageTimelineItem.isEdited(),
|
||||||
return EmoteRoomTimelineItem(id: message.id,
|
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||||
body: message.body,
|
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||||
formattedBody: formattedBody,
|
}
|
||||||
timestamp: message.timestamp.formatted(date: .omitted, time: .shortened),
|
|
||||||
isOutgoing: isOutgoing,
|
private func buildAudioTimelineItem(for eventItemProxy: EventTimelineItemProxy,
|
||||||
isEditable: eventItemProxy.isEditable,
|
_ messageTimelineItem: Message,
|
||||||
sender: eventItemProxy.sender,
|
_ messageContent: AudioMessageContent,
|
||||||
properties: RoomTimelineItemProperties(isEdited: message.isEdited,
|
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
||||||
reactions: aggregateReactions(eventItemProxy.reactions),
|
AudioRoomTimelineItem(id: eventItemProxy.id,
|
||||||
deliveryStatus: eventItemProxy.deliveryStatus))
|
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||||
|
isOutgoing: isOutgoing,
|
||||||
|
isEditable: eventItemProxy.isEditable,
|
||||||
|
sender: eventItemProxy.sender,
|
||||||
|
content: buildAudioTimelineItemContent(messageContent),
|
||||||
|
replyDetails: buildReplyToDetailsFrom(details: messageTimelineItem.inReplyTo()),
|
||||||
|
properties: RoomTimelineItemProperties(isEdited: messageTimelineItem.isEdited(),
|
||||||
|
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||||
|
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func buildFileTimelineItem(for eventItemProxy: EventTimelineItemProxy,
|
||||||
|
_ messageTimelineItem: Message,
|
||||||
|
_ messageContent: FileMessageContent,
|
||||||
|
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
||||||
|
FileRoomTimelineItem(id: eventItemProxy.id,
|
||||||
|
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||||
|
isOutgoing: isOutgoing,
|
||||||
|
isEditable: eventItemProxy.isEditable,
|
||||||
|
sender: eventItemProxy.sender,
|
||||||
|
content: buildFileTimelineItemContent(messageContent),
|
||||||
|
replyDetails: buildReplyToDetailsFrom(details: messageTimelineItem.inReplyTo()),
|
||||||
|
properties: RoomTimelineItemProperties(isEdited: messageTimelineItem.isEdited(),
|
||||||
|
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||||
|
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func buildNoticeTimelineItem(for eventItemProxy: EventTimelineItemProxy,
|
||||||
|
_ messageTimelineItem: Message,
|
||||||
|
_ messageContent: NoticeMessageContent,
|
||||||
|
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
||||||
|
NoticeRoomTimelineItem(id: eventItemProxy.id,
|
||||||
|
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||||
|
isOutgoing: isOutgoing,
|
||||||
|
isEditable: eventItemProxy.isEditable,
|
||||||
|
sender: eventItemProxy.sender,
|
||||||
|
content: buildNoticeTimelineItemContent(messageContent),
|
||||||
|
replyDetails: buildReplyToDetailsFrom(details: messageTimelineItem.inReplyTo()),
|
||||||
|
properties: RoomTimelineItemProperties(isEdited: messageTimelineItem.isEdited(),
|
||||||
|
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||||
|
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func buildEmoteTimelineItem(for eventItemProxy: EventTimelineItemProxy,
|
||||||
|
_ messageTimelineItem: Message,
|
||||||
|
_ messageContent: EmoteMessageContent,
|
||||||
|
_ isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
||||||
|
EmoteRoomTimelineItem(id: eventItemProxy.id,
|
||||||
|
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||||
|
isOutgoing: isOutgoing,
|
||||||
|
isEditable: eventItemProxy.isEditable,
|
||||||
|
sender: eventItemProxy.sender,
|
||||||
|
content: buildEmoteTimelineItemContent(senderDisplayName: eventItemProxy.sender.displayName, senderID: eventItemProxy.sender.id, messageContent: messageContent),
|
||||||
|
replyDetails: buildReplyToDetailsFrom(details: messageTimelineItem.inReplyTo()),
|
||||||
|
properties: RoomTimelineItemProperties(isEdited: messageTimelineItem.isEdited(),
|
||||||
|
reactions: aggregateReactions(eventItemProxy.reactions),
|
||||||
|
deliveryStatus: eventItemProxy.deliveryStatus))
|
||||||
}
|
}
|
||||||
|
|
||||||
private func aggregateReactions(_ reactions: [Reaction]) -> [AggregatedReaction] {
|
private func aggregateReactions(_ reactions: [Reaction]) -> [AggregatedReaction] {
|
||||||
@@ -338,41 +288,129 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - State Events
|
// MARK: - Message events content
|
||||||
|
|
||||||
private func buildStateTimelineItemFor(eventItemProxy: EventTimelineItemProxy,
|
private func buildTextTimelineItemContent(_ messageContent: TextMessageContent) -> TextRoomTimelineItemContent {
|
||||||
state: OtherState,
|
let htmlBody = messageContent.formatted?.format == .html ? messageContent.formatted?.body : nil
|
||||||
stateKey: String,
|
let formattedBody = (htmlBody != nil ? attributedStringBuilder.fromHTML(htmlBody) : attributedStringBuilder.fromPlain(messageContent.body))
|
||||||
isOutgoing: Bool) -> RoomTimelineItemProtocol? {
|
|
||||||
guard let text = stateEventStringBuilder.buildString(for: state, stateKey: stateKey, sender: eventItemProxy.sender, isOutgoing: isOutgoing) else { return nil }
|
return .init(body: messageContent.body, formattedBody: formattedBody)
|
||||||
return buildStateTimelineItem(eventItemProxy: eventItemProxy, text: text, isOutgoing: isOutgoing)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func buildStateMembershipChangeTimelineItemFor(eventItemProxy: EventTimelineItemProxy,
|
private func buildAudioTimelineItemContent(_ messageContent: AudioMessageContent) -> AudioRoomTimelineItemContent {
|
||||||
member: String,
|
AudioRoomTimelineItemContent(body: messageContent.body,
|
||||||
membershipChange: MembershipChange?,
|
duration: messageContent.info?.duration ?? 0,
|
||||||
isOutgoing: Bool) -> RoomTimelineItemProtocol? {
|
source: MediaSourceProxy(source: messageContent.source, mimeType: messageContent.info?.mimetype),
|
||||||
|
contentType: UTType(mimeType: messageContent.info?.mimetype, fallbackFilename: messageContent.body))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func buildImageTimelineItemContent(_ messageContent: ImageMessageContent) -> ImageRoomTimelineItemContent {
|
||||||
|
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 {
|
||||||
|
aspectRatio = width / height
|
||||||
|
}
|
||||||
|
|
||||||
|
return .init(body: messageContent.body,
|
||||||
|
source: MediaSourceProxy(source: messageContent.source, mimeType: messageContent.info?.mimetype),
|
||||||
|
thumbnailSource: thumbnailSource,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
aspectRatio: aspectRatio,
|
||||||
|
blurhash: messageContent.info?.blurhash,
|
||||||
|
contentType: UTType(mimeType: messageContent.info?.mimetype, fallbackFilename: messageContent.body))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func buildVideoTimelineItemContent(_ messageContent: VideoMessageContent) -> VideoRoomTimelineItemContent {
|
||||||
|
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 {
|
||||||
|
aspectRatio = width / height
|
||||||
|
}
|
||||||
|
|
||||||
|
return .init(body: messageContent.body,
|
||||||
|
duration: messageContent.info?.duration ?? 0,
|
||||||
|
source: MediaSourceProxy(source: messageContent.source, mimeType: messageContent.info?.mimetype),
|
||||||
|
thumbnailSource: thumbnailSource,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
aspectRatio: aspectRatio,
|
||||||
|
blurhash: messageContent.info?.blurhash,
|
||||||
|
contentType: UTType(mimeType: messageContent.info?.mimetype, fallbackFilename: messageContent.body))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func buildFileTimelineItemContent(_ messageContent: FileMessageContent) -> FileRoomTimelineItemContent {
|
||||||
|
let thumbnailSource = messageContent.info?.thumbnailSource.map { MediaSourceProxy(source: $0, mimeType: messageContent.info?.thumbnailInfo?.mimetype) }
|
||||||
|
|
||||||
|
return .init(body: messageContent.body,
|
||||||
|
source: MediaSourceProxy(source: messageContent.source, mimeType: messageContent.info?.mimetype),
|
||||||
|
thumbnailSource: thumbnailSource,
|
||||||
|
contentType: UTType(mimeType: messageContent.info?.mimetype, fallbackFilename: messageContent.body))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func buildNoticeTimelineItemContent(_ messageContent: NoticeMessageContent) -> NoticeRoomTimelineItemContent {
|
||||||
|
let htmlBody = messageContent.formatted?.format == .html ? messageContent.formatted?.body : nil
|
||||||
|
let formattedBody = (htmlBody != nil ? attributedStringBuilder.fromHTML(htmlBody) : attributedStringBuilder.fromPlain(messageContent.body))
|
||||||
|
|
||||||
|
return .init(body: messageContent.body, formattedBody: formattedBody)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func buildEmoteTimelineItemContent(senderDisplayName: String?, senderID: String, messageContent: EmoteMessageContent) -> EmoteRoomTimelineItemContent {
|
||||||
|
let name = senderDisplayName ?? senderID
|
||||||
|
|
||||||
|
let htmlBody = messageContent.formatted?.format == .html ? messageContent.formatted?.body : nil
|
||||||
|
|
||||||
|
var formattedBody: AttributedString?
|
||||||
|
if let htmlBody {
|
||||||
|
formattedBody = attributedStringBuilder.fromHTML(L10n.commonEmote(name, htmlBody))
|
||||||
|
} else {
|
||||||
|
formattedBody = attributedStringBuilder.fromPlain(L10n.commonEmote(name, messageContent.body))
|
||||||
|
}
|
||||||
|
|
||||||
|
return .init(body: messageContent.body, formattedBody: formattedBody)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - State Events
|
||||||
|
|
||||||
|
private func buildStateTimelineItem(for eventItemProxy: EventTimelineItemProxy,
|
||||||
|
state: OtherState,
|
||||||
|
stateKey: String,
|
||||||
|
isOutgoing: Bool) -> RoomTimelineItemProtocol? {
|
||||||
|
guard let text = stateEventStringBuilder.buildString(for: state, stateKey: stateKey, sender: eventItemProxy.sender, isOutgoing: isOutgoing) else { return nil }
|
||||||
|
return buildStateTimelineItem(for: eventItemProxy, text: text, isOutgoing: isOutgoing)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func buildStateMembershipChangeTimelineItem(for eventItemProxy: EventTimelineItemProxy,
|
||||||
|
member: String,
|
||||||
|
membershipChange: MembershipChange?,
|
||||||
|
isOutgoing: Bool) -> RoomTimelineItemProtocol? {
|
||||||
guard let text = stateEventStringBuilder.buildString(for: membershipChange, member: member, sender: eventItemProxy.sender, isOutgoing: isOutgoing) else { return nil }
|
guard let text = stateEventStringBuilder.buildString(for: membershipChange, member: member, sender: eventItemProxy.sender, isOutgoing: isOutgoing) else { return nil }
|
||||||
return buildStateTimelineItem(eventItemProxy: eventItemProxy, text: text, isOutgoing: isOutgoing)
|
return buildStateTimelineItem(for: eventItemProxy, text: text, isOutgoing: isOutgoing)
|
||||||
}
|
}
|
||||||
|
|
||||||
// swiftlint:disable:next function_parameter_count
|
// swiftlint:disable:next function_parameter_count
|
||||||
private func buildStateProfileChangeTimelineItemFor(eventItemProxy: EventTimelineItemProxy,
|
private func buildStateProfileChangeTimelineItem(for eventItemProxy: EventTimelineItemProxy,
|
||||||
displayName: String?,
|
displayName: String?,
|
||||||
previousDisplayName: String?,
|
previousDisplayName: String?,
|
||||||
avatarURLString: String?,
|
avatarURLString: String?,
|
||||||
previousAvatarURLString: String?,
|
previousAvatarURLString: String?,
|
||||||
isOutgoing: Bool) -> RoomTimelineItemProtocol? {
|
isOutgoing: Bool) -> RoomTimelineItemProtocol? {
|
||||||
guard let text = stateEventStringBuilder.buildProfileChangeString(displayName: displayName,
|
guard let text = stateEventStringBuilder.buildProfileChangeString(displayName: displayName,
|
||||||
previousDisplayName: previousDisplayName,
|
previousDisplayName: previousDisplayName,
|
||||||
avatarURLString: avatarURLString,
|
avatarURLString: avatarURLString,
|
||||||
previousAvatarURLString: previousAvatarURLString,
|
previousAvatarURLString: previousAvatarURLString,
|
||||||
member: eventItemProxy.sender.id,
|
member: eventItemProxy.sender.id,
|
||||||
memberIsYou: isOutgoing) else { return nil }
|
memberIsYou: isOutgoing) else { return nil }
|
||||||
return buildStateTimelineItem(eventItemProxy: eventItemProxy, text: text, isOutgoing: isOutgoing)
|
return buildStateTimelineItem(for: eventItemProxy, text: text, isOutgoing: isOutgoing)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func buildStateTimelineItem(eventItemProxy: EventTimelineItemProxy, text: String, isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
private func buildStateTimelineItem(for eventItemProxy: EventTimelineItemProxy, text: String, isOutgoing: Bool) -> RoomTimelineItemProtocol {
|
||||||
StateRoomTimelineItem(id: eventItemProxy.id,
|
StateRoomTimelineItem(id: eventItemProxy.id,
|
||||||
body: text,
|
body: text,
|
||||||
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
timestamp: eventItemProxy.timestamp.formatted(date: .omitted, time: .shortened),
|
||||||
@@ -380,4 +418,54 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
|
|||||||
isEditable: false,
|
isEditable: false,
|
||||||
sender: eventItemProxy.sender)
|
sender: eventItemProxy.sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Reply details
|
||||||
|
|
||||||
|
// swiftlint:disable:next cyclomatic_complexity
|
||||||
|
private func buildReplyToDetailsFrom(details: InReplyToDetails?) -> TimelineItemReplyDetails? {
|
||||||
|
guard let details else { return nil }
|
||||||
|
|
||||||
|
switch details.event {
|
||||||
|
case .unavailable:
|
||||||
|
return .notLoaded(eventID: details.eventId)
|
||||||
|
case .pending:
|
||||||
|
return .loading(eventID: details.eventId)
|
||||||
|
case let .ready(message, senderID, senderProfile):
|
||||||
|
let sender: TimelineItemSender
|
||||||
|
switch senderProfile {
|
||||||
|
case let .ready(displayName, _, avatarUrl):
|
||||||
|
sender = TimelineItemSender(id: senderID,
|
||||||
|
displayName: displayName,
|
||||||
|
avatarURL: avatarUrl.flatMap(URL.init(string:)))
|
||||||
|
default:
|
||||||
|
sender = TimelineItemSender(id: senderID,
|
||||||
|
displayName: nil,
|
||||||
|
avatarURL: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
let replyContent: TimelineItemReplyContent
|
||||||
|
switch message.msgtype() {
|
||||||
|
case .audio(let content):
|
||||||
|
replyContent = .audio(buildAudioTimelineItemContent(content))
|
||||||
|
case .emote(let content):
|
||||||
|
replyContent = .emote(buildEmoteTimelineItemContent(senderDisplayName: sender.displayName, senderID: sender.id, messageContent: content))
|
||||||
|
case .file(let content):
|
||||||
|
replyContent = .file(buildFileTimelineItemContent(content))
|
||||||
|
case .image(let content):
|
||||||
|
replyContent = .image(buildImageTimelineItemContent(content))
|
||||||
|
case .notice(let content):
|
||||||
|
replyContent = .notice(buildNoticeTimelineItemContent(content))
|
||||||
|
case .text(let content):
|
||||||
|
replyContent = .text(buildTextTimelineItemContent(content))
|
||||||
|
case .video(let content):
|
||||||
|
replyContent = .video(buildVideoTimelineItemContent(content))
|
||||||
|
case .none:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return .loaded(sender: sender, content: replyContent)
|
||||||
|
case let .error(message):
|
||||||
|
return .error(eventID: details.eventId, message: message)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -18,5 +18,5 @@ import Foundation
|
|||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
protocol RoomTimelineItemFactoryProtocol {
|
protocol RoomTimelineItemFactoryProtocol {
|
||||||
func buildTimelineItemFor(eventItemProxy: EventTimelineItemProxy) -> RoomTimelineItemProtocol?
|
func buildTimelineItem(for eventItemProxy: EventTimelineItemProxy) -> RoomTimelineItemProtocol?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -341,7 +341,6 @@ class AttributedStringBuilderTests: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertTrue(component.isBlockquote, "The reply quote should be a blockquote.")
|
XCTAssertTrue(component.isBlockquote, "The reply quote should be a blockquote.")
|
||||||
XCTAssertTrue(component.isReply, "The reply quote should be detected as a reply")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMultipleGroupedBlockquotes() {
|
func testMultipleGroupedBlockquotes() {
|
||||||
@@ -388,9 +387,6 @@ class AttributedStringBuilderTests: XCTestCase {
|
|||||||
let coalescedComponents = attributedString.formattedComponents
|
let coalescedComponents = attributedString.formattedComponents
|
||||||
|
|
||||||
XCTAssertEqual(coalescedComponents.count, 6)
|
XCTAssertEqual(coalescedComponents.count, 6)
|
||||||
for component in coalescedComponents where component.isReply {
|
|
||||||
XCTFail("None of the blockquotes should be detected as replies.")
|
|
||||||
}
|
|
||||||
|
|
||||||
var numberOfBlockquotes = 0
|
var numberOfBlockquotes = 0
|
||||||
for run in attributedString.runs where run.elementX.blockquote ?? false && run.link != nil {
|
for run in attributedString.runs where run.elementX.blockquote ?? false && run.link != nil {
|
||||||
|
|||||||
@@ -186,37 +186,55 @@ class LoggingTests: XCTestCase {
|
|||||||
XCTFail(Constants.genericFailure)
|
XCTFail(Constants.genericFailure)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = try String(contentsOf: logFile)
|
let content = try String(contentsOf: logFile)
|
||||||
XCTAssertTrue(content.contains(roomSummary.id))
|
XCTAssertTrue(content.contains(roomSummary.id))
|
||||||
XCTAssertFalse(content.contains(roomName))
|
XCTAssertFalse(content.contains(roomName))
|
||||||
XCTAssertFalse(content.contains(lastMessage))
|
XCTAssertFalse(content.contains(lastMessage))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swiftlint:disable:next function_body_length
|
||||||
func testTimelineContentIsRedacted() throws {
|
func testTimelineContentIsRedacted() throws {
|
||||||
// Given timeline items that contain text
|
// Given timeline items that contain text
|
||||||
let textAttributedString = "TextAttributed"
|
let textAttributedString = "TextAttributed"
|
||||||
let textMessage = TextRoomTimelineItem(id: "mytextmessage", body: "TextString",
|
let textMessage = TextRoomTimelineItem(id: "mytextmessage",
|
||||||
formattedBody: AttributedString(textAttributedString),
|
timestamp: "",
|
||||||
timestamp: "", isOutgoing: false, isEditable: false, sender: .init(id: "sender"))
|
isOutgoing: false,
|
||||||
|
isEditable: false,
|
||||||
|
sender: .init(id: "sender"),
|
||||||
|
content: .init(body: "TextString", formattedBody: AttributedString(textAttributedString)))
|
||||||
let noticeAttributedString = "NoticeAttributed"
|
let noticeAttributedString = "NoticeAttributed"
|
||||||
let noticeMessage = NoticeRoomTimelineItem(id: "mynoticemessage", body: "NoticeString",
|
let noticeMessage = NoticeRoomTimelineItem(id: "mynoticemessage",
|
||||||
formattedBody: AttributedString(noticeAttributedString),
|
timestamp: "",
|
||||||
timestamp: "", isOutgoing: false, isEditable: false, sender: .init(id: "sender"))
|
isOutgoing: false,
|
||||||
|
isEditable: false,
|
||||||
|
sender: .init(id: "sender"),
|
||||||
|
content: .init(body: "NoticeString", formattedBody: AttributedString(noticeAttributedString)))
|
||||||
let emoteAttributedString = "EmoteAttributed"
|
let emoteAttributedString = "EmoteAttributed"
|
||||||
let emoteMessage = EmoteRoomTimelineItem(id: "myemotemessage", body: "EmoteString",
|
let emoteMessage = EmoteRoomTimelineItem(id: "myemotemessage",
|
||||||
formattedBody: AttributedString(emoteAttributedString),
|
timestamp: "",
|
||||||
timestamp: "", isOutgoing: false, isEditable: false, sender: .init(id: "sender"))
|
isOutgoing: false,
|
||||||
let imageMessage = ImageRoomTimelineItem(id: "myimagemessage", body: "ImageString",
|
isEditable: false,
|
||||||
timestamp: "", isOutgoing: false, isEditable: false,
|
|
||||||
sender: .init(id: "sender"),
|
sender: .init(id: "sender"),
|
||||||
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/gif"))
|
content: .init(body: "EmoteString", formattedBody: AttributedString(emoteAttributedString)))
|
||||||
let videoMessage = VideoRoomTimelineItem(id: "myvideomessage", body: "VideoString",
|
let imageMessage = ImageRoomTimelineItem(id: "myimagemessage",
|
||||||
timestamp: "", isOutgoing: false, isEditable: false,
|
timestamp: "",
|
||||||
sender: .init(id: "sender"), duration: 0, source: nil, thumbnailSource: nil)
|
isOutgoing: false,
|
||||||
let fileMessage = FileRoomTimelineItem(id: "myfilemessage", body: "FileString",
|
isEditable: false,
|
||||||
timestamp: "", isOutgoing: false, isEditable: false,
|
sender: .init(id: "sender"),
|
||||||
sender: .init(id: "sender"), source: nil, thumbnailSource: nil)
|
content: .init(body: "ImageString", source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/gif"), thumbnailSource: nil))
|
||||||
|
let videoMessage = VideoRoomTimelineItem(id: "myvideomessage",
|
||||||
|
timestamp: "",
|
||||||
|
isOutgoing: false,
|
||||||
|
isEditable: false,
|
||||||
|
sender: .init(id: "sender"),
|
||||||
|
content: .init(body: "VideoString", duration: 0, source: nil, thumbnailSource: nil))
|
||||||
|
let fileMessage = FileRoomTimelineItem(id: "myfilemessage",
|
||||||
|
timestamp: "",
|
||||||
|
isOutgoing: false,
|
||||||
|
isEditable: false,
|
||||||
|
sender: .init(id: "sender"),
|
||||||
|
content: .init(body: "FileString", source: nil, thumbnailSource: nil, contentType: nil))
|
||||||
|
|
||||||
// When logging that value
|
// When logging that value
|
||||||
XCTAssert(MXLogger.logFiles.isEmpty)
|
XCTAssert(MXLogger.logFiles.isEmpty)
|
||||||
|
|||||||
@@ -1,168 +0,0 @@
|
|||||||
//
|
|
||||||
// Copyright 2023 New Vector Ltd
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
//
|
|
||||||
|
|
||||||
@testable import ElementX
|
|
||||||
import MatrixRustSDK
|
|
||||||
import XCTest
|
|
||||||
|
|
||||||
class MessageTimelineItemTests: XCTestCase {
|
|
||||||
// MARK: Image
|
|
||||||
|
|
||||||
func testImageContentType() {
|
|
||||||
let mimetype = "image/gif"
|
|
||||||
let imageContent = ImageMessageContent(body: "amazing.gif",
|
|
||||||
source: mediaSourceFromUrl(url: "mxc://doesnt/matter"),
|
|
||||||
info: makeImageInfo(mimetype: mimetype))
|
|
||||||
let messageItem = MockEventTimelineItem.message(from: imageContent)
|
|
||||||
XCTAssertEqual(messageItem.contentType, .gif)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testImageContentTypeWithoutMimetype() {
|
|
||||||
let imageContent = ImageMessageContent(body: "amazing.jpeg",
|
|
||||||
source: mediaSourceFromUrl(url: "mxc://doesnt/matter"),
|
|
||||||
info: makeImageInfo(mimetype: nil))
|
|
||||||
let messageItem = MockEventTimelineItem.message(from: imageContent)
|
|
||||||
XCTAssertEqual(messageItem.contentType, .jpeg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeImageInfo(mimetype: String?) -> ImageInfo {
|
|
||||||
ImageInfo(height: nil,
|
|
||||||
width: nil,
|
|
||||||
mimetype: mimetype,
|
|
||||||
size: nil,
|
|
||||||
thumbnailInfo: nil,
|
|
||||||
thumbnailSource: nil,
|
|
||||||
blurhash: nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: Video
|
|
||||||
|
|
||||||
func testVideoContentType() {
|
|
||||||
let mimetype = "video/x-msvideo"
|
|
||||||
let imageContent = VideoMessageContent(body: "amazing.avi",
|
|
||||||
source: mediaSourceFromUrl(url: "mxc://doesnt/matter"),
|
|
||||||
info: makeVideoInfo(mimetype: mimetype))
|
|
||||||
let messageItem = MockEventTimelineItem.message(from: imageContent)
|
|
||||||
XCTAssertEqual(messageItem.contentType, .avi)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testVideoContentTypeWithoutMimetype() {
|
|
||||||
let imageContent = VideoMessageContent(body: "amazing.mp4",
|
|
||||||
source: mediaSourceFromUrl(url: "mxc://doesnt/matter"),
|
|
||||||
info: makeVideoInfo(mimetype: nil))
|
|
||||||
let messageItem = MockEventTimelineItem.message(from: imageContent)
|
|
||||||
XCTAssertEqual(messageItem.contentType, .mpeg4Movie)
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeVideoInfo(mimetype: String?) -> VideoInfo {
|
|
||||||
VideoInfo(duration: nil,
|
|
||||||
height: nil,
|
|
||||||
width: nil,
|
|
||||||
mimetype: mimetype,
|
|
||||||
size: nil,
|
|
||||||
thumbnailInfo: nil,
|
|
||||||
thumbnailSource: nil,
|
|
||||||
blurhash: nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: Audio
|
|
||||||
|
|
||||||
func testAudioContentType() {
|
|
||||||
let mimetype = "audio/mp3"
|
|
||||||
let imageContent = AudioMessageContent(body: "amazing.mp3",
|
|
||||||
source: mediaSourceFromUrl(url: "mxc://doesnt/matter"),
|
|
||||||
info: makeAudioInfo(mimetype: mimetype))
|
|
||||||
let messageItem = MockEventTimelineItem.message(from: imageContent)
|
|
||||||
XCTAssertEqual(messageItem.contentType, .mp3)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testAudioContentTypeWithoutMimetype() {
|
|
||||||
let imageContent = AudioMessageContent(body: "amazing.m4a",
|
|
||||||
source: mediaSourceFromUrl(url: "mxc://doesnt/matter"),
|
|
||||||
info: makeAudioInfo(mimetype: nil))
|
|
||||||
let messageItem = MockEventTimelineItem.message(from: imageContent)
|
|
||||||
|
|
||||||
// swiftlint:disable:next force_unwrapping
|
|
||||||
XCTAssertTrue(messageItem.contentType!.conforms(to: .mpeg4Audio))
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeAudioInfo(mimetype: String?) -> AudioInfo {
|
|
||||||
AudioInfo(duration: nil, size: nil, mimetype: mimetype)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: File
|
|
||||||
|
|
||||||
func testFileContentType() {
|
|
||||||
let mimetype = "text"
|
|
||||||
let imageContent = FileMessageContent(body: "amazing.txt",
|
|
||||||
source: mediaSourceFromUrl(url: "mxc://doesnt/matter"),
|
|
||||||
info: makeFileInfo(mimetype: mimetype))
|
|
||||||
let messageItem = MockEventTimelineItem.message(from: imageContent)
|
|
||||||
XCTAssertEqual(messageItem.contentType, .plainText)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testFileContentTypeWithoutMimetype() {
|
|
||||||
let imageContent = FileMessageContent(body: "amazing.rtf",
|
|
||||||
source: mediaSourceFromUrl(url: "mxc://doesnt/matter"),
|
|
||||||
info: makeFileInfo(mimetype: nil))
|
|
||||||
let messageItem = MockEventTimelineItem.message(from: imageContent)
|
|
||||||
XCTAssertEqual(messageItem.contentType, .rtf)
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeFileInfo(mimetype: String?) -> FileInfo {
|
|
||||||
FileInfo(mimetype: mimetype, size: nil, thumbnailInfo: nil, thumbnailSource: nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Mocks
|
|
||||||
|
|
||||||
private struct MockEventTimelineItem: EventTimelineItemProtocol {
|
|
||||||
static func message<Content: MessageContentProtocol>(from content: Content) -> MessageTimelineItem<Content> {
|
|
||||||
let item = MockEventTimelineItem(underlyingContent: content)
|
|
||||||
return MessageTimelineItem(item: item, content: content)
|
|
||||||
}
|
|
||||||
|
|
||||||
let underlyingContent: MessageContentProtocol
|
|
||||||
|
|
||||||
// swiftlint:disable:next force_cast
|
|
||||||
func content() -> MatrixRustSDK.TimelineItemContent { underlyingContent as! TimelineItemContent }
|
|
||||||
|
|
||||||
func eventId() -> String? { UUID().uuidString }
|
|
||||||
|
|
||||||
func debugInfo() -> MatrixRustSDK.EventTimelineItemDebugInfo { .init(model: "MockEvent", originalJson: nil, latestEditJson: nil) }
|
|
||||||
|
|
||||||
func isEditable() -> Bool { false }
|
|
||||||
|
|
||||||
func isLocal() -> Bool { false }
|
|
||||||
|
|
||||||
func isOwn() -> Bool { false }
|
|
||||||
|
|
||||||
func isRemote() -> Bool { true }
|
|
||||||
|
|
||||||
func localSendState() -> MatrixRustSDK.EventSendState? { nil }
|
|
||||||
|
|
||||||
func raw() -> String? { nil }
|
|
||||||
|
|
||||||
func reactions() -> [MatrixRustSDK.Reaction] { [] }
|
|
||||||
|
|
||||||
func sender() -> String { "@user:server.com" }
|
|
||||||
|
|
||||||
func senderProfile() -> MatrixRustSDK.ProfileDetails { .unavailable }
|
|
||||||
|
|
||||||
func timestamp() -> UInt64 { 0 }
|
|
||||||
|
|
||||||
func uniqueIdentifier() -> String { eventId() ?? "" }
|
|
||||||
}
|
|
||||||
@@ -155,11 +155,11 @@ class RoomScreenViewModelTests: XCTestCase {
|
|||||||
private extension TextRoomTimelineItem {
|
private extension TextRoomTimelineItem {
|
||||||
init(text: String, sender: String, addReactions: Bool = false) {
|
init(text: String, sender: String, addReactions: Bool = false) {
|
||||||
self.init(id: UUID().uuidString,
|
self.init(id: UUID().uuidString,
|
||||||
body: text,
|
|
||||||
timestamp: "10:47 am",
|
timestamp: "10:47 am",
|
||||||
isOutgoing: sender == "bob",
|
isOutgoing: sender == "bob",
|
||||||
isEditable: sender == "bob",
|
isEditable: sender == "bob",
|
||||||
sender: .init(id: "@\(sender):server.com", displayName: sender),
|
sender: .init(id: "@\(sender):server.com", displayName: sender),
|
||||||
|
content: .init(body: text),
|
||||||
properties: RoomTimelineItemProperties(reactions: addReactions ? [
|
properties: RoomTimelineItemProperties(reactions: addReactions ? [
|
||||||
AggregatedReaction(key: "🦄", count: 1, isHighlighted: false)
|
AggregatedReaction(key: "🦄", count: 1, isHighlighted: false)
|
||||||
] : []))
|
] : []))
|
||||||
|
|||||||
Reference in New Issue
Block a user