mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Bump the RustSDK to v1.0.67 (#3512)
* Bump the RustSDK to v1.0.67 * PR comments --------- Co-authored-by: Doug <douglase@element.io>
This commit is contained in:
@@ -9,42 +9,46 @@ import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
struct RoomMessageEventStringBuilder {
|
||||
enum Prefix {
|
||||
case senderName
|
||||
case messageType
|
||||
case none
|
||||
enum Destination {
|
||||
/// Strings show on the room list as the last message
|
||||
/// The sender will be prefixed in bold
|
||||
case roomList
|
||||
/// Events pinned to the banner on the top of the timeline
|
||||
/// The message type will be prefixed in bold
|
||||
case pinnedEvent
|
||||
/// Shown in push notifications
|
||||
/// No prefix
|
||||
case notification
|
||||
}
|
||||
|
||||
let attributedStringBuilder: AttributedStringBuilderProtocol
|
||||
let prefix: Prefix
|
||||
let destination: Destination
|
||||
|
||||
func buildAttributedString(for messageType: MessageType, senderDisplayName: String) -> AttributedString {
|
||||
let message: AttributedString
|
||||
switch messageType {
|
||||
// Message types that don't need a prefix.
|
||||
case .emote(content: let content):
|
||||
if let attributedMessage = attributedMessageFrom(formattedBody: content.formatted) {
|
||||
return AttributedString(L10n.commonEmote(senderDisplayName, String(attributedMessage.characters)))
|
||||
} else {
|
||||
return AttributedString(L10n.commonEmote(senderDisplayName, content.body))
|
||||
}
|
||||
// Message types that should be prefixed with the sender's name.
|
||||
case .audio(content: let content):
|
||||
let isVoiceMessage = content.voice != nil
|
||||
var content = AttributedString(isVoiceMessage ? L10n.commonVoiceMessage : L10n.commonAudio)
|
||||
if prefix == .messageType {
|
||||
if destination == .pinnedEvent {
|
||||
content.bold()
|
||||
}
|
||||
message = content
|
||||
case .image(let content):
|
||||
message = prefix == .messageType ? prefix(AttributedString(content.body), with: L10n.commonImage) : AttributedString("\(L10n.commonImage) - \(content.body)")
|
||||
message = buildMessage(for: destination, caption: content.caption, type: L10n.commonImage)
|
||||
case .video(let content):
|
||||
message = prefix == .messageType ? prefix(AttributedString(content.body), with: L10n.commonVideo) : AttributedString("\(L10n.commonVideo) - \(content.body)")
|
||||
message = buildMessage(for: destination, caption: content.caption, type: L10n.commonVideo)
|
||||
case .file(let content):
|
||||
message = prefix == .messageType ? prefix(AttributedString(content.body), with: L10n.commonFile) : AttributedString("\(L10n.commonFile) - \(content.body)")
|
||||
message = buildMessage(for: destination, caption: content.caption, type: L10n.commonFile)
|
||||
case .location:
|
||||
var content = AttributedString(L10n.commonSharedLocation)
|
||||
if prefix == .messageType {
|
||||
if destination == .pinnedEvent {
|
||||
content.bold()
|
||||
}
|
||||
message = content
|
||||
@@ -64,13 +68,25 @@ struct RoomMessageEventStringBuilder {
|
||||
message = AttributedString(body)
|
||||
}
|
||||
|
||||
if prefix == .senderName {
|
||||
if destination == .roomList {
|
||||
return prefix(message, with: senderDisplayName)
|
||||
} else {
|
||||
return message
|
||||
}
|
||||
}
|
||||
|
||||
private func buildMessage(for destination: Destination, caption: String?, type: String) -> AttributedString {
|
||||
guard let caption else {
|
||||
return AttributedString(type)
|
||||
}
|
||||
|
||||
if destination == .pinnedEvent {
|
||||
return prefix(AttributedString(caption), with: type)
|
||||
} else {
|
||||
return AttributedString("\(type) - \(caption)")
|
||||
}
|
||||
}
|
||||
|
||||
private func prefix(_ eventSummary: AttributedString, with textToBold: String) -> AttributedString {
|
||||
let attributedEventSummary = AttributedString(eventSummary.string.trimmingCharacters(in: .whitespacesAndNewlines))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user