diff --git a/app/src/main/java/com/swoosh/microblog/ui/feed/FeedViewModel.kt b/app/src/main/java/com/swoosh/microblog/ui/feed/FeedViewModel.kt index 4565db1..b8695ec 100644 --- a/app/src/main/java/com/swoosh/microblog/ui/feed/FeedViewModel.kt +++ b/app/src/main/java/com/swoosh/microblog/ui/feed/FeedViewModel.kt @@ -589,9 +589,11 @@ class FeedViewModel(application: Application) : AndroidViewModel(application) { } } + private val imgSrcRegex = Regex("""]+src\s*=\s*["']([^"']+)["']""", RegexOption.IGNORE_CASE) + private fun GhostPost.toFeedPost(): FeedPost { val mobiledocCards = parseMobiledocCards(mobiledoc) - // Use feature_image as primary, then add mobiledoc images (avoiding duplicates) + // Use feature_image as primary, then add mobiledoc images, then HTML images (avoiding duplicates) val allImages = mutableListOf() if (feature_image != null) { allImages.add(feature_image) @@ -601,6 +603,15 @@ class FeedViewModel(application: Application) : AndroidViewModel(application) { allImages.add(url) } } + // Fallback: extract images from HTML content + if (allImages.isEmpty() && html != null) { + imgSrcRegex.findAll(html).forEach { match -> + val url = match.groupValues[1] + if (url !in allImages) { + allImages.add(url) + } + } + } val isEmailOnly = status == "sent" || email_only == true return FeedPost( ghostId = id,