From 1316682a38bdd4c521f342f1100154da1a9c3347 Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Sun, 19 May 2024 21:46:15 -0300 Subject: [PATCH 1/3] Quoted message overriding contextInfo When sendMessage is used with quotedMessage parameter, quoted overrides contextInfo present on original message I don't know if this method is the best method to fix this, but thats the first way I thought --- .../whatsapp/model/info/ContextInfo.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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..e5c1e68c 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,36 @@ public static ContextInfo of(MessageInfo quotedMessage) { .build(); } + public static ContextInfo of(ContextInfo contextInfo, MessageInfo quotedMessage) { + return new ContextInfoBuilder() + .quotedMessageId(quotedMessage.id()) + .quotedMessage(quotedMessage.message()) + .quotedMessageChatJid(quotedMessage.parentJid()) + .quotedMessageSenderJid(quotedMessage.senderJid()) + .actionLink(contextInfo.actionLink().orElse(null)) + .conversionData(contextInfo.conversionData().orElse(null)) + .conversionSource(contextInfo.conversionSource().orElse(null)) + .conversionDelaySeconds(contextInfo.conversionDelaySeconds()) + .entryPointConversionApp(contextInfo.entryPointConversionApp().orElse(null)) + .entryPointConversionSource(contextInfo.entryPointConversionSource().orElse(null)) + .entryPointConversionDelaySeconds(contextInfo.entryPointConversionDelaySeconds()) + .disappearingMode(contextInfo.disappearingMode().orElse(null)) + .ephemeralExpiration(contextInfo.ephemeralExpiration()) + .ephemeralSettingTimestamp(contextInfo.ephemeralSettingTimestamp()) + .externalAdReply(contextInfo.externalAdReply().orElse(null)) + .forwarded(contextInfo.forwarded()) + .forwardingScore(contextInfo.forwardingScore()) + .groupSubject(contextInfo.groupSubject().orElse(null)) + .ephemeralSharedSecret(contextInfo.ephemeralSharedSecret().orElse(null)) + .parentGroup(contextInfo.parentGroup().orElse(null)) + .placeholderKey(contextInfo.placeholderKey().orElse(null)) + .quotedAd(contextInfo.quotedAd().orElse(null)) + .trustBannerAction(contextInfo.trustBannerAction()) + .trustBannerType(contextInfo.trustBannerType().orElse(null)) + .mentions(contextInfo.mentions()) + .build(); + } + public static ContextInfo empty() { return new ContextInfoBuilder() .mentions(new ArrayList<>()) @@ -401,4 +431,4 @@ public Optional trustBannerType() { public int trustBannerAction() { return trustBannerAction; } -} \ No newline at end of file +} From 10002c505d8576dac1c05819b60f9bb63a65143b Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Sun, 19 May 2024 21:53:43 -0300 Subject: [PATCH 2/3] Changes on sendMessage structure --- src/main/java/it/auties/whatsapp/api/Whatsapp.java | 9 +++------ 1 file changed, 3 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 b8c05869..bc3c9de1 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)); } From 2803d7be3d72ab035ee7d45f52b8eb59803739b3 Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Sun, 16 Jun 2024 19:50:55 -0300 Subject: [PATCH 3/3] automating data association --- .../whatsapp/model/info/ContextInfo.java | 42 +++++++------------ 1 file changed, 15 insertions(+), 27 deletions(-) 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 e5c1e68c..fd55367c 100644 --- a/src/main/java/it/auties/whatsapp/model/info/ContextInfo.java +++ b/src/main/java/it/auties/whatsapp/model/info/ContextInfo.java @@ -227,33 +227,21 @@ public static ContextInfo of(MessageInfo quotedMessage) { } public static ContextInfo of(ContextInfo contextInfo, MessageInfo quotedMessage) { - return new ContextInfoBuilder() - .quotedMessageId(quotedMessage.id()) - .quotedMessage(quotedMessage.message()) - .quotedMessageChatJid(quotedMessage.parentJid()) - .quotedMessageSenderJid(quotedMessage.senderJid()) - .actionLink(contextInfo.actionLink().orElse(null)) - .conversionData(contextInfo.conversionData().orElse(null)) - .conversionSource(contextInfo.conversionSource().orElse(null)) - .conversionDelaySeconds(contextInfo.conversionDelaySeconds()) - .entryPointConversionApp(contextInfo.entryPointConversionApp().orElse(null)) - .entryPointConversionSource(contextInfo.entryPointConversionSource().orElse(null)) - .entryPointConversionDelaySeconds(contextInfo.entryPointConversionDelaySeconds()) - .disappearingMode(contextInfo.disappearingMode().orElse(null)) - .ephemeralExpiration(contextInfo.ephemeralExpiration()) - .ephemeralSettingTimestamp(contextInfo.ephemeralSettingTimestamp()) - .externalAdReply(contextInfo.externalAdReply().orElse(null)) - .forwarded(contextInfo.forwarded()) - .forwardingScore(contextInfo.forwardingScore()) - .groupSubject(contextInfo.groupSubject().orElse(null)) - .ephemeralSharedSecret(contextInfo.ephemeralSharedSecret().orElse(null)) - .parentGroup(contextInfo.parentGroup().orElse(null)) - .placeholderKey(contextInfo.placeholderKey().orElse(null)) - .quotedAd(contextInfo.quotedAd().orElse(null)) - .trustBannerAction(contextInfo.trustBannerAction()) - .trustBannerType(contextInfo.trustBannerType().orElse(null)) - .mentions(contextInfo.mentions()) - .build(); + var newContext = of(quotedMessage); + var fields = contextInfo.getClass().getFields(); + try { + for (var field : fields) { + field.setAccessible(true); + var value = field.get(contextInfo); + if (value != null) { + field.set(newContext, value); + } + } + return newContext; + } catch (IllegalAccessException e) { + System.err.println("Failed to merge context info"); + return ContextInfo.of(quotedMessage); + } } public static ContextInfo empty() {