Skip to content

Commit da4131e

Browse files
committed
Fixed a bug which prevented chats or contacts from being loaded
1 parent d04f67f commit da4131e

File tree

9 files changed

+26
-81
lines changed

9 files changed

+26
-81
lines changed
0 Bytes
Binary file not shown.
1019 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.jar

57.8 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

gradlew

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ esac
8282

8383
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
8484

85+
8586
# Determine the Java command to use to start the JVM.
8687
if [ -n "$JAVA_HOME" ] ; then
8788
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -129,6 +130,7 @@ fi
129130
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130131
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131132
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133+
132134
JAVACMD=`cygpath --unix "$JAVACMD"`
133135

134136
# We build the pattern for arguments to be converted via cygpath

gradlew.bat

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
2929
set APP_BASE_NAME=%~n0
3030
set APP_HOME=%DIRNAME%
3131

32+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
33+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34+
3235
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
3336
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
3437

@@ -37,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
3740

3841
set JAVA_EXE=java.exe
3942
%JAVA_EXE% -version >NUL 2>&1
40-
if "%ERRORLEVEL%" == "0" goto init
43+
if "%ERRORLEVEL%" == "0" goto execute
4144

4245
echo.
4346
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -51,7 +54,7 @@ goto fail
5154
set JAVA_HOME=%JAVA_HOME:"=%
5255
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5356

54-
if exist "%JAVA_EXE%" goto init
57+
if exist "%JAVA_EXE%" goto execute
5558

5659
echo.
5760
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@@ -61,28 +64,14 @@ echo location of your Java installation.
6164

6265
goto fail
6366

64-
:init
65-
@rem Get command-line arguments, handling Windows variants
66-
67-
if not "%OS%" == "Windows_NT" goto win9xME_args
68-
69-
:win9xME_args
70-
@rem Slurp the command line arguments.
71-
set CMD_LINE_ARGS=
72-
set _SKIP=2
73-
74-
:win9xME_args_slurp
75-
if "x%~1" == "x" goto execute
76-
77-
set CMD_LINE_ARGS=%*
78-
7967
:execute
8068
@rem Setup the command line
8169

8270
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
8371

72+
8473
@rem Execute Gradle
85-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
74+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
8675

8776
:end
8877
@rem End local scope for the variables with windows NT shell

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

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/main/java/icu/jnet/whatsjava/messages/WAMessageParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ public static Object[] jsonToObjects(String json) {
2525
if(json != null) {
2626
JsonArray node = JsonParser.parseString(json).getAsJsonArray();
2727

28-
if(!node.get(1).isJsonNull() && !node.get(2).isJsonNull()) {
28+
if(!node.get(1).isJsonNull()) {
2929
JsonObject attributes = node.get(1).getAsJsonObject();
3030
// Attributes key values
3131
Set<String> keys = attributes.keySet();
3232

33-
// Contains node content
34-
JsonArray childrenArray = node.get(2).getAsJsonArray();
35-
3633
if (keys.contains("type")) {
3734
String typeValue = attributes.get("type").getAsString();
3835

36+
// Contains node content
37+
JsonArray childrenArray = node.get(2).isJsonArray() ? node.get(2).getAsJsonArray() : null;
38+
3939
switch (typeValue) {
4040
case "message":
4141
objects = messageToObject(childrenArray);

src/main/java/icu/jnet/whatsjava/whatsapp/WABackendConnector.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
import icu.jnet.whatsjava.listener.ClientActionInterface;
1111
import icu.jnet.whatsjava.listener.ClientActionListener;
1212
import icu.jnet.whatsjava.messages.WAMessageParser;
13-
import org.apache.commons.codec.DecoderException;
14-
import org.apache.commons.codec.binary.Hex;
1513

1614
import java.io.IOException;
15+
import java.util.ArrayList;
1716
import java.util.Base64;
17+
import java.util.List;
1818

1919
public class WABackendConnector extends WebSocketAdapter implements PayloadGenerator {
2020

@@ -34,11 +34,8 @@ public class WABackendConnector extends WebSocketAdapter implements PayloadGener
3434
// WebSocket object that is used for communication with the WhatsApp web server.
3535
protected WebSocket ws;
3636

37-
// Last received messages from onTextMessage callback
38-
private final TimeLimitedList<String> onTextMessageBuffer = new TimeLimitedList<>();
39-
// Last received messages from onBinaryMessage callback
40-
private final TimeLimitedList<String> onBinaryMessageBuffer = new TimeLimitedList<>();
41-
37+
// Last received messages from onTextMessage and onBinaryMessage callback
38+
private final List<String> textMessageBuffer = new ArrayList<>();
4239

4340
public WABackendConnector() {
4441
this.auth = AuthCredentials.loadAuthCredentials(credentialsPath);
@@ -209,19 +206,15 @@ String sendBinary(String json, byte[] waTags, String... search) {
209206
* @return
210207
*/
211208
private String waitForTextMessage(String... search) {
209+
textMessageBuffer.clear();
212210
if(search.length > 0) {
213211
for(int i = 0; i < 200; i++) {
214212
for(String s : search) {
215-
for(String message : onTextMessageBuffer) {
213+
for(String message : textMessageBuffer) {
216214
if(message.contains(s)) {
217215
return message;
218216
}
219217
}
220-
for(String message : onBinaryMessageBuffer) {
221-
if (message.contains(s)) {
222-
return message;
223-
}
224-
}
225218
}
226219
Utils.waitMill(100);
227220
}
@@ -231,7 +224,7 @@ private String waitForTextMessage(String... search) {
231224

232225
@Override
233226
public void onTextMessage(WebSocket websocket, String message) throws Exception {
234-
onTextMessageBuffer.add(message);
227+
textMessageBuffer.add(message);
235228
}
236229

237230
@Override
@@ -241,7 +234,7 @@ public void onBinaryMessage(WebSocket websocket, byte[] binaryMessage) throws Ex
241234

242235
// Use protobuf to make messages of the type "message" human readable
243236
String decoded = new BinaryDecoder().decode(decrypted);
244-
onBinaryMessageBuffer.add(decoded);
237+
textMessageBuffer.add(decoded);
245238
WAMessageParser.jsonToObjects(decoded);
246239
}
247240

0 commit comments

Comments
 (0)