diff --git a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift index 138615747..fd37145de 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift @@ -420,7 +420,7 @@ struct ChatBubbleView: View { .frame(maxWidth: .infinity, alignment: .leading) .lineLimit(1) - Text("2,2 Mo") + Text(eventLogMessage.message.attachments.first!.size.formatBytes()) .default_text_style_300(styleSize: 16) .frame(maxWidth: .infinity, alignment: .leading) .lineLimit(1) diff --git a/Linphone/UI/Main/Conversations/Model/Attachment.swift b/Linphone/UI/Main/Conversations/Model/Attachment.swift index 8d2d83c5a..58b0536bb 100644 --- a/Linphone/UI/Main/Conversations/Model/Attachment.swift +++ b/Linphone/UI/Main/Conversations/Model/Attachment.swift @@ -84,17 +84,19 @@ public struct Attachment: Codable, Identifiable, Hashable { public let full: URL public let type: AttachmentType public let duration: Int + public let size: Int - public init(id: String, name: String, thumbnail: URL, full: URL, type: AttachmentType, duration: Int = 0) { + public init(id: String, name: String, thumbnail: URL, full: URL, type: AttachmentType, duration: Int = 0, size: Int = 0) { self.id = id self.name = name self.thumbnail = thumbnail self.full = full self.type = type self.duration = duration + self.size = size } - public init(id: String, name: String, url: URL, type: AttachmentType, duration: Int = 0) { - self.init(id: id, name: name, thumbnail: url, full: url, type: type, duration: duration) + public init(id: String, name: String, url: URL, type: AttachmentType, duration: Int = 0, size: Int = 0) { + self.init(id: id, name: name, thumbnail: url, full: url, type: type, duration: duration, size: size) } } diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift index 2073502ec..f4ea9e59a 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift @@ -312,7 +312,8 @@ class ConversationViewModel: ObservableObject { id: UUID().uuidString, name: content.name!, url: path!, - type: .fileTransfer + type: .fileTransfer, + size: content.fileSize ) attachmentNameList += ", \(content.name!)" attachmentList.append(attachment) @@ -342,7 +343,8 @@ class ConversationViewModel: ObservableObject { name: content.name!, url: path!, type: typeTmp, - duration: typeTmp == . voiceRecording ? content.fileDuration : 0 + duration: typeTmp == .voiceRecording ? content.fileDuration : 0, + size: content.fileSize ) attachmentNameList += ", \(content.name!)" attachmentList.append(attachment) @@ -358,7 +360,8 @@ class ConversationViewModel: ObservableObject { name: content.name!, thumbnail: pathThumbnail!, full: path!, - type: .video + type: .video, + size: content.fileSize ) attachmentNameList += ", \(content.name!)" attachmentList.append(attachment) @@ -528,7 +531,8 @@ class ConversationViewModel: ObservableObject { id: UUID().uuidString, name: content.name!, url: path!, - type: .fileTransfer + type: .fileTransfer, + size: content.fileSize ) attachmentNameList += ", \(content.name!)" attachmentList.append(attachment) @@ -558,7 +562,8 @@ class ConversationViewModel: ObservableObject { name: content.name!, url: path!, type: typeTmp, - duration: typeTmp == . voiceRecording ? content.fileDuration : 0 + duration: typeTmp == . voiceRecording ? content.fileDuration : 0, + size: content.fileSize ) attachmentNameList += ", \(content.name!)" attachmentList.append(attachment) @@ -574,7 +579,8 @@ class ConversationViewModel: ObservableObject { name: content.name!, thumbnail: pathThumbnail!, full: path!, - type: .video + type: .video, + size: content.fileSize ) attachmentNameList += ", \(content.name!)" attachmentList.append(attachment) @@ -741,7 +747,8 @@ class ConversationViewModel: ObservableObject { id: UUID().uuidString, name: content.name ?? "???", url: path!, - type: .fileTransfer + type: .fileTransfer, + size: content.fileSize ) attachmentNameList += ", \(content.name ?? "???")" attachmentList.append(attachment) @@ -771,7 +778,8 @@ class ConversationViewModel: ObservableObject { name: content.name!, url: path!, type: typeTmp, - duration: typeTmp == . voiceRecording ? content.fileDuration : 0 + duration: typeTmp == . voiceRecording ? content.fileDuration : 0, + size: content.fileSize ) attachmentNameList += ", \(content.name!)" attachmentList.append(attachment) @@ -787,7 +795,8 @@ class ConversationViewModel: ObservableObject { name: content.name!, thumbnail: pathThumbnail!, full: path!, - type: .video + type: .video, + size: content.fileSize ) attachmentNameList += ", \(content.name!)" attachmentList.append(attachment) @@ -1027,7 +1036,8 @@ class ConversationViewModel: ObservableObject { id: UUID().uuidString, name: content.name!, url: path!, - type: .fileTransfer + type: .fileTransfer, + size: content.fileSize ) attachmentNameList += ", \(content.name!)" attachmentList.append(attachment) @@ -1057,7 +1067,8 @@ class ConversationViewModel: ObservableObject { name: content.name!, url: path!, type: typeTmp, - duration: typeTmp == . voiceRecording ? content.fileDuration : 0 + duration: typeTmp == . voiceRecording ? content.fileDuration : 0, + size: content.fileSize ) attachmentNameList += ", \(content.name!)" attachmentList.append(attachment) @@ -1073,7 +1084,8 @@ class ConversationViewModel: ObservableObject { name: content.name!, thumbnail: pathThumbnail!, full: path!, - type: .video + type: .video, + size: content.fileSize ) attachmentNameList += ", \(content.name!)" attachmentList.append(attachment) diff --git a/Linphone/Utils/Extensions/IntExtension.swift b/Linphone/Utils/Extensions/IntExtension.swift index b4dce52f2..4067dcac5 100644 --- a/Linphone/Utils/Extensions/IntExtension.swift +++ b/Linphone/Utils/Extensions/IntExtension.swift @@ -34,6 +34,14 @@ extension Int { } return "\(duration)\(self.getMinute(minute: minute))\(self.getSecond(second: second))" } + + public func formatBytes() -> String { + let byteCountFormatter = ByteCountFormatter() + byteCountFormatter.allowedUnits = [.useKB, .useMB, .useGB] // Allows KB, MB and KB + byteCountFormatter.countStyle = .file // Use file size style + byteCountFormatter.isAdaptive = true // Adjusts automatically to appropriate unit + return byteCountFormatter.string(fromByteCount: Int64(self)) + } private func getHour(hour: Int) -> String { var duration = "\(hour):"