Skip to content

Commit

Permalink
Fix deletion of credentials.json file
Browse files Browse the repository at this point in the history
  • Loading branch information
Louuke committed Aug 16, 2021
1 parent 4ac2b7c commit e5c1915
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 14 deletions.
12 changes: 12 additions & 0 deletions .idea/WhatsJava.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified build/classes/java/main/icu/jnet/whatsjava/Main$1.class
Binary file not shown.
Binary file modified build/classes/java/main/icu/jnet/whatsjava/Main.class
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static WAMessage[] messageToObject(JsonArray childrenArray) {

// Convert json message of the type "chat" into WAChat
private static WAChat[] chatToObject(JsonArray childrenArray) {
WAChat[] WAChats = new WAChat[childrenArray.size()];
WAChat[] waChats = new WAChat[childrenArray.size()];

for(int i = 0; i < childrenArray.size(); i++) {
JsonObject chatAttributes = childrenArray.get(i).getAsJsonArray().get(1).getAsJsonObject();
Expand All @@ -103,10 +103,10 @@ private static WAChat[] chatToObject(JsonArray childrenArray) {
long lastInteraction = chatAttributes.get("t").getAsLong();
boolean muted = chatAttributes.get("mute").getAsBoolean();

WAChats[i] = new WAChat(jid, name, unreadMessages, lastInteraction, muted);
waChats[i] = new WAChat(jid, name, unreadMessages, lastInteraction, muted);
}
storedWAChats = WAChats;
return WAChats;
storedWAChats = waChats;
return waChats;
}

// Convert json message of the type "contacts" into WebChat
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/icu/jnet/whatsjava/whatsapp/WABackendConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,15 @@ private int initOrRestoreSession() {

String challengeResponse = sendText(challengeRequest);
loginStatus = Utils.encodeValidJson(challengeResponse).get("status").getAsInt();

// An error occurred during authentication
// Old session data is invalid so it gets deleted
if(loginStatus != 200) {
AuthCredentials.deletePreviousSession(credentialsPath);
disconnect();
}
} else {
loginStatus = Utils.encodeValidJson(restoreResponse).get("status").getAsInt();
}
// An error occurred during authentication
// Old session data is invalid so it gets deleted
if(loginStatus != 200) {
AuthCredentials.deletePreviousSession(credentialsPath);
disconnect();
}
}
listener.onReceiveLoginResponse(loginStatus);
return loginStatus;
Expand Down Expand Up @@ -216,14 +215,14 @@ private String waitForTextMessage(String... search) {
}
}
}
Utils.waitMill(100);
Utils.waitMill(50);
}
}
return null;
}

@Override
public void onTextMessage(WebSocket websocket, String message) throws Exception {
public void onTextMessage(WebSocket websocket, String message) {
textMessageBuffer.add(message);
}

Expand All @@ -232,7 +231,7 @@ public void onBinaryMessage(WebSocket websocket, byte[] binaryMessage) throws Ex
// Decrypt binary message
byte[] decrypted = BinaryEncryption.decrypt(binaryMessage, auth.getEncryptionKeyPair());

// Use protobuf to make messages of the type "message" human readable
// Use protobuf to make messages of the type "message" human-readable
String decoded = new BinaryDecoder().decode(decrypted);
textMessageBuffer.add(decoded);
WAMessageParser.jsonToObjects(decoded);
Expand Down

0 comments on commit e5c1915

Please sign in to comment.