Skip to content

Commit

Permalink
Handling edited messages + fixing protocolType() exception
Browse files Browse the repository at this point in the history
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)
`
  • Loading branch information
Darker935 authored Apr 20, 2024
1 parent b4bc48d commit 6c23b31
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/it/auties/whatsapp/socket/MessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6c23b31

Please sign in to comment.