aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp-ft
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-11 14:51:39 +0300
committerGravatar Vitaly Takmazov2016-11-11 14:51:39 +0300
commitfcbf13dae35f024ceace25bcbf81a3cd05d6243a (patch)
tree85054658157f267073120b668fd4337259d47fae /juick-xmpp-ft
parent49d632e5e234cf9dbc057d20f5e3eabc34b48969 (diff)
xmpp-ft: using juick:// URI scheme for attachments
Diffstat (limited to 'juick-xmpp-ft')
-rw-r--r--juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java14
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);
}
}