Skip to content

Commit

Permalink
Fix when JID is null
Browse files Browse the repository at this point in the history
  • Loading branch information
Darker935 committed Jun 17, 2024
1 parent 2c43c6d commit d4a8da2
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import it.auties.whatsapp.api.ClientType;
import it.auties.whatsapp.model.info.ChatMessageInfo;
import it.auties.whatsapp.model.jid.Jid;
import it.auties.whatsapp.model.jid.JidServer;
import it.auties.whatsapp.util.Bytes;

import java.nio.ByteBuffer;
Expand Down Expand Up @@ -79,7 +80,8 @@ public static String randomIdV2(Jid jid, ClientType... clientType) {
private static String randomWebKeyId(Jid jid) {
try {
var random = new Random();
var meUser = "%s@%s".formatted(jid.user(), "@c.us");
var meJid = Objects.requireNonNullElse(jid, Jid.ofServer(JidServer.WHATSAPP));
var meUser = "%s@%s".formatted(meJid.user(), "@c.us");
long timeSeconds = Instant.now().getEpochSecond();
byte[] randomBytes = new byte[16];
random.nextBytes(randomBytes);
Expand All @@ -93,15 +95,16 @@ private static String randomWebKeyId(Jid jid) {
System.arraycopy(hash, 0, truncatedHash, 0, 9);
return "3EB0" + HexFormat.of().formatHex(truncatedHash).toUpperCase();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
return randomId();
}
}

private static String randomMobileKeyId(Jid jid) {
try {
var random = new Random();
var meJid = Objects.requireNonNullElse(jid, Jid.ofServer(JidServer.WHATSAPP));
var meUser = meJid.toSimpleJid().toString().getBytes();
var messageDigest = MessageDigest.getInstance("MD5");
var meUser = jid.toSimpleJid().toString().getBytes();
long timeMillis = System.currentTimeMillis();
byte[] bArr = new byte[8];
for (int i = 7; i >= 0; i--) {
Expand All @@ -126,7 +129,7 @@ private static String randomMobileKeyId(Jid jid) {
}
return new String(cArr2);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
return randomId();
}
}

Expand Down

0 comments on commit d4a8da2

Please sign in to comment.