Skip to content

Commit

Permalink
automating data association
Browse files Browse the repository at this point in the history
  • Loading branch information
Darker935 authored Jun 16, 2024
1 parent 10002c5 commit 2803d7b
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions src/main/java/it/auties/whatsapp/model/info/ContextInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2803d7b

Please sign in to comment.