2024-07-11 13:59:24 +00:00
|
|
|
import CoreLocation
|
2024-06-19 15:15:27 +00:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
extension String {
|
|
|
|
var firstLetter: String {
|
|
|
|
String(prefix(1)).uppercased()
|
|
|
|
}
|
2024-06-27 11:39:41 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2024-07-11 13:59:24 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2024-07-16 18:14:59 +00:00
|
|
|
|
|
|
|
var isContact: Bool {
|
|
|
|
hasPrefix("contact:")
|
|
|
|
}
|
|
|
|
|
|
|
|
var getContactJid: String {
|
|
|
|
components(separatedBy: ":")[1]
|
|
|
|
}
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
2024-07-13 13:38:15 +00:00
|
|
|
|
|
|
|
extension String {
|
|
|
|
var attachmentType: MessageAttachmentType {
|
|
|
|
let ext = (self as NSString).pathExtension.lowercased()
|
|
|
|
|
|
|
|
switch ext {
|
|
|
|
case "mov", "mp4", "avi":
|
|
|
|
return .movie
|
|
|
|
|
|
|
|
case "jpg", "png", "gif":
|
|
|
|
return .image
|
|
|
|
|
|
|
|
case "mp3", "wav", "m4a":
|
|
|
|
return .audio
|
|
|
|
|
|
|
|
case "txt", "doc", "pdf":
|
|
|
|
return .file
|
|
|
|
|
|
|
|
default:
|
|
|
|
return .file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|