diff options
author | Vitaly Takmazov | 2018-03-13 12:15:17 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-03-13 12:15:17 +0300 |
commit | 9852c44e52832a8fb8223214e5bbf6866312c60d (patch) | |
tree | 8f16dbf154e345dd871633b7ecd01af9f0950bab /juick-server | |
parent | c9ff06c5edc4ba555e43a465c2f1454bf9d9f351 (diff) |
server: attachments in XMPP
Diffstat (limited to 'juick-server')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/XMPPConnection.java | 27 |
1 files changed, 14 insertions, 13 deletions
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); |