diff options
Diffstat (limited to 'src/main/java/com/juick/XMPPManager.java')
-rw-r--r-- | src/main/java/com/juick/XMPPManager.java | 65 |
1 files changed, 26 insertions, 39 deletions
diff --git a/src/main/java/com/juick/XMPPManager.java b/src/main/java/com/juick/XMPPManager.java index 624fe73a..1080b1b9 100644 --- a/src/main/java/com/juick/XMPPManager.java +++ b/src/main/java/com/juick/XMPPManager.java @@ -91,38 +91,22 @@ import java.util.concurrent.Executor; public class XMPPManager implements NotificationListener { private static final Logger logger = LoggerFactory.getLogger("XMPP"); private ExternalComponent xmpp; - @Value("${xmppbot_jid:juick@localhost}") - private String botJid; - @Value("${hostname:localhost}") - private String componentName; - @Value("${component_port:5347}") - private int componentPort; - @Value("${component_host:localhost}") - private String componentHost; - @Inject - private CommandsManager commandsManager; - @Value("${xmpp_password:secret}") - private String password; - @Value("classpath:juick.png") - private Resource vCardImage; - @Inject - private StorageService storageService; - @Inject - private MessagesService messagesService; - @Inject - private UserService userService; - @Inject - private PMQueriesService pmQueriesService; - @Inject - private Executor applicationTaskExecutor; - @Inject - private WebApp webApp; - - private Jid jid; - - @PostConstruct - public void init() { + private final CommandsManager commandsManager; + private final MessagesService messagesService; + private final UserService userService; + private final PMQueriesService pmQueriesService; + + private final Jid jid; + + public XMPPManager(String botJid, String componentName, int componentPort, String componentHost, + String password, Resource vCardImage, CommandsManager commandsManager, + StorageService storageService, MessagesService messagesService, UserService userService, + PMQueriesService pmQueriesService, Executor applicationTaskExecutor, WebApp webApp) { jid = Jid.of(botJid); + this.commandsManager = commandsManager; + this.messagesService = messagesService; + this.userService = userService; + this.pmQueriesService = pmQueriesService; logger.info("xmpp component start connecting to {}", componentPort); XmppSessionConfiguration configuration = XmppSessionConfiguration.builder() .extensions(Extension.of(com.juick.model.Message.class), Extension.of(MessageQuery.class)) @@ -155,6 +139,7 @@ public class XMPPManager implements NotificationListener { public java.lang.Class<?> getPayloadClass() { return MessageQuery.class; } + public IQ handleRequest(IQ iq) { Message warningMessage = new Message(iq.getFrom(), Message.Type.CHAT); warningMessage.setFrom(jid); @@ -164,11 +149,12 @@ public class XMPPManager implements NotificationListener { } }); xmpp.addIQHandler(new IQHandler() { - public Class<?> getPayloadClass() { - return VCard.class; - } - @Override - public IQ handleRequest(IQ iq) { + public Class<?> getPayloadClass() { + return VCard.class; + } + + @Override + public IQ handleRequest(IQ iq) { if (iq.getTo().equals(jid) || iq.getTo().asBareJid().equals(jid.asBareJid()) || iq.getTo().asBareJid().toEscapedString().equals(jid.getDomain())) { return iq.createResult(vCard); @@ -349,6 +335,7 @@ public class XMPPManager implements NotificationListener { processLike(activity.getFrom(), activity.getMessage(), activity.getTo()); } } + private void processMessage(com.juick.model.Message msg, List<User> subscribers) { if (msg.isService()) { return; @@ -371,8 +358,7 @@ public class XMPPManager implements NotificationListener { }); } else if (MessageUtils.isReply(msg)) { sendJuickComment(msg, subscribers); - } - else { + } else { sendJuickMessage(msg, subscribers); } } @@ -484,7 +470,7 @@ public class XMPPManager implements NotificationListener { Presence reply = new Presence(); reply.setFrom(p.getTo().withResource(jid.getResource())); reply.setTo(p.getFrom()); - reply.setPriority((byte)10); + reply.setPriority((byte) 10); if (!userService.getActiveJIDs().contains(p.getFrom().asBareJid().toEscapedString())) { reply.setStatus("Send ON to enable notifications"); } @@ -586,6 +572,7 @@ public class XMPPManager implements NotificationListener { errorMessage.setError(new StanzaError(StanzaError.Type.CANCEL, Condition.ITEM_NOT_FOUND)); return errorMessage; } + private ClientMessage incomingMessageJuick(User user_from, Jid from, String to, String command, @Nonnull URI attachment) { if (StringUtils.isBlank(command) && attachment.toString().isEmpty()) { return null; |