aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-server/src/main/java/com/juick/service/UserService.java2
-rw-r--r--juick-server/src/main/java/com/juick/service/UserServiceImpl.java6
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/s2s/JuickBot.java28
3 files changed, 35 insertions, 1 deletions
diff --git a/juick-server/src/main/java/com/juick/service/UserService.java b/juick-server/src/main/java/com/juick/service/UserService.java
index 166cfeeb..661f386c 100644
--- a/juick-server/src/main/java/com/juick/service/UserService.java
+++ b/juick-server/src/main/java/com/juick/service/UserService.java
@@ -121,4 +121,6 @@ public interface UserService {
boolean deleteJID(int uid, String jid);
boolean unauthJID(int uid, String jid);
+
+ List<String> getAllJIDs();
}
diff --git a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
index b1339049..81a1fea7 100644
--- a/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/UserServiceImpl.java
@@ -693,4 +693,10 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
return getJdbcTemplate()
.update("DELETE FROM auth WHERE user_id=? AND protocol='xmpp' AND account=?", uid, jid) > 0;
}
+
+ @Transactional(readOnly = true)
+ @Override
+ public List<String> getAllJIDs() {
+ return getJdbcTemplate().queryForList("SELECT jid FROM jids WHERE loginhash IS NULL", String.class);
+ }
}
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);
+ }
}