mirror of
				https://github.com/oxen-io/session-android.git
				synced 2025-11-04 00:55:14 +00:00 
			
		
		
		
	Add federation support for attachment retrieval.
This commit is contained in:
		@@ -172,9 +172,14 @@ public class PushServiceSocket {
 | 
			
		||||
    return new Gson().fromJson(response.second, AttachmentKey.class).getId();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public File retrieveAttachment(long attachmentId) throws IOException {
 | 
			
		||||
    Pair<String, String> response = makeRequestForResponseHeader(String.format(ATTACHMENT_PATH, String.valueOf(attachmentId)),
 | 
			
		||||
                                                                 "GET", null, "Content-Location");
 | 
			
		||||
  public File retrieveAttachment(String relay, long attachmentId) throws IOException {
 | 
			
		||||
    String path = String.format(ATTACHMENT_PATH, String.valueOf(attachmentId));
 | 
			
		||||
 | 
			
		||||
    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);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -57,6 +57,11 @@ public class IncomingMediaMessage {
 | 
			
		||||
        media.setContentType(Util.toIsoBytes(attachment.getContentType()));
 | 
			
		||||
        media.setContentLocation(Util.toIsoBytes(String.valueOf(attachment.getId())));
 | 
			
		||||
        media.setContentDisposition(Util.toIsoBytes(Base64.encodeBytes(encryptedKey)));
 | 
			
		||||
 | 
			
		||||
        if (message.getRelay() != null) {
 | 
			
		||||
          media.setName(Util.toIsoBytes(message.getRelay()));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        media.setPendingPush(true);
 | 
			
		||||
 | 
			
		||||
        body.addPart(media);
 | 
			
		||||
 
 | 
			
		||||
@@ -69,8 +69,13 @@ public class PushDownloader {
 | 
			
		||||
      MasterCipher masterCipher    = new MasterCipher(masterSecret);
 | 
			
		||||
      long         contentLocation = Long.parseLong(Util.toIsoString(part.getContentLocation()));
 | 
			
		||||
      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);
 | 
			
		||||
 | 
			
		||||
      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());
 | 
			
		||||
    return socket.retrieveAttachment(contentLocation);
 | 
			
		||||
    return socket.retrieveAttachment(relay, contentLocation);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user