From 6c23b3110efcf4ad938427d2eabe95387ee294ce Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Fri, 19 Apr 2024 22:46:08 -0300 Subject: [PATCH 1/6] Handling edited messages + fixing protocolType() exception Sometimes, when a verified BOT send a message to the host, after a time, the session starts to throw an exception, that says: `java.lang.NullPointerException: Cannot invoke "it.auties.whatsapp.model.message.server.ProtocolMessage$Type.ordinal()" because the return value of "it.auties.whatsapp.model.message.server.ProtocolMessage.protocolType()" is null at it.auties.whatsapp.socket.MessageHandler.handleProtocolMessage(MessageHandler.java:934) at it.auties.whatsapp.socket.MessageHandler.saveMessage(MessageHandler.java:901) at it.auties.whatsapp.socket.MessageHandler.decodeChatMessage(MessageHandler.java:806) at it.auties.whatsapp.socket.MessageHandler.lambda$decode$55(MessageHandler.java:618) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at it.auties.whatsapp.socket.MessageHandler.decode(MessageHandler.java:618) at it.auties.whatsapp.socket.SocketHandler.decodeMessage(SocketHandler.java:447) at it.auties.whatsapp.socket.StreamHandler.digest(StreamHandler.java:107) at it.auties.whatsapp.socket.SocketHandler.onMessage(SocketHandler.java:201) at it.auties.whatsapp.socket.SocketSession$WebSocketSession.notifyMessage(SocketSession.java:150) at it.auties.whatsapp.socket.SocketSession$WebSocketSession.onBinary(SocketSession.java:139) at it.auties.whatsapp.socket.SocketSession$WebSocketSession.onBinary(SocketSession.java:141) at it.auties.whatsapp.socket.SocketSession$WebSocketSession.onBinary(SocketSession.java:141) ` --- src/main/java/it/auties/whatsapp/socket/MessageHandler.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/auties/whatsapp/socket/MessageHandler.java b/src/main/java/it/auties/whatsapp/socket/MessageHandler.java index 0ab21b01..da8adbae 100644 --- a/src/main/java/it/auties/whatsapp/socket/MessageHandler.java +++ b/src/main/java/it/auties/whatsapp/socket/MessageHandler.java @@ -1076,10 +1076,12 @@ private void saveMessage(ChatMessageInfo info, boolean notify) { return; } if (info.message().hasCategory(MessageCategory.SERVER)) { - if (info.message().content() instanceof ProtocolMessage protocolMessage) { + if (!(info.message().content() instanceof ProtocolMessage protocolMessage)) return; + if (protocolMessage.protocolType() == null) return; + if (!protocolMessage.protocolType().equals(ProtocolMessage.Type.MESSAGE_EDIT)) { handleProtocolMessage(info, protocolMessage); + return; } - return; } var chat = info.chat() From 21c777fa62cbc1ebbd738b59576109e038558b67 Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Fri, 19 Apr 2024 22:59:58 -0300 Subject: [PATCH 2/6] just a test --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 41baf86c..dc46c277 100644 --- a/pom.xml +++ b/pom.xml @@ -173,7 +173,7 @@ 21 3.0.0-M9 3.0.1 - 3.11.0 + 3.13.0 3.2.1 3.5.0 1.6.13 From bc5ca89739ce5e1e51b2c8e1465705ea7b3dd150 Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Fri, 19 Apr 2024 23:04:39 -0300 Subject: [PATCH 3/6] Revert "just a test" This reverts commit 21c777fa62cbc1ebbd738b59576109e038558b67. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dc46c277..41baf86c 100644 --- a/pom.xml +++ b/pom.xml @@ -173,7 +173,7 @@ 21 3.0.0-M9 3.0.1 - 3.13.0 + 3.11.0 3.2.1 3.5.0 1.6.13 From c9b4d9f8c964be153af231ea366571f509a560df Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Sun, 28 Apr 2024 07:15:27 -0300 Subject: [PATCH 4/6] Sent messages aren't showing on WhatsApp Desktop --- src/main/java/it/auties/whatsapp/api/Whatsapp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/it/auties/whatsapp/api/Whatsapp.java b/src/main/java/it/auties/whatsapp/api/Whatsapp.java index b8c05869..c79f08de 100644 --- a/src/main/java/it/auties/whatsapp/api/Whatsapp.java +++ b/src/main/java/it/auties/whatsapp/api/Whatsapp.java @@ -583,7 +583,7 @@ public CompletableFuture sendChatMessage(JidProvider recipient, .status(MessageStatus.PENDING) .senderJid(jidOrThrowError()) .key(key) - .message(message.withDeviceInfo(deviceInfo)) + .message(recipient.toJid().hasServer(JidServer.GROUP) ? message : message.withDeviceInfo(deviceInfo)) .timestampSeconds(timestamp) .broadcast(recipient.toJid().hasServer(JidServer.BROADCAST)) .build(); 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 5/6] 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 71eeaae917f342c60624a1da40752156615e439b Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Sun, 19 May 2024 21:30:27 -0300 Subject: [PATCH 6/6] Fixed contextInfo overriding --- .../java/it/auties/whatsapp/api/Whatsapp.java | 9 ++---- .../whatsapp/model/info/ContextInfo.java | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/it/auties/whatsapp/api/Whatsapp.java b/src/main/java/it/auties/whatsapp/api/Whatsapp.java index c79f08de..9eb54653 100644 --- a/src/main/java/it/auties/whatsapp/api/Whatsapp.java +++ b/src/main/java/it/auties/whatsapp/api/Whatsapp.java @@ -503,8 +503,7 @@ public CompletableFuture sendNewsletterMessage(JidProvide * @return a CompletableFuture */ public CompletableFuture sendMessage(JidProvider chat, ContextualMessage message, MessageInfo quotedMessage) { - var contextInfo = ContextInfo.of(quotedMessage); - message.setContextInfo(contextInfo); + message.contextInfo().ifPresentOrElse(contextInfo -> message.setContextInfo(ContextInfo.of(contextInfo, quotedMessage)), () -> message.setContextInfo(ContextInfo.of(quotedMessage))); return sendMessage(chat, MessageContainer.of(message)); } @@ -517,8 +516,7 @@ public CompletableFuture sendMessage(JidProvider chat, Co * @return a CompletableFuture */ public CompletableFuture sendChatMessage(JidProvider chat, ContextualMessage message, MessageInfo quotedMessage) { - var contextInfo = ContextInfo.of(quotedMessage); - message.setContextInfo(contextInfo); + message.contextInfo().ifPresentOrElse(contextInfo -> message.setContextInfo(ContextInfo.of(contextInfo, quotedMessage)), () -> message.setContextInfo(ContextInfo.of(quotedMessage))); return sendChatMessage(chat, MessageContainer.of(message)); } @@ -532,8 +530,7 @@ public CompletableFuture sendChatMessage(JidProvider chat, Cont * @return a CompletableFuture */ public CompletableFuture sendNewsletterMessage(JidProvider chat, ContextualMessage message, MessageInfo quotedMessage) { - var contextInfo = ContextInfo.of(quotedMessage); - message.setContextInfo(contextInfo); + message.contextInfo().ifPresentOrElse(contextInfo -> message.setContextInfo(ContextInfo.of(contextInfo, quotedMessage)), () -> message.setContextInfo(ContextInfo.of(quotedMessage))); return sendNewsletterMessage(chat, MessageContainer.of(message)); } diff --git a/src/main/java/it/auties/whatsapp/model/info/ContextInfo.java b/src/main/java/it/auties/whatsapp/model/info/ContextInfo.java index 09f19437..2fa3086c 100644 --- a/src/main/java/it/auties/whatsapp/model/info/ContextInfo.java +++ b/src/main/java/it/auties/whatsapp/model/info/ContextInfo.java @@ -226,6 +226,37 @@ public static ContextInfo of(MessageInfo quotedMessage) { .build(); } + public static ContextInfo of(ContextInfo context, MessageInfo quotedMessage) { + return new ContextInfoBuilder() + .quotedMessageId(quotedMessage.id()) + .quotedMessage(quotedMessage.message()) + .quotedMessageChatJid(quotedMessage.parentJid()) + .quotedMessageSenderJid(quotedMessage.senderJid()) + .actionLink(context.actionLink().orElse(null)) + .conversionData(context.conversionData().orElse(null)) + .conversionSource(context.conversionSource().orElse(null)) + .conversionDelaySeconds(context.conversionDelaySeconds()) + .entryPointConversionApp(context.entryPointConversionApp().orElse(null)) + .entryPointConversionSource(context.entryPointConversionSource().orElse(null)) + .entryPointConversionDelaySeconds(context.entryPointConversionDelaySeconds()) + .disappearingMode(context.disappearingMode().orElse(null)) + .ephemeralExpiration(context.ephemeralExpiration()) + .ephemeralSettingTimestamp(context.ephemeralSettingTimestamp()) + .externalAdReply(context.externalAdReply().orElse(null)) + .forwarded(context.forwarded()) + .forwardingScore(context.forwardingScore()) + .groupSubject(context.groupSubject().orElse(null)) + .ephemeralSharedSecret(context.ephemeralSharedSecret().orElse(null)) + .parentGroup(context.parentGroup().orElse(null)) + .placeholderKey(context.placeholderKey().orElse(null)) + .quotedAd(context.quotedAd().orElse(null)) + .trustBannerAction(context.trustBannerAction()) + .trustBannerType(context.trustBannerType().orElse(null)) + .mentions(context.mentions()) + .build(); + } + + public static ContextInfo empty() { return new ContextInfoBuilder() .mentions(new ArrayList<>())