Ensure images sent to stories respect media quality settings.

Stories should always use "Standard" quality, not L3 (high quality). This change ensures that we:

1. Always send stories at the appropriate quality
2. Do not corrupt or overwrite pre-existing image attachments
3. Close several streams when done (thanks StrictMode!)
This commit is contained in:
Alex Hart
2022-07-13 12:48:17 -03:00
committed by Cody Henthorne
parent c4bef8099f
commit b18542a839
20 changed files with 384 additions and 79 deletions
@@ -10,13 +10,15 @@ package org.whispersystems.signalservice.api.messages;
import org.whispersystems.signalservice.internal.push.http.CancelationSignal;
import org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
/**
* Represents a local SignalServiceAttachment to be sent.
*/
public class SignalServiceAttachmentStream extends SignalServiceAttachment {
public class SignalServiceAttachmentStream extends SignalServiceAttachment implements Closeable {
private final InputStream inputStream;
private final long length;
@@ -151,4 +153,9 @@ public class SignalServiceAttachmentStream extends SignalServiceAttachment {
public Optional<ResumableUploadSpec> getResumableUploadSpec() {
return resumableUploadSpec;
}
@Override
public void close() throws IOException {
inputStream.close();
}
}
@@ -1450,17 +1450,11 @@ public class PushServiceSocket {
connections.add(call);
}
try {
Response response;
try {
response = call.execute();
} catch (IOException e) {
throw new PushNetworkException(e);
}
try (Response response = call.execute()) {
if (response.isSuccessful()) return file.getTransmittedDigest();
else throw new NonSuccessfulResponseCodeException(response.code(), "Response: " + response);
} catch (IOException e) {
throw new PushNetworkException(e);
} finally {
synchronized (connections) {
connections.remove(call);