From 62960df0089be25bc58aadcb99fd0f8cbbb4cda2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 15 Aug 2017 17:12:17 +0300 Subject: xmpp: handle file transfer errors --- .../src/main/java/com/juick/components/XMPPConnection.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'juick-xmpp/src/main/java/com/juick') diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java b/juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java index 8317c600..ff879bee 100644 --- a/juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java +++ b/juick-xmpp/src/main/java/com/juick/components/XMPPConnection.java @@ -176,7 +176,7 @@ public class XMPPConnection implements AutoCloseable { FileTransfer ft = e.accept(filePath).get(); ft.addFileTransferStatusListener(st -> { logger.debug("{}: received {} of {}", e.getName(), st.getBytesTransferred(), e.getSize()); - if (ft.isDone()) { + if (st.getStatus().equals(FileTransfer.Status.COMPLETED)) { logger.info("transfer completed"); Message msg = new Message(); msg.setType(Message.Type.CHAT); @@ -190,6 +190,16 @@ public class XMPPConnection implements AutoCloseable { } catch (URISyntaxException e1) { logger.warn("attachment error", e1); } + } else if (st.getStatus().equals(FileTransfer.Status.FAILED)) { + logger.info("transfer failed", ft.getException()); + Message msg = new Message(); + msg.setType(Message.Type.CHAT); + msg.setFrom(xmpp.getJid()); + msg.setTo(e.getInitiator()); + msg.setBody("File transfer failed, please report to us"); + router.sendMessage(msg); + } else if (st.getStatus().equals(FileTransfer.Status.CANCELED)) { + logger.info("transfer cancelled"); } }); ft.transfer(); -- cgit v1.2.3