New attachment download UI.

This commit is contained in:
Nicholas
2023-10-05 19:07:37 -04:00
committed by Nicholas Tinsley
parent 1f41b9e481
commit 82956c4149
31 changed files with 1487 additions and 590 deletions

View File

@@ -1,7 +1,6 @@
/*
* Copyright (C) 2014-2016 Open Whisper Systems
*
* Licensed according to the LICENSE file in this repository.
* Copyright 2023 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.signalservice.api.messages;
@@ -172,9 +171,11 @@ public abstract class SignalServiceAttachment {
/**
* Called on a progress change event.
*
* @param total The total amount to transmit/receive in bytes.
* @param total The total amount to transmit/receive in bytes.
* @param progress The amount that has been transmitted/received in bytes thus far
*/
public void onAttachmentProgress(long total, long progress);
void onAttachmentProgress(long total, long progress);
boolean shouldCancel();
}
}

View File

@@ -1517,6 +1517,9 @@ public class PushServiceSocket {
if (listener != null) {
listener.onAttachmentProgress(body.contentLength() + offset, totalRead);
if (listener.shouldCancel()) {
call.cancel();
}
}
}
} else if (response.code() == 416) {

View File

@@ -1,7 +1,13 @@
/*
* Copyright 2023 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.signalservice.internal.push.http;
import org.junit.Test;
import org.whispersystems.signalservice.api.crypto.AttachmentCipherStreamUtil;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.internal.crypto.AttachmentDigest;
import org.whispersystems.signalservice.internal.util.Util;
@@ -12,12 +18,11 @@ import okio.Buffer;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
public class DigestingRequestBodyTest {
private static int CONTENT_LENGTH = 70000;
private static int TOTAL_LENGTH = (int) AttachmentCipherStreamUtil.getCiphertextLength(CONTENT_LENGTH);
private static final int CONTENT_LENGTH = 70000;
private static final int TOTAL_LENGTH = (int) AttachmentCipherStreamUtil.getCiphertextLength(CONTENT_LENGTH);
private final byte[] attachmentKey = Util.getSecretBytes(64);
private final byte[] attachmentIV = Util.getSecretBytes(16);
@@ -78,6 +83,15 @@ public class DigestingRequestBodyTest {
}
private DigestingRequestBody getBody(long contentStart) {
return new DigestingRequestBody(new ByteArrayInputStream(input), outputStreamFactory, "application/octet", CONTENT_LENGTH, (a, b) -> {}, () -> false, contentStart);
return new DigestingRequestBody(new ByteArrayInputStream(input), outputStreamFactory, "application/octet", CONTENT_LENGTH, new SignalServiceAttachment.ProgressListener() {
@Override
public void onAttachmentProgress(long total, long progress) {
// no-op
}
@Override public boolean shouldCancel() {
return false;
}
}, () -> false, contentStart);
}
}