diff --git a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java index cbc42c06f2..1e9324a970 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java @@ -64,6 +64,7 @@ import org.whispersystems.signalservice.api.util.OptionalUtil; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutionException; @@ -190,6 +191,17 @@ public class LinkPreviewRepository { return; } + if (MediaUtil.isImageType(response.header("Content-Type"))) { + // We've been linked directly to an image. + okhttp3.HttpUrl imageUrl = response.request().url(); + // The best we can do for a title is the filename in the URL itself, + // but that's no worse than the body of the message. + List requestedUrlPathSegments = imageUrl.pathSegments(); + String filename = requestedUrlPathSegments.get(requestedUrlPathSegments.size() - 1); + callback.accept(new Metadata(Optional.of(filename), Optional.empty(), 0, Optional.of(imageUrl.toString()))); + return; + } + String body; try { body = OkHttpUtil.readAsString(response.body(), FAILSAFE_MAX_TEXT_SIZE);