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..6a398a6e 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; } @@ -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 * @@ -274,4 +278,4 @@ public boolean hasAgent() { public int hashCode() { return Objects.hashCode(toString()); } -} \ No newline at end of file +} diff --git a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java index 8759ba18..2be64740 100644 --- a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java +++ b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java @@ -715,15 +715,22 @@ 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); + 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)); @@ -742,6 +749,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); @@ -749,8 +759,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));