Skip to content

Commit

Permalink
Invoking randomIdV2()
Browse files Browse the repository at this point in the history
  • Loading branch information
Darker935 committed Jun 16, 2024
1 parent 096839e commit 965213a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/main/java/it/auties/whatsapp/api/Whatsapp.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public CompletableFuture<? extends MessageInfo> sendReaction(MessageInfo message
*/
public CompletableFuture<? extends MessageInfo> 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()))
Expand Down Expand Up @@ -574,7 +574,7 @@ public CompletableFuture<ChatMessageInfo> 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())
Expand Down Expand Up @@ -688,7 +688,7 @@ public CompletableFuture<ChatMessageInfo> 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())
Expand Down Expand Up @@ -1731,7 +1731,7 @@ public CompletableFuture<Void> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/auties/whatsapp/socket/SocketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public CompletableFuture<Void> 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)
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/it/auties/whatsapp/TestLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 965213a

Please sign in to comment.