Add recent documents to home on iOS

This commit is contained in:
Arkadiusz Fal
2022-11-18 23:39:52 +01:00
parent 8ec06b0d59
commit bc1571a746
8 changed files with 148 additions and 20 deletions

View File

@@ -54,6 +54,19 @@ final class DocumentsModel: ObservableObject {
return nil
}
func recentDocuments(_ limit: Int = 10) -> [URL] {
guard let documentsDirectory else { return [] }
return Array(
contents(of: documentsDirectory)
.sorted {
((try? $0.resourceValues(forKeys: [.creationDateKey]).creationDate) ?? Date()) >
((try? $1.resourceValues(forKeys: [.creationDateKey]).creationDate) ?? Date())
}
.prefix(limit)
)
}
func isDocument(_ video: Video) -> Bool {
guard video.isLocal, let url = video.localStream?.localURL, let url = replacePrivateVar(url) else { return false }
return isDocument(url)