diff options
author | 2016-11-11 14:51:39 +0300 | |
---|---|---|
committer | 2016-11-11 14:51:39 +0300 | |
commit | fcbf13dae35f024ceace25bcbf81a3cd05d6243a (patch) | |
tree | 85054658157f267073120b668fd4337259d47fae /juick-xmpp-ft/src | |
parent | 49d632e5e234cf9dbc057d20f5e3eabc34b48969 (diff) |
xmpp-ft: using juick:// URI scheme for attachments
Diffstat (limited to 'juick-xmpp-ft/src')
-rw-r--r-- | juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java b/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java index 37ca7ec6..6726a156 100644 --- a/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java +++ b/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java @@ -16,6 +16,8 @@ import rocks.xmpp.extensions.oob.model.x.OobX; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; @@ -39,7 +41,8 @@ public class XMPPFTServer { fileTransferManager.addFileTransferOfferListener(e -> { try { List<String> allowedTypes = new ArrayList<String>() {{ add("png"); add("jpg"); }}; - if (allowedTypes.contains(FilenameUtils.getExtension(e.getName()))) { + String attachmentExtension = FilenameUtils.getExtension(e.getName()); + if (allowedTypes.contains(attachmentExtension)) { Path filePath = Paths.get(tmpDir, e.getName()); FileTransfer ft = e.accept(filePath).get(); ft.addFileTransferStatusListener(st -> { @@ -52,10 +55,13 @@ public class XMPPFTServer { msg.setTo(Jid.of(juickJid)); msg.setBody(e.getDescription()); try { - String attachmentUrl = DigestUtils.md5Hex(String.format("%s-%s", e.getInitiator().toString(), e.getSessionId()).getBytes()); - msg.addExtension(new OobX(new URL(attachmentUrl), "!!!!Juick!!")); + String attachmentUrl = String.format("juick://%s.%s", + DigestUtils.md5Hex(String.format("%s-%s", + e.getInitiator().toString(), e.getSessionId()).getBytes()), + attachmentExtension); + msg.addExtension(new OobX(new URI(attachmentUrl).toURL(), "!!!!Juick!!")); component.sendMessage(msg); - } catch (MalformedURLException e1) { + } catch (MalformedURLException | URISyntaxException e1) { logger.warn("attachment error", e1); } } |