From 32f589b3555f04ea53e0878347523f66b5b97d3c Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Wed, 8 May 2024 12:51:12 -0300 Subject: [PATCH 1/9] Receipts not sending on groups --- .../java/it/auties/whatsapp/socket/SocketHandler.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java index 8759ba18..48ff0577 100644 --- a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java +++ b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java @@ -721,9 +721,13 @@ public CompletableFuture sendReceipt(Jid jid, Jid participant, List Objects.equals(type, "read") || Objects.equals(type, "read-self")) .put("to", jid) .put("type", type, Objects::nonNull); - if (Objects.equals(type, "sender") && jid.hasServer(JidServer.WHATSAPP)) { - attributes.put("recipient", jid); - attributes.put("to", participant); + if (Objects.equals(type, "sender")) { + if (jid.hasServer(JidServer.WHATSAPP)) { + attributes.put("recipient", jid); + attributes.put("to", participant); + } else if (jid.hasServer(JidServer.GROUP)) { + attributes.put("participant", participant); + } } var receipt = Node.of("receipt", attributes.toMap(), toMessagesNode(messages)); From 6c9b930740ec719470a929099bdfacfad546bd8e Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Sat, 15 Jun 2024 20:58:08 -0300 Subject: [PATCH 2/9] Converting LIDS to SimpleJid --- .../java/it/auties/whatsapp/socket/SocketHandler.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java index 48ff0577..f795b379 100644 --- a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java +++ b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java @@ -715,13 +715,19 @@ public CompletableFuture sendReceipt(Jid jid, Jid participant, List Objects.equals(type, "read") || Objects.equals(type, "read-self")) .put("to", jid) .put("type", type, Objects::nonNull); - if (Objects.equals(type, "sender")) { + if (type == null || Objects.equals(type, "sender")) { if (jid.hasServer(JidServer.WHATSAPP)) { attributes.put("recipient", jid); attributes.put("to", participant); From 484aaeea8eda24f3b0932971d62738c2d4a054eb Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Sat, 15 Jun 2024 21:00:53 -0300 Subject: [PATCH 3/9] Adding support to LIDs Idk if it's the best and correct way to identify lids, but I noticed that when a JID comes with `agent: 1` it's a lid Ps: not every LID comes with `agent: 1`, but every `agent: 1` is a lid --- src/main/java/it/auties/whatsapp/model/jid/Jid.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/auties/whatsapp/model/jid/Jid.java b/src/main/java/it/auties/whatsapp/model/jid/Jid.java index 390668a7..8a79b20e 100644 --- a/src/main/java/it/auties/whatsapp/model/jid/Jid.java +++ b/src/main/java/it/auties/whatsapp/model/jid/Jid.java @@ -17,7 +17,7 @@ public record Jid(String user, JidServer server, Integer device, Integer agent) */ public Jid(String user, JidServer server, Integer device, Integer agent) { this.user = user != null && user.startsWith("+") ? user.substring(1) : user; - this.server = server; + this.server = agent != null && agent == 1 ? JidServer.LID : server; this.device = device; this.agent = agent; } @@ -274,4 +274,4 @@ public boolean hasAgent() { public int hashCode() { return Objects.hashCode(toString()); } -} \ No newline at end of file +} From 5e89fc63b09b0b90fc35da95abc5b62738c8560e Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Sat, 15 Jun 2024 21:58:54 -0300 Subject: [PATCH 4/9] withAgent() method --- src/main/java/it/auties/whatsapp/model/jid/Jid.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/it/auties/whatsapp/model/jid/Jid.java b/src/main/java/it/auties/whatsapp/model/jid/Jid.java index 8a79b20e..6a398a6e 100644 --- a/src/main/java/it/auties/whatsapp/model/jid/Jid.java +++ b/src/main/java/it/auties/whatsapp/model/jid/Jid.java @@ -189,6 +189,10 @@ public Jid withServer(JidServer server) { return new Jid(user(), server, device, agent); } + public Jid withAgent(Integer agent) { + return new Jid(user(), server, device, agent); + } + /** * Converts this jid to a user jid * From 7224f9293a13533e9a4daeb57ab35975a8503bac Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Sat, 15 Jun 2024 22:00:53 -0300 Subject: [PATCH 5/9] Update SocketHandler.java Removing agent from jids (participant and jid) --- .../java/it/auties/whatsapp/socket/SocketHandler.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java index f795b379..53a1d42f 100644 --- a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java +++ b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java @@ -715,12 +715,9 @@ public CompletableFuture sendReceipt(Jid jid, Jid participant, List Date: Mon, 17 Jun 2024 09:23:48 -0300 Subject: [PATCH 6/9] Update SocketHandler.java --- .../java/it/auties/whatsapp/socket/SocketHandler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java index 53a1d42f..63c51757 100644 --- a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java +++ b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java @@ -716,8 +716,12 @@ public CompletableFuture sendReceipt(Jid jid, Jid participant, List Date: Mon, 17 Jun 2024 09:43:24 -0300 Subject: [PATCH 7/9] Update SocketHandler.java --- src/main/java/it/auties/whatsapp/socket/SocketHandler.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java index 63c51757..f68f02ea 100644 --- a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java +++ b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java @@ -716,9 +716,7 @@ public CompletableFuture sendReceipt(Jid jid, Jid participant, List Date: Mon, 24 Jun 2024 14:01:01 -0300 Subject: [PATCH 8/9] send message ack causing dead sessions too --- src/main/java/it/auties/whatsapp/socket/SocketHandler.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java index f68f02ea..c8af1dcb 100644 --- a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java +++ b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java @@ -751,6 +751,9 @@ private List toMessagesNode(List messages) { protected CompletableFuture sendMessageAck(Jid from, Node node) { var attrs = node.attributes(); + var to = from.withAgent(null); + var participant = attrs.getNullableString("participant"); + var recipient = attrs.getNullableString("recipient"); var type = attrs.getOptionalString("type") .filter(entry -> !Objects.equals(entry, "message")) .orElse(null); @@ -758,8 +761,8 @@ protected CompletableFuture sendMessageAck(Jid from, Node node) { .put("id", node.id()) .put("to", from) .put("class", node.description()) - .put("participant", attrs.getNullableString("participant"), Objects::nonNull) - .put("recipient", attrs.getNullableString("recipient"), Objects::nonNull) + .put("participant", Jid.of(participant).withAgent(null), Objects.nonNull(participant)) + .put("recipient", Jid.of(recipient).withAgent(null), Objects.nonNull(recipient)) .put("type", type, Objects::nonNull) .toMap(); return sendNodeWithNoResponse(Node.of("ack", attributes)); From a32ae01728c7067d22f6b2433be4ecfd938e1979 Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Fri, 28 Jun 2024 22:14:16 -0300 Subject: [PATCH 9/9] recipient sending on non-allowed receipts --- .../it/auties/whatsapp/socket/SocketHandler.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java index c8af1dcb..2be64740 100644 --- a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java +++ b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java @@ -726,13 +726,11 @@ public CompletableFuture sendReceipt(Jid jid, Jid participant, List Objects.equals(type, "read") || Objects.equals(type, "read-self")) .put("to", jid) .put("type", type, Objects::nonNull); - if (type == null || Objects.equals(type, "sender")) { - if (jid.hasServer(JidServer.WHATSAPP)) { - attributes.put("recipient", jid); - attributes.put("to", participant); - } else if (jid.hasServer(JidServer.GROUP)) { - attributes.put("participant", participant); - } + if (jid.hasServer(JidServer.WHATSAPP)) { + attributes.put("to", participant); + attributes.put("recipient", jid, Objects.equals(type, "sender")); + } else if (jid.hasServer(JidServer.GROUP)) { + attributes.put("participant", participant); } var receipt = Node.of("receipt", attributes.toMap(), toMessagesNode(messages));