aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'juick-xmpp')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java
index cf791ada..9a970855 100644
--- a/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java
+++ b/juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java
@@ -3,6 +3,8 @@ package com.juick.components.s2s;
import com.juick.User;
import com.juick.components.XMPPServer;
import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import rocks.xmpp.addr.Jid;
import rocks.xmpp.core.stanza.model.Message;
import rocks.xmpp.core.stanza.model.Presence;
@@ -21,7 +23,9 @@ import java.util.regex.Pattern;
*
* @author ugnich
*/
-public class JuickBot implements StanzaListener {
+public class JuickBot implements StanzaListener, AutoCloseable {
+
+ private static final Logger logger = LoggerFactory.getLogger(JuickBot.class);
XMPPServer xmpp;
@@ -29,6 +33,7 @@ public class JuickBot implements StanzaListener {
public JuickBot(XMPPServer xmpp) {
this.xmpp = xmpp;
xmpp.addStanzaListener(this);
+ broadcastPresence(null);
}
private static final String HELPTEXT =
@@ -431,4 +436,25 @@ public class JuickBot implements StanzaListener {
}
}
}
+
+ void broadcastPresence(Presence.Type type) {
+ Presence presence = new Presence();
+ presence.setFrom(xmpp.getJid());
+ if (type != null) {
+ presence.setType(type);
+ }
+ xmpp.userService.getAllJIDs().forEach(j -> {
+ try {
+ presence.setTo(Jid.of(j));
+ xmpp.sendOut(ClientPresence.from(presence));
+ } catch (IllegalArgumentException ex) {
+ logger.warn("Invalid jid: {}", j, ex);
+ }
+ });
+ }
+
+ @Override
+ public void close() throws Exception {
+ broadcastPresence(Presence.Type.UNAVAILABLE);
+ }
}