From 85e9288348e93bf033ad8b7a648fcc94189b9a96 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 10 Jan 2023 09:07:15 +0300 Subject: XMPP: send `unsubscribe` presence to unknown JIDs --- src/main/java/com/juick/XMPPManager.java | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/main/java/com/juick/XMPPManager.java b/src/main/java/com/juick/XMPPManager.java index cba6ef3e..38da2d51 100644 --- a/src/main/java/com/juick/XMPPManager.java +++ b/src/main/java/com/juick/XMPPManager.java @@ -424,6 +424,7 @@ public class XMPPManager implements NotificationListener { } private void incomingPresence(Presence p) { + User visitor = userService.getUserByJID(p.getFrom().asBareJid().toEscapedString()); final boolean toJuick = isValidTarget(p.getTo(), false); if (p.getType() == null) { Presence reply = new Presence(); @@ -433,27 +434,28 @@ public class XMPPManager implements NotificationListener { xmpp.send(ClientPresence.from(reply)); } else if (p.getType().equals(Presence.Type.PROBE)) { if (toJuick) { - User visitor = userService.getUserByJID(p.getFrom().asBareJid().toEscapedString()); if (visitor != null) { userService.updateLastSeen(visitor); + Presence reply = new Presence(); + reply.setFrom(p.getTo().withResource(jid.getResource())); + reply.setTo(p.getFrom()); + reply.setPriority((byte) 10); + if (!userService.getActiveJIDs().contains(p.getFrom().asBareJid().toEscapedString())) { + reply.setStatus("Send ON to enable notifications"); + } + xmpp.send(ClientPresence.from(reply)); + } else { + Presence reply = new Presence(); + reply.setFrom(p.getTo()); + reply.setTo(p.getFrom()); + reply.setType(Presence.Type.UNSUBSCRIBED); + xmpp.send(ClientPresence.from(reply)); } - } - if (toJuick) { - Presence reply = new Presence(); - reply.setFrom(p.getTo().withResource(jid.getResource())); - reply.setTo(p.getFrom()); - reply.setPriority((byte) 10); - if (!userService.getActiveJIDs().contains(p.getFrom().asBareJid().toEscapedString())) { - reply.setStatus("Send ON to enable notifications"); - } - xmpp.send(ClientPresence.from(reply)); } else { Presence reply = new Presence(); reply.setFrom(p.getTo()); reply.setTo(p.getFrom()); - reply.setType(Presence.Type.ERROR); - reply.setId(p.getId()); - reply.setError(new StanzaError(StanzaError.Type.CANCEL, Condition.ITEM_NOT_FOUND)); + reply.setType(Presence.Type.UNSUBSCRIBED); xmpp.send(ClientPresence.from(reply)); } } else if (p.getType().equals(Presence.Type.SUBSCRIBE)) { -- cgit v1.2.3