62 lines
1.7 KiB
Swift
62 lines
1.7 KiB
Swift
|
|
//
|
||
|
|
// TranscriptDisplayItems.swift
|
||
|
|
// kordophone2
|
||
|
|
//
|
||
|
|
// Created by James Magahern on 8/24/25.
|
||
|
|
//
|
||
|
|
|
||
|
|
import Foundation
|
||
|
|
import SwiftUI
|
||
|
|
|
||
|
|
extension TranscriptView.ViewModel
|
||
|
|
{
|
||
|
|
internal func rebuildDisplayItems(animated: Bool = false) {
|
||
|
|
var displayItems: [DisplayItem] = []
|
||
|
|
var lastDate: Date = .distantPast
|
||
|
|
|
||
|
|
let client = XPCClient()
|
||
|
|
let dateAnnotationTimeInterval: TimeInterval = 60 * 60 * 30 // 30m
|
||
|
|
for message in messages {
|
||
|
|
if message.date.timeIntervalSince(lastDate) > dateAnnotationTimeInterval {
|
||
|
|
lastDate = message.date
|
||
|
|
displayItems.append(.date(message.date))
|
||
|
|
}
|
||
|
|
|
||
|
|
for attachment in message.attachments {
|
||
|
|
displayItems.append(.attachment(attachment))
|
||
|
|
|
||
|
|
if !attachment.isPreviewDownloaded {
|
||
|
|
Task.detached {
|
||
|
|
try await client.downloadAttachment(attachmentId: attachment.id, preview: true)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
displayItems.append(.message(message))
|
||
|
|
}
|
||
|
|
|
||
|
|
let animation: Animation? = animated ? .default : nil
|
||
|
|
withAnimation(animation) {
|
||
|
|
self.displayItems = displayItems
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
enum DisplayItem: Identifiable
|
||
|
|
{
|
||
|
|
case message(Display.Message)
|
||
|
|
case attachment(Display.ImageAttachment)
|
||
|
|
case date(Date)
|
||
|
|
|
||
|
|
var id: String {
|
||
|
|
switch self {
|
||
|
|
case .message(let message):
|
||
|
|
message.id
|
||
|
|
case .attachment(let attachment):
|
||
|
|
attachment.id
|
||
|
|
case .date(let date):
|
||
|
|
date.description
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|