import Foundation // MARK: - Mood enum Mood: String, Codable, CaseIterable { case still = "still" case unruhig = "unruhig" case melancholisch = "melancholisch" case aufgedreht = "aufgedreht" // color, label, emoji → Colors.swift extension } // MARK: - Post struct Post: Identifiable, Codable { let id: String let author: User let content: String let mood: Mood? let createdAt: Date var resonanceCount: Int // "Hat mich getroffen" var hasResonated: Bool // Current user's reaction var commentCount: Int let isAnonymous: Bool let nightOf: Date var isExpired: Bool { Date().timeIntervalSince(createdAt) > 14 * 3_600 } // Is this post in the "Gerade Jetzt" window (< 10 min old) var isRightNow: Bool { Date().timeIntervalSince(createdAt) < 10 * 60 } var formattedTime: String { let f = DateFormatter() f.dateFormat = "HH:mm" return f.string(from: createdAt) } var timeAgo: String { let diff = Date().timeIntervalSince(createdAt) if diff < 60 { return "gerade eben" } if diff < 3_600 { return "\(Int(diff / 60))m" } return "\(Int(diff / 3_600))h" } static let previews: [Post] = [ Post( id: "1", author: .preview, content: "warum denk ich um 3 uhr morgens noch an das was ich 2019 gesagt hab", mood: .melancholisch, createdAt: Date().addingTimeInterval(-180), resonanceCount: 12, hasResonated: false, commentCount: 3, isAnonymous: false, nightOf: Date() ), Post( id: "2", author: User( id: "2", username: "insomniac_", displayName: "can't sleep", bio: nil, avatarURL: nil, followerCount: 88, followingCount: 44, postCount: 12, isFollowing: true ), content: "das licht vom handy macht alles schlimmer aber ich leg es trotzdem nicht weg", mood: .unruhig, createdAt: Date().addingTimeInterval(-900), resonanceCount: 8, hasResonated: true, commentCount: 1, isAnonymous: false, nightOf: Date() ), Post( id: "3", author: .preview, content: "ich warte irgendwie immer noch auf eine nachricht von dir obwohl ich weiß dass sie nicht kommt", mood: .melancholisch, createdAt: Date().addingTimeInterval(-300), resonanceCount: 31, hasResonated: true, commentCount: 7, isAnonymous: true, nightOf: Date() ), Post( id: "4", author: User( id: "4", username: "felix.nacht", displayName: "Felix", bio: nil, avatarURL: nil, followerCount: 33, followingCount: 20, postCount: 8, isFollowing: false ), content: "hab gerade realisiert dass ich seit 4 stunden auf tiktok bin und morgen um 7 aufstehen muss", mood: .aufgedreht, createdAt: Date().addingTimeInterval(-60), resonanceCount: 5, hasResonated: false, commentCount: 0, isAnonymous: false, nightOf: Date() ) ] }