diff options
author | 2018-03-30 14:18:56 +0300 | |
---|---|---|
committer | 2018-03-30 14:18:56 +0300 | |
commit | a746598faef08af794c66d65ba9324bee5043b73 (patch) | |
tree | eff6bd472547df069b3fcbd3da2e29f750d58626 /juick-server/src/main/java/com/juick/server/api/Post.java | |
parent | 42e2a727c2bc15ac15c9a3af66f126dbefe508a2 (diff) |
server: process everything in one place
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/api/Post.java')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/api/Post.java | 66 |
1 files changed, 8 insertions, 58 deletions
diff --git a/juick-server/src/main/java/com/juick/server/api/Post.java b/juick-server/src/main/java/com/juick/server/api/Post.java index 6bab5b41..3d9703fd 100644 --- a/juick-server/src/main/java/com/juick/server/api/Post.java +++ b/juick-server/src/main/java/com/juick/server/api/Post.java @@ -22,7 +22,9 @@ import com.juick.User; import com.juick.server.EmailManager; import com.juick.server.ServerManager; import com.juick.server.CommandsManager; +import com.juick.server.XMPPConnection; import com.juick.server.util.*; +import com.juick.server.xmpp.helpers.CommandResult; import com.juick.service.MessagesService; import com.juick.service.SubscriptionService; import com.juick.service.UserService; @@ -88,7 +90,7 @@ public class Post { public void doPostMessage( @RequestParam String body, @RequestParam(required = false) String img, - @RequestParam(required = false) MultipartFile attach) throws IOException { + @RequestParam(required = false) MultipartFile attach) throws Exception { User visitor = UserUtils.getCurrentUser(); if (visitor.isAnonymous()) @@ -124,7 +126,7 @@ public class Post { @RequestParam String body, @RequestParam(required = false) String img, @RequestParam(required = false) MultipartFile attach) - throws IOException { + throws Exception { User visitor = UserUtils.getCurrentUser(); int vuid = visitor.getUid(); if (vuid == 0) { @@ -167,46 +169,7 @@ public class Post { } } - String attachmentType = StringUtils.isNotEmpty(attachmentFName) ? attachmentFName.substring(attachmentFName.length() - 3) : null; - int ridnew = messagesService.createReply(mid, rid, vuid, body, attachmentType); - subscriptionService.subscribeMessage(mid, vuid); - - com.juick.Message jmsg = messagesService.getReply(mid, ridnew); - - Message xmsg = new Message(); - xmsg.setFrom(Jid.of("juick@juick.com")); - xmsg.setType(Message.Type.CHAT); - xmsg.setThread("juick-" + mid); - xmsg.addExtension(jmsg); - - String quote = reply != null ? StringUtils.defaultString(reply.getText()) : StringUtils.defaultString(msg.getText()); - if (quote.length() >= 50) { - quote = quote.substring(0, 47) + "..."; - } - - xmsg.addExtension(new Nickname("@" + jmsg.getUser().getName())); - - if (StringUtils.isNotEmpty(attachmentFName)) { - String fname = mid + "-" + ridnew + "." + attachmentType; - String attachmentURL = "http://i.juick.com/photos-1024/" + fname; - - ImageUtils.saveImageWithPreviews(attachmentFName, fname, tmpDir, imgDir); - - body = attachmentURL + "\n" + body; - try { - xmsg.addExtension(new OobX(new URI(attachmentURL))); - } catch (URISyntaxException e) { - logger.error("invalid uri: {}, exception {}", attachmentURL, e); - } - } - - xmsg.setBody("Reply by @" + jmsg.getUser().getName() + ":\n>" + quote + "\n" + body + "\n\n#" + - mid + "/" + ridnew + " http://juick.com/" + mid + "#" + ridnew); - - xmsg.setTo(Jid.of("juick@s2s.juick.com")); - serverManager.sendMessage(xmsg); - - return jmsg; + return serverManager.processMessage(visitor, body, attachmentFName); } Session session = Session.getDefaultInstance(new Properties()); @@ -268,20 +231,7 @@ public class Post { body[0] = rid > 0 ? String.format("#%d/%d %s", mid, rid, body[0]) : String.format("#%d %s", mid, body[0]); } - rocks.xmpp.core.stanza.model.Message xmsg = new rocks.xmpp.core.stanza.model.Message(); - xmsg.setType(rocks.xmpp.core.stanza.model.Message.Type.CHAT); - xmsg.setFrom(Jid.of(String.valueOf(visitor.getUid()), "uid.juick.com", "mail")); - xmsg.setTo(Jid.of("juick@juick.com/Juick")); - xmsg.setBody(body[0]); - try { - if (StringUtils.isNotEmpty(attachmentFName[0])) { - String attachmentUrl = String.format("juick://%s", attachmentFName[0]); - xmsg.addExtension(new OobX(new URI(attachmentUrl), "!!!!Juick!!")); - } - serverManager.sendMessage(xmsg); - } catch (URISyntaxException e1) { - logger.warn("attachment error", e1); - } + serverManager.processMessage(visitor, body[0], attachmentFName[0]); } else { logger.info("not registered: {}", from); } @@ -303,7 +253,7 @@ public class Post { if (msg.getUser().getUid() == visitor.getUid()) { throw new HttpForbiddenException(); } - String status = commandsManager.commandRecommend(visitor, null, null, String.valueOf(mid)); - return Status.getStatus(status); + CommandResult status = commandsManager.commandRecommend(visitor, null, null, String.valueOf(mid)); + return Status.getStatus(status.getText()); } } |