From 6c23b3110efcf4ad938427d2eabe95387ee294ce Mon Sep 17 00:00:00 2001 From: Quishot WADEV <70950705+Darker935@users.noreply.github.com> Date: Fri, 19 Apr 2024 22:46:08 -0300 Subject: [PATCH] Handling edited messages + fixing protocolType() exception Sometimes, when a verified BOT send a message to the host, after a time, the session starts to throw an exception, that says: `java.lang.NullPointerException: Cannot invoke "it.auties.whatsapp.model.message.server.ProtocolMessage$Type.ordinal()" because the return value of "it.auties.whatsapp.model.message.server.ProtocolMessage.protocolType()" is null at it.auties.whatsapp.socket.MessageHandler.handleProtocolMessage(MessageHandler.java:934) at it.auties.whatsapp.socket.MessageHandler.saveMessage(MessageHandler.java:901) at it.auties.whatsapp.socket.MessageHandler.decodeChatMessage(MessageHandler.java:806) at it.auties.whatsapp.socket.MessageHandler.lambda$decode$55(MessageHandler.java:618) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at it.auties.whatsapp.socket.MessageHandler.decode(MessageHandler.java:618) at it.auties.whatsapp.socket.SocketHandler.decodeMessage(SocketHandler.java:447) at it.auties.whatsapp.socket.StreamHandler.digest(StreamHandler.java:107) at it.auties.whatsapp.socket.SocketHandler.onMessage(SocketHandler.java:201) at it.auties.whatsapp.socket.SocketSession$WebSocketSession.notifyMessage(SocketSession.java:150) at it.auties.whatsapp.socket.SocketSession$WebSocketSession.onBinary(SocketSession.java:139) at it.auties.whatsapp.socket.SocketSession$WebSocketSession.onBinary(SocketSession.java:141) at it.auties.whatsapp.socket.SocketSession$WebSocketSession.onBinary(SocketSession.java:141) ` --- src/main/java/it/auties/whatsapp/socket/MessageHandler.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/auties/whatsapp/socket/MessageHandler.java b/src/main/java/it/auties/whatsapp/socket/MessageHandler.java index 0ab21b01..da8adbae 100644 --- a/src/main/java/it/auties/whatsapp/socket/MessageHandler.java +++ b/src/main/java/it/auties/whatsapp/socket/MessageHandler.java @@ -1076,10 +1076,12 @@ private void saveMessage(ChatMessageInfo info, boolean notify) { return; } if (info.message().hasCategory(MessageCategory.SERVER)) { - if (info.message().content() instanceof ProtocolMessage protocolMessage) { + if (!(info.message().content() instanceof ProtocolMessage protocolMessage)) return; + if (protocolMessage.protocolType() == null) return; + if (!protocolMessage.protocolType().equals(ProtocolMessage.Type.MESSAGE_EDIT)) { handleProtocolMessage(info, protocolMessage); + return; } - return; } var chat = info.chat()