diff options
author | Vitaly Takmazov | 2018-04-05 12:28:39 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-04-05 12:42:02 +0300 |
commit | 2f53f75e584e0522c8f4783bc28df4ad6eb3033d (patch) | |
tree | 72cb50c58ef003e75d847694f46c877ea345f285 /juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java | |
parent | 21889ca8d29843271c0fcea6a8ea7b64145714bc (diff) |
server: refactoring
Diffstat (limited to 'juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java')
-rw-r--r-- | juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java index 19fddd78..a277a4a4 100644 --- a/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server-xmpp/src/main/java/com/juick/server/XMPPConnection.java @@ -27,7 +27,7 @@ import com.juick.server.helpers.UserInfo; import com.juick.server.util.HttpUtils; import com.juick.server.util.ImageUtils; import com.juick.server.util.TagUtils; -import com.juick.server.xmpp.helpers.CommandResult; +import com.juick.server.helpers.CommandResult; import com.juick.server.xmpp.s2s.BasicXmppSession; import com.juick.server.xmpp.s2s.StanzaListener; import com.juick.service.*; @@ -57,7 +57,6 @@ import rocks.xmpp.extensions.filetransfer.FileTransferManager; import rocks.xmpp.extensions.nick.model.Nickname; import rocks.xmpp.extensions.oob.model.x.OobX; import rocks.xmpp.extensions.ping.PingManager; -import rocks.xmpp.extensions.receipts.MessageDeliveryReceiptsManager; import rocks.xmpp.extensions.vcard.temp.model.VCard; import rocks.xmpp.extensions.version.SoftwareVersionManager; import rocks.xmpp.extensions.version.model.SoftwareVersion; @@ -589,6 +588,11 @@ public class XMPPConnection implements StanzaListener, NotificationListener { User user_from; user_from = userService.getUserByJID(msg.getFrom().asBareJid().toEscapedString()); + if (user_from == null) { + String signuphash = userService.getSignUpHashByJID(msg.getFrom().asBareJid().toEscapedString()); + sendReply(msg.getFrom(), "Для того, чтобы начать пользоваться сервисом, пожалуйста пройдите быструю регистрацию: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nTo start using Juick, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account."); + return; + } URI attachmentURI = URI.create(StringUtils.EMPTY); OobX oobX = msg.getExtension(OobX.class); if (oobX != null) { @@ -596,12 +600,8 @@ public class XMPPConnection implements StanzaListener, NotificationListener { } incomingMessageJuick(user_from, msg.getFrom(), msg.getBody(), attachmentURI); } - public com.juick.Message incomingMessageJuick(User user_from, Jid from, String command, @Nonnull URI attachment) throws Exception { - if (user_from == null) { - String signuphash = userService.getSignUpHashByJID(from.asBareJid().toEscapedString()); - sendReply(from, "Для того, чтобы начать пользоваться сервисом, пожалуйста пройдите быструю регистрацию: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nЕсли у вас уже есть учетная запись на Juick, вы сможете присоединить этот JabberID к ней.\n\nTo start using Juick, please sign up: http://juick.com/signup?type=xmpp&hash=" + signuphash + "\nIf you already have an account on Juick, you will be proposed to attach this JabberID to your existing account."); - return null; - } + public com.juick.Message incomingMessageJuick(User user_from, Jid from, String command, @Nonnull URI attachment) + throws Exception { if (StringUtils.isBlank(command) && attachment.toString().isEmpty()) { return null; } @@ -613,27 +613,11 @@ public class XMPPConnection implements StanzaListener, NotificationListener { command = command.substring(3).trim(); } - Optional<CommandResult> result = commandsManager.processCommand(user_from, from, command, attachment); - if (result.isPresent()) { - sendReply(from, result.get().getText()); - return result.get().getNewMessage(); - } else { - // new message - List<Tag> tags = tagService.fromString(command, false); - String body = command.substring(TagUtils.toString(tags).length()); - String attachmentType = attachment != null && StringUtils.isNotEmpty(attachment.toString()) ? attachment.toString().substring(attachment.toString().length() - 3) : null; - int mid = messagesService.createMessage(user_from.getUid(), body, attachmentType, tags); - subscriptionService.subscribeMessage(mid, user_from.getUid()); - if (StringUtils.isNotEmpty(attachmentType)) { - String attachmentFName = attachment.getScheme().equals("juick") ? attachment.getHost() - : HttpUtils.downloadImage(attachment.toURL(), tmpDir).getHost(); - String fname = String.format("%d.%s", mid, attachmentType); - ImageUtils.saveImageWithPreviews(attachmentFName, fname, tmpDir, imgDir); - } - com.juick.Message msg = messagesService.getMessage(mid); - applicationEventPublisher.publishEvent(new MessageEvent(this, msg)); - return msg; + CommandResult result = commandsManager.processCommand(user_from, from, command, attachment); + if (StringUtils.isNotBlank(result.getText())) { + sendReply(from, result.getText()); } + return result.getNewMessage(); } @Override |