Add rich link previews for shared URLs

- Capture both URL and title when sharing links
- Create LinkPreviewView component with clickable cards
- Support markdown-style links [title](url)
- Auto-detect plain URLs in messages
- Add link metadata fetching on iOS
- Display clean preview cards with title, URL, and description
This commit is contained in:
jack
2025-07-08 04:32:57 +02:00
parent 244af2197c
commit b8d930614e
4 changed files with 225 additions and 16 deletions
+15 -2
View File
@@ -92,8 +92,21 @@ struct BitchatApp: App {
// Send the shared content after a short delay
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
let prefix = contentType == "url" ? "Shared link: " : ""
self.chatViewModel.sendMessage(prefix + sharedContent)
if contentType == "url" {
// Try to parse as JSON first
if let data = sharedContent.data(using: .utf8),
let urlData = try? JSONSerialization.jsonObject(with: data) as? [String: String],
let url = urlData["url"],
let title = urlData["title"] {
// Send formatted link with title and URL
self.chatViewModel.sendMessage("[\(title)](\(url))")
} else {
// Fallback to simple URL
self.chatViewModel.sendMessage("Shared link: \(sharedContent)")
}
} else {
self.chatViewModel.sendMessage(sharedContent)
}
}
}
}