From a5f045a3780ef8530afa7493cf090771b8fdcfe1 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 3 Apr 2018 17:55:46 +0300 Subject: refactoring: all messages are processed with XMPPConnection --- .../java/com/juick/www/controllers/NewMessage.java | 25 +++++++++------------- .../java/com/juick/www/controllers/Settings.java | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) (limited to 'juick-www/src/main/java/com/juick/www') diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java index ee4a6025..b93d6f57 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java @@ -132,9 +132,9 @@ public class NewMessage { throw new HttpForbiddenException(); } - String attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir); + URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir); - if (StringUtils.isBlank(attachmentFName) && img != null && img.length() > 10) { + if (StringUtils.isBlank(attachmentFName.toString()) && img != null && img.length() > 10) { try { URL imgUrl = new URL(img); attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir); @@ -144,7 +144,7 @@ public class NewMessage { } } - String attachmentType = StringUtils.isNotEmpty(attachmentFName) ? attachmentFName.substring(attachmentFName.length() - 3) : null; + String attachmentType = StringUtils.isNotEmpty(attachmentFName.toString()) ? attachmentFName.toString().substring(attachmentFName.toString().length() - 3) : null; int ridnew = messagesService.createReply(mid, rid, visitor.getUid(), body, attachmentType); subscriptionService.subscribeMessage(mid, visitor.getUid()); @@ -163,11 +163,11 @@ public class NewMessage { } xmsg.addExtension(new Nickname("@" + jmsg.getUser().getName())); - if (StringUtils.isNotEmpty(attachmentFName)) { + if (StringUtils.isNotEmpty(attachmentFName.toString())) { String fname = mid + "-" + ridnew + "." + attachmentType; String attachmentURL = "http://i.juick.com/photos-1024/" + fname; - ImageUtils.saveImageWithPreviews(attachmentFName, fname, tmpDir, imgDir); + ImageUtils.saveImageWithPreviews(attachmentFName.getHost(), fname, tmpDir, imgDir); body = attachmentURL + "\n" + body; try { @@ -246,9 +246,9 @@ public class NewMessage { } String body = StringUtils.isNotEmpty(bodyParam) ? bodyParam.replace("\r", StringUtils.EMPTY) : StringUtils.EMPTY; - String attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir); + URI attachmentFName = HttpUtils.receiveMultiPartFile(attach, tmpDir); - if (StringUtils.isBlank(attachmentFName) && StringUtils.isNotBlank(img)) { + if (StringUtils.isBlank(attachmentFName.toString()) && StringUtils.isNotBlank(img)) { try { URL imgUrl = new URL(img); attachmentFName = HttpUtils.downloadImage(imgUrl, tmpDir); @@ -262,15 +262,10 @@ public class NewMessage { msg.setFrom(Jid.of(String.valueOf(visitor.getUid()), "uid.juick.com", "perl")); msg.setTo(botJid); msg.setBody(body); - try { - if (StringUtils.isNotEmpty(attachmentFName)) { - String attachmentUrl = String.format("juick://%s", attachmentFName); - msg.addExtension(new OobX(new URI(attachmentUrl), "!!!!Juick!!")); - } - xmpp.sendMessage(msg); - } catch (URISyntaxException e1) { - logger.warn("attachment error", e1); + if (StringUtils.isNotEmpty(attachmentFName.toString())) { + msg.addExtension(new OobX(attachmentFName, "!!!!Juick!!")); } + xmpp.sendMessage(msg); if (StringUtils.isBlank(referer) || referer.substring(0, 21).equals("http://juick.com/post") || referer.substring(0, 22).equals("https://juick.com/post")) { return "redirect:/?show=my"; diff --git a/juick-www/src/main/java/com/juick/www/controllers/Settings.java b/juick-www/src/main/java/com/juick/www/controllers/Settings.java index ffc66841..15f18052 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/Settings.java +++ b/juick-www/src/main/java/com/juick/www/controllers/Settings.java @@ -158,7 +158,7 @@ public class Settings { info.setCountry(request.getParameter("country")); info.setUrl(request.getParameter("url")); info.setDescription(request.getParameter("descr")); - String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, tmpDir); + String avatarTmpPath = HttpUtils.receiveMultiPartFile(avatar, tmpDir).getHost(); if (StringUtils.isNotEmpty(avatarTmpPath)) { ImageUtils.saveAvatar(avatarTmpPath, visitor.getUid(), tmpDir, imgDir); } -- cgit v1.2.3