import CoreLocation import Foundation import SwiftUI extension String { var firstLetter: String { String(prefix(1)).uppercased() } var makeReply: String { let allLines = components(separatedBy: .newlines) let nonBlankLines = allLines.filter { !$0.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty } var result = nonBlankLines.joined(separator: "\n") result = "> \(result)" return result } var isLocation: Bool { hasPrefix("geo:") } var getLatLon: CLLocationCoordinate2D { let geo = components(separatedBy: ":")[1] let parts = geo.components(separatedBy: ",") let lat = Double(parts[0]) ?? 0.0 let lon = Double(parts[1]) ?? 0.0 return CLLocationCoordinate2D(latitude: lat, longitude: lon) } var isContact: Bool { hasPrefix("contact:") } var getContactJid: String { components(separatedBy: ":")[1] } } extension String { // var attachmentType: AttachmentType { // let ext = (self as NSString).pathExtension.lowercased() // if ext.contains("jpeg") || ext.contains("jpg") || ext.contains("png") || ext.contains("gif") { // return .image // } else if ext.contains("mov") || ext.contains("mp4") || ext.contains("avi") { // return .video // } else if ext.contains("mp3") || ext.contains("wav") || ext.contains("m4a") { // return .audio // } else { // return .file // } // } } extension String { var firstLetterColor: Color { let firstLetter = self.firstLetter switch firstLetter { case "A", "M", "Y": return Color.Rainbow.tortoiseLight500 case "B", "N", "Z": return Color.Rainbow.orangeLight500 case "C", "O": return Color.Rainbow.yellowLight500 case "D", "P": return Color.Rainbow.greenLight500 case "E", "Q": return Color.Rainbow.blueLight500 case "F", "R": return Color.Rainbow.magentaLight500 case "G", "S": return Color.Rainbow.tortoiseDark500 case "H", "T": return Color.Rainbow.orangeDark500 case "I", "U": return Color.Rainbow.yellowDark500 case "J", "V": return Color.Rainbow.greenDark500 case "K", "W": return Color.Rainbow.blueDark500 case "L", "X": return Color.Rainbow.magentaDark500 default: return Color.Rainbow.tortoiseLight500 } } }