From 9852c44e52832a8fb8223214e5bbf6866312c60d Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 13 Mar 2018 12:15:17 +0300 Subject: server: attachments in XMPP --- .../main/java/com/juick/server/XMPPConnection.java | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'juick-server') diff --git a/juick-server/src/main/java/com/juick/server/XMPPConnection.java b/juick-server/src/main/java/com/juick/server/XMPPConnection.java index ae7ba252..edc547eb 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java @@ -24,6 +24,7 @@ import com.juick.server.helpers.UserInfo; import com.juick.service.MessagesService; import com.juick.service.SubscriptionService; import com.juick.service.UserService; +import com.juick.util.MessageUtils; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; @@ -292,9 +293,9 @@ public class XMPPConnection implements AutoCloseable { } com.juick.Message fullMsg = messagesService.getMessage(jmsg.getMid()); String txt = "@" + jmsg.getUser().getName() + ":" + fullMsg.getTagsString() + "\n"; - Attachment attachment = fullMsg.getAttachment(); - if (attachment != null) { - txt += attachment.getMedium().getUrl() + "\n"; + String attachmentUrl = MessageUtils.attachmentUrl(fullMsg); + if (StringUtils.isNotEmpty(attachmentUrl)) { + txt += attachmentUrl + "\n"; } txt += StringUtils.defaultString(jmsg.getText()) + "\n\n"; txt += "#" + jmsg.getMid() + " http://juick.com/" + jmsg.getMid(); @@ -308,9 +309,9 @@ public class XMPPConnection implements AutoCloseable { msg.setThread("juick-" + jmsg.getMid()); msg.addExtension(jmsg); msg.addExtension(nick); - if (attachment != null) { + if (StringUtils.isNotEmpty(attachmentUrl)) { try { - OobX oob = new OobX(new URI(attachment.getMedium().getUrl())); + OobX oob = new OobX(new URI(attachmentUrl)); msg.addExtension(oob); } catch (URISyntaxException e) { logger.warn("uri exception", e); @@ -335,9 +336,9 @@ public class XMPPConnection implements AutoCloseable { replyQuote = fullReply.getReplyQuote(); String txt = "Reply by @" + jmsg.getUser().getName() + ":\n" + replyQuote + "\n@" + replyTo + " "; - Attachment attachment = jmsg.getAttachment(); - if (attachment != null) { - txt += attachment.getMedium().getUrl() + "\n"; + String attachmentUrl = MessageUtils.attachmentUrl(fullReply); + if (StringUtils.isNotEmpty(attachmentUrl)) { + txt += attachmentUrl + "\n"; } txt += StringUtils.defaultString(jmsg.getText()) + "\n\n" + "#" + jmsg.getMid() + "/" + jmsg.getRid() + " http://juick.com/" + jmsg.getMid() + "#" + jmsg.getRid(); @@ -362,9 +363,9 @@ public class XMPPConnection implements AutoCloseable { String txt = "Recommended by @" + recomm.getUser().getName() + ":\n"; txt += "@" + jmsg.getUser().getName() + ":" + jmsg.getTagsString() + "\n"; - Attachment attachment = jmsg.getAttachment(); - if (attachment != null) { - txt += attachment.getMedium().getUrl() + "\n"; + String attachmentUrl = MessageUtils.attachmentUrl(jmsg); + if (StringUtils.isNotEmpty(attachmentUrl)) { + txt += attachmentUrl + "\n"; } txt += StringUtils.defaultString(jmsg.getText()) + "\n\n"; txt += "#" + jmsg.getMid(); @@ -386,9 +387,9 @@ public class XMPPConnection implements AutoCloseable { msg.setThread("juick-" + jmsg.getMid()); msg.addExtension(jmsg); msg.addExtension(nick); - if (attachment != null) { + if (StringUtils.isNotEmpty(attachmentUrl)) { try { - OobX oob = new OobX(new URI(attachment.getMedium().getUrl())); + OobX oob = new OobX(new URI(attachmentUrl)); msg.addExtension(oob); } catch (URISyntaxException e) { logger.warn("uri exception", e); -- cgit v1.2.3