diff --git a/src/main/java/it/auties/whatsapp/api/Whatsapp.java b/src/main/java/it/auties/whatsapp/api/Whatsapp.java index b8c05869..c7e1f849 100644 --- a/src/main/java/it/auties/whatsapp/api/Whatsapp.java +++ b/src/main/java/it/auties/whatsapp/api/Whatsapp.java @@ -411,7 +411,7 @@ public CompletableFuture sendReaction(MessageInfo message */ public CompletableFuture sendReaction(MessageInfo message, String reaction) { var key = new ChatMessageKeyBuilder() - .id(ChatMessageKey.randomId()) + .id(ChatMessageKey.randomIdV2(message.senderJid(), store().clientType())) .chatJid(message.parentJid()) .senderJid(message.senderJid()) .fromMe(Objects.equals(message.senderJid().toSimpleJid(), jidOrThrowError().toSimpleJid())) @@ -574,7 +574,7 @@ public CompletableFuture sendChatMessage(JidProvider recipient, .deviceListMetadataVersion(2) .build(); var key = new ChatMessageKeyBuilder() - .id(ChatMessageKey.randomId()) + .id(ChatMessageKey.randomIdV2(jidOrThrowError(), store().clientType())) .chatJid(recipient.toJid()) .fromMe(true) .senderJid(jidOrThrowError()) @@ -688,7 +688,7 @@ public CompletableFuture sendStatus(MessageContainer message) { .deviceListMetadataVersion(2) .build(); var key = new ChatMessageKeyBuilder() - .id(ChatMessageKey.randomId()) + .id(ChatMessageKey.randomIdV2(jidOrThrowError(), store().clientType())) .chatJid(Jid.of("status@broadcast")) .fromMe(true) .senderJid(jidOrThrowError()) @@ -1731,7 +1731,7 @@ public CompletableFuture deleteMessage(ChatMessageInfo messageInfo, boolea .build(); var sender = messageInfo.chatJid().hasServer(JidServer.GROUP) ? jidOrThrowError() : null; var key = new ChatMessageKeyBuilder() - .id(ChatMessageKey.randomId()) + .id(ChatMessageKey.randomIdV2(sender, store().clientType())) .chatJid(messageInfo.chatJid()) .fromMe(true) .senderJid(sender) diff --git a/src/main/java/it/auties/whatsapp/model/message/model/ChatMessageKey.java b/src/main/java/it/auties/whatsapp/model/message/model/ChatMessageKey.java index 5898b2b9..18c46724 100644 --- a/src/main/java/it/auties/whatsapp/model/message/model/ChatMessageKey.java +++ b/src/main/java/it/auties/whatsapp/model/message/model/ChatMessageKey.java @@ -10,10 +10,11 @@ import it.auties.whatsapp.model.jid.Jid; import it.auties.whatsapp.util.Bytes; -import java.util.HexFormat; -import java.util.Locale; -import java.util.Objects; -import java.util.Optional; +import java.nio.ByteBuffer; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.time.Instant; +import java.util.*; /** * A container for unique identifiers and metadata linked to a {@link Message} and contained in @@ -37,7 +38,7 @@ public final class ChatMessageKey implements ProtobufMessage { public ChatMessageKey(Jid chatJid, boolean fromMe, String id, Jid senderJid) { this.chatJid = chatJid; this.fromMe = fromMe; - this.id = Objects.requireNonNullElseGet(id, ChatMessageKey::randomId); + this.id = Objects.requireNonNullElse(id, randomIdV2(senderJid)); this.senderJid = senderJid; } @@ -46,7 +47,7 @@ public ChatMessageKey(Jid chatJid, boolean fromMe) { } public ChatMessageKey(Jid chatJid, boolean fromMe, Jid senderJid) { - this(chatJid, fromMe, randomId(), senderJid); + this(chatJid, fromMe, randomIdV2(senderJid), senderJid); } /** diff --git a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java index 8759ba18..a57704a4 100644 --- a/src/main/java/it/auties/whatsapp/socket/SocketHandler.java +++ b/src/main/java/it/auties/whatsapp/socket/SocketHandler.java @@ -455,7 +455,7 @@ public CompletableFuture sendPeerMessage(Jid companion, ProtocolMessage me var jid = store.jid() .orElseThrow(() -> new IllegalStateException("The session isn't connected")); var key = new ChatMessageKeyBuilder() - .id(ChatMessageKey.randomId()) + .id(ChatMessageKey.randomIdV2(jid, store.clientType())) .chatJid(companion) .fromMe(true) .senderJid(jid) diff --git a/src/test/java/it/auties/whatsapp/TestLibrary.java b/src/test/java/it/auties/whatsapp/TestLibrary.java index 8423d433..53a6bf72 100644 --- a/src/test/java/it/auties/whatsapp/TestLibrary.java +++ b/src/test/java/it/auties/whatsapp/TestLibrary.java @@ -756,7 +756,7 @@ public void testListMessage() { .jid() .orElseThrow(); var keyInfo = new ChatMessageKeyBuilder() - .id(ChatMessageKey.randomId()) + .id(ChatMessageKey.randomIdV2(jid, api.store().clientType())) .chatJid(contact) .senderJid(jid) .fromMe(true)