mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Add federation support for attachment retrieval.
This commit is contained in:
parent
246cd10454
commit
51b9affe90
@ -172,9 +172,14 @@ public class PushServiceSocket {
|
|||||||
return new Gson().fromJson(response.second, AttachmentKey.class).getId();
|
return new Gson().fromJson(response.second, AttachmentKey.class).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public File retrieveAttachment(long attachmentId) throws IOException {
|
public File retrieveAttachment(String relay, long attachmentId) throws IOException {
|
||||||
Pair<String, String> response = makeRequestForResponseHeader(String.format(ATTACHMENT_PATH, String.valueOf(attachmentId)),
|
String path = String.format(ATTACHMENT_PATH, String.valueOf(attachmentId));
|
||||||
"GET", null, "Content-Location");
|
|
||||||
|
if (relay != null) {
|
||||||
|
path = path + "?relay=" + relay;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pair<String, String> response = makeRequestForResponseHeader(path, "GET", null, "Content-Location");
|
||||||
|
|
||||||
Log.w("PushServiceSocket", "Attachment: " + attachmentId + " is at: " + response.first);
|
Log.w("PushServiceSocket", "Attachment: " + attachmentId + " is at: " + response.first);
|
||||||
|
|
||||||
|
@ -57,6 +57,11 @@ public class IncomingMediaMessage {
|
|||||||
media.setContentType(Util.toIsoBytes(attachment.getContentType()));
|
media.setContentType(Util.toIsoBytes(attachment.getContentType()));
|
||||||
media.setContentLocation(Util.toIsoBytes(String.valueOf(attachment.getId())));
|
media.setContentLocation(Util.toIsoBytes(String.valueOf(attachment.getId())));
|
||||||
media.setContentDisposition(Util.toIsoBytes(Base64.encodeBytes(encryptedKey)));
|
media.setContentDisposition(Util.toIsoBytes(Base64.encodeBytes(encryptedKey)));
|
||||||
|
|
||||||
|
if (message.getRelay() != null) {
|
||||||
|
media.setName(Util.toIsoBytes(message.getRelay()));
|
||||||
|
}
|
||||||
|
|
||||||
media.setPendingPush(true);
|
media.setPendingPush(true);
|
||||||
|
|
||||||
body.addPart(media);
|
body.addPart(media);
|
||||||
|
@ -69,8 +69,13 @@ public class PushDownloader {
|
|||||||
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
||||||
long contentLocation = Long.parseLong(Util.toIsoString(part.getContentLocation()));
|
long contentLocation = Long.parseLong(Util.toIsoString(part.getContentLocation()));
|
||||||
byte[] key = masterCipher.decryptBytes(Base64.decode(Util.toIsoString(part.getContentDisposition())));
|
byte[] key = masterCipher.decryptBytes(Base64.decode(Util.toIsoString(part.getContentDisposition())));
|
||||||
|
String relay = null;
|
||||||
|
|
||||||
attachmentFile = downloadAttachment(contentLocation);
|
if (part.getName() != null) {
|
||||||
|
relay = Util.toIsoString(part.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
attachmentFile = downloadAttachment(relay, contentLocation);
|
||||||
InputStream attachmentInput = new AttachmentCipherInputStream(attachmentFile, key);
|
InputStream attachmentInput = new AttachmentCipherInputStream(attachmentFile, key);
|
||||||
|
|
||||||
database.updateDownloadedPart(messageId, partId, part, attachmentInput);
|
database.updateDownloadedPart(messageId, partId, part, attachmentInput);
|
||||||
@ -97,9 +102,9 @@ public class PushDownloader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File downloadAttachment(long contentLocation) throws IOException {
|
private File downloadAttachment(String relay, long contentLocation) throws IOException {
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||||
return socket.retrieveAttachment(contentLocation);
|
return socket.retrieveAttachment(relay, contentLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user