aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/XMPPConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/XMPPConnection.java')
-rw-r--r--juick-server/src/main/java/com/juick/server/XMPPConnection.java27
1 files changed, 11 insertions, 16 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 942b4787..c45fc7cd 100644
--- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java
+++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java
@@ -27,6 +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.xmpp.s2s.BasicXmppSession;
import com.juick.server.xmpp.s2s.StanzaListener;
import com.juick.service.*;
@@ -123,6 +124,8 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
@Inject
private ExecutorService service;
@Inject
+ private ServerManager serverManager;
+ @Inject
private ApplicationEventPublisher applicationEventPublisher;
@PostConstruct
@@ -237,18 +240,12 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
logger.debug("{}: received {} of {}", e.getName(), st.getBytesTransferred(), e.getSize());
if (st.getStatus().equals(FileTransfer.Status.COMPLETED)) {
logger.info("transfer completed");
- Message msg = new Message();
- msg.setType(Message.Type.CHAT);
- msg.setFrom(e.getInitiator());
- msg.setTo(jid);
- msg.setBody(e.getDescription());
try {
- String attachmentUrl = String.format("juick://%s", targetFilename);
- msg.addExtension(new OobX(new URI(attachmentUrl), "!!!!Juick!!"));
- router.sendMessage(msg);
- } catch (URISyntaxException e1) {
- logger.warn("attachment error", e1);
+ serverManager.processMessage(userService.getUserByJID(e.getInitiator().toEscapedString()), e.getDescription(), targetFilename);
+ } catch (Exception e1) {
+ logger.error("ft error", e1);
}
+
} else if (st.getStatus().equals(FileTransfer.Status.FAILED)) {
logger.info("transfer failed", ft.getException());
Message msg = new Message();
@@ -660,17 +657,15 @@ public class XMPPConnection implements StanzaListener, NotificationListener {
command = command.substring(3).trim();
}
- Optional<String> result = commandsManager.processCommand(user_from, from, command, attachment);
+ Optional<CommandResult> result = commandsManager.processCommand(user_from, from, command, attachment);
if (result.isPresent()) {
- sendReply(from, result.get());
- com.juick.Message msg = new com.juick.Message();
- msg.setText(result.get());
- return msg;
+ 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 ? attachment.toString().substring(attachment.toString().length() - 3) : null;
+ String attachmentType = 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)) {