Skip to content

Commit d064d52

Browse files
committed
Add clearMessage method
- It is now possible to delete a message for yourself - WhatsApp Web Version got bumped up to 2,2035,14
1 parent 7225c25 commit d064d52

File tree

13 files changed

+14
-5
lines changed

13 files changed

+14
-5
lines changed
630 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
1 Byte
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

build/libs/WhatsJava-all.jar

256 Bytes
Binary file not shown.

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,20 @@ private void confirmLogin() {
152152
listener.onReceiveLoginResponse(200);
153153
}
154154

155-
// Generic text message
155+
// Send generic text message
156156
public void sendMessage(String remoteJid, String messageContent) {
157157
String json = WAMessage.buildJson(remoteJid, messageContent, true, Instant.now().getEpochSecond());
158158
sendBinary(json, WAMetric.message, WAFlag.ignore);
159159
}
160160

161+
// Delete the send message only for you
162+
public void clearMessage(String remoteJid, String messageId, boolean owner) {
163+
String modTag = Math.round(Math.random() * 1000000) + "";
164+
sendBinary("[\"action\", {epoch: \"" + Utils.getMessageCount() + "\", type: \"set\"}, "
165+
+ "[[\"chat\", {jid: \"" + remoteJid + "\", modify_tag: \"" + modTag +"\", type: \"clear\"}, "
166+
+ "[[\"item\", {owner: \"" + owner + "\", index: \"" + messageId +"\"}, null]]]]]", WAMetric.group, WAFlag.ignore);
167+
}
168+
161169
// Load the last x messages of a direct chat or group
162170
public void loadConversation(String remoteJid, int messageCount) {
163171
sendBinary("[\"query\", {type: \"message\", epoch: \"" + Utils.getMessageCount() + "\", jid: \"" + remoteJid + "\", "

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public static Object[] jsonToObject(String json) {
5757
JsonArray node = JsonParser.parseString(json).getAsJsonArray();
5858

5959
JsonObject attributes = node.get(1).getAsJsonObject();
60+
// Attributes key values
6061
Set<String> keys = attributes.keySet();
6162

6263
// Contains node content

src/main/java/icu/jnet/whatsjava/encryption/BinaryDecoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private int readInt(int n, boolean littleEndian) {
8787
}
8888

8989
private int readInt20() {
90-
checkEOS(3);
90+
checkEOS(3);
9191

9292
int a = next() & 0xff;
9393
int b = next() & 0xff;
@@ -112,8 +112,8 @@ private String readPacked8(int tag) {
112112
}
113113

114114
if (startByte >> 7 != 0) {
115-
value = value.substring(0, value.length() - 1);
116-
}
115+
value = value.substring(0, value.length() - 1);
116+
}
117117
return value;
118118
}
119119

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

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

9494
switch(requestType) {
9595
case RequestType.LOGIN:
96-
request = "[\"admin\",\"init\",[2,2029,4],[\"Ubuntu\",\"Firefox\",\"Unknown\"],\""
96+
request = "[\"admin\",\"init\",[2,2035,14],[\"Ubuntu\",\"Firefox\",\"Unknown\"],\""
9797
+ "" + content[0] + "\",true]";
9898
break;
9999
case RequestType.RESTORE_SESSION:

0 commit comments

Comments
 (0)