Skip to content

Commit bb14437

Browse files
committed
Fix conversion error if attribute is null
1 parent d096062 commit bb14437

File tree

8 files changed

+48
-45
lines changed

8 files changed

+48
-45
lines changed

build.gradle

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
// Apply the java-library plugin to add support for Java Library
33
id 'java-library'
4-
id "com.github.johnrengelman.shadow" version "6.0.0"
4+
id "com.github.johnrengelman.shadow" version "6.1.0"
55
}
66

77
jar {
@@ -11,32 +11,33 @@ jar {
1111
}
1212

1313
repositories {
14-
// Use jcenter for resolving dependencies.
15-
// You can declare any Maven/Ivy/file repository here.
16-
jcenter()
14+
mavenCentral()
1715
}
1816

1917
dependencies {
2018
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
2119
implementation 'com.google.guava:guava:28.0-jre'
2220

21+
// https://mvnrepository.com/artifact/com.google.code.gson/gson
2322
implementation 'com.google.code.gson:gson:2.8.6'
2423

2524
// https://mvnrepository.com/artifact/commons-codec/commons-codec
26-
compile group: 'commons-codec', name: 'commons-codec', version: '1.14'
25+
implementation group: 'commons-codec', name: 'commons-codec', version: '1.14'
2726

2827
// https://mvnrepository.com/artifact/commons-io/commons-io
29-
compile group: 'commons-io', name: 'commons-io', version: '2.7'
28+
implementation group: 'commons-io', name: 'commons-io', version: '2.7'
3029

3130
// https://mvnrepository.com/artifact/org.whispersystems/curve25519-java
32-
compile group: 'org.whispersystems', name: 'curve25519-java', version: '0.5.0'
31+
implementation group: 'org.whispersystems', name: 'curve25519-java', version: '0.5.0'
3332

3433
// https://mvnrepository.com/artifact/com.google.zxing/core
35-
compile group: 'com.google.zxing', name: 'core', version: '3.4.0'
36-
37-
compile group: 'at.favre.lib', name: 'hkdf', version: '1.0.2'
34+
implementation group: 'com.google.zxing', name: 'core', version: '3.4.0'
35+
36+
// https://mvnrepository.com/artifact/at.favre.lib/hkdf
37+
implementation group: 'at.favre.lib', name: 'hkdf', version: '1.0.2'
3838

39-
compile 'com.neovisionaries:nv-websocket-client:2.10'
39+
// https://mvnrepository.com/artifact/com.neovisionaries/nv-websocket-client
40+
implementation group: 'com.neovisionaries', name: 'nv-websocket-client', version: '2.10'
4041

4142
// Use JUnit test framework
4243
testImplementation 'junit:junit:4.12'
388 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
141 Bytes
Binary file not shown.
1 Byte
Binary file not shown.

src/main/java/icu/jnet/whatsjava/WAClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public WAClient(String authCredentialsPath) {
6464
public WAClient openConnection() {
6565
try {
6666
disconnect();
67-
67+
6868
WebSocketFactory factory = new WebSocketFactory();
6969
ws = factory.createSocket(WHATSAPP_SERVER);
7070
ws.addHeader("Origin", HEADER_ORIGIN);

src/main/java/icu/jnet/whatsjava/WAMessage.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,41 +55,43 @@ private static String generateMessageID() {
5555
*/
5656
public static Object[] jsonToObject(String json) {
5757
JsonArray node = JsonParser.parseString(json).getAsJsonArray();
58-
59-
JsonObject attributes = node.get(1).getAsJsonObject();
60-
// Attributes key values
61-
Set<String> keys = attributes.keySet();
62-
63-
// Contains node content
64-
JsonArray childrenArray = node.get(2).getAsJsonArray();
65-
6658
Object[] objects = null;
67-
68-
if(keys.contains("add")) { // Generic message
69-
objects = messageToObject(childrenArray);
70-
} else if(!keys.contains("duplicate") && keys.contains("type")) {
71-
72-
String typeValue = attributes.get("type").getAsString();
73-
74-
switch(typeValue) {
75-
case "message":
76-
// Also generic message but gets called as response of the loadConversation() method
77-
objects = messageToObject(childrenArray);
78-
break;
79-
case "chat":
80-
objects = chatToObject(childrenArray);
81-
break;
82-
case "contacts":
83-
objects = contactToObject(childrenArray);
84-
break;
85-
case "status":
86-
objects = statusToObject(childrenArray);
87-
break;
88-
case "emoji":
89-
objects = emojiToObject(childrenArray);
90-
break;
59+
60+
if(node.get(1) != null) {
61+
JsonObject attributes = node.get(1).getAsJsonObject();
62+
// Attributes key values
63+
Set<String> keys = attributes.keySet();
64+
65+
// Contains node content
66+
JsonArray childrenArray = node.get(2).getAsJsonArray();
67+
68+
if(keys.contains("add")) { // Generic message
69+
objects = messageToObject(childrenArray);
70+
} else if(!keys.contains("duplicate") && keys.contains("type")) {
71+
72+
String typeValue = attributes.get("type").getAsString();
73+
74+
switch(typeValue) {
75+
case "message":
76+
// Also generic message but gets called as response of the loadConversation() method
77+
objects = messageToObject(childrenArray);
78+
break;
79+
case "chat":
80+
objects = chatToObject(childrenArray);
81+
break;
82+
case "contacts":
83+
objects = contactToObject(childrenArray);
84+
break;
85+
case "status":
86+
objects = statusToObject(childrenArray);
87+
break;
88+
case "emoji":
89+
objects = emojiToObject(childrenArray);
90+
break;
91+
}
9192
}
9293
}
94+
9395
return objects;
9496
}
9597

src/main/java/icu/jnet/whatsjava/helper/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static String buildWebsocketJsonRequest(int requestType, String... conten
9191

9292
switch(requestType) {
9393
case RequestType.LOGIN:
94-
request = "[\"admin\",\"init\",[2,2117,5],[\"Ubuntu\",\"Firefox\",\"Unknown\"],\""
94+
request = "[\"admin\",\"init\",[2,2035,14],[\"Ubuntu\",\"Firefox\",\"Unknown\"],\""
9595
+ "" + content[0] + "\",true]";
9696
break;
9797
case RequestType.RESTORE_SESSION:

0 commit comments

Comments
 (0)