mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Add link preview support for raw images.
This commit is contained in:
committed by
Greyson Parrelli
parent
3b0878f493
commit
1ce6aacec6
@@ -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<String> 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);
|
||||
|
||||
Reference in New Issue
Block a user