mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-01 20:10:39 +00:00
FIX: NullpointerException for messages without content in mqttHandler
This commit is contained in:
parent
055a8a421f
commit
92879048a1
2 changed files with 29 additions and 16 deletions
|
@ -80,7 +80,7 @@ public class MqttJsonMessage {
|
||||||
|
|
||||||
if (envelope != null) {
|
if (envelope != null) {
|
||||||
result.putPOJO("envelope", new JsonMessageEnvelope(envelope, content));
|
result.putPOJO("envelope", new JsonMessageEnvelope(envelope, content));
|
||||||
message.setSubTopic(findSubTopic(content));
|
message.setSubTopic(findSubTopic(envelope, content));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
message.setContent(jsonProcessor.writeValueAsString(result));
|
message.setContent(jsonProcessor.writeValueAsString(result));
|
||||||
|
@ -102,22 +102,37 @@ public class MqttJsonMessage {
|
||||||
* Finds the designated type of the message and defines the subtopic for the mqtt broker.
|
* Finds the designated type of the message and defines the subtopic for the mqtt broker.
|
||||||
*
|
*
|
||||||
* Possible subtopics: data, synq, call, typinginfo, receipt, other
|
* Possible subtopics: data, synq, call, typinginfo, receipt, other
|
||||||
|
*
|
||||||
|
* @param envelope
|
||||||
* @param content
|
* @param content
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static String findSubTopic(final SignalServiceContent content) {
|
private static String findSubTopic(final SignalServiceEnvelope envelope, final SignalServiceContent content) {
|
||||||
if (content.getDataMessage().isPresent()) {
|
if(content !=null) {
|
||||||
return SUBTOPIC_DATA;
|
if (content.getDataMessage().isPresent()) {
|
||||||
} else if (content.getSyncMessage().isPresent()) {
|
return SUBTOPIC_DATA;
|
||||||
return SUBTOPIC_SYNC;
|
} else if (content.getSyncMessage().isPresent()) {
|
||||||
} else if (content.getCallMessage().isPresent()) {
|
return SUBTOPIC_SYNC;
|
||||||
return SUBTOPIC_CALL;
|
} else if (content.getCallMessage().isPresent()) {
|
||||||
} else if (content.getTypingMessage().isPresent()) {
|
return SUBTOPIC_CALL;
|
||||||
return SUBTOPIC_TYPING_INFO;
|
} else if (content.getTypingMessage().isPresent()) {
|
||||||
} else if (content.getReceiptMessage().isPresent()) {
|
return SUBTOPIC_TYPING_INFO;
|
||||||
return SUBTOPIC_RECEIPT;
|
} else if (content.getReceiptMessage().isPresent()) {
|
||||||
} else {
|
return SUBTOPIC_RECEIPT;
|
||||||
return SUBTOPIC_OTHER;
|
} else {
|
||||||
|
return SUBTOPIC_OTHER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(envelope.isReceipt())
|
||||||
|
{
|
||||||
|
return SUBTOPIC_RECEIPT;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return SUBTOPIC_OTHER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,6 @@ public class MqttReceiveMessageHandler implements Manager.ReceiveMessageHandler
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(final SignalServiceEnvelope envelope, final SignalServiceContent decryptedContent, final Throwable e) {
|
public void handleMessage(final SignalServiceEnvelope envelope, final SignalServiceContent decryptedContent, final Throwable e) {
|
||||||
System.out.println("Message Received from " + decryptedContent.getSender());
|
|
||||||
|
|
||||||
MqttJsonMessage msg = MqttJsonMessage.build(envelope, decryptedContent, e);
|
MqttJsonMessage msg = MqttJsonMessage.build(envelope, decryptedContent, e);
|
||||||
String topic = DEFAULT_TOPIC + stripIllegalTopicCharacters(manager.getUsername() + "/" + msg.getSubTopic());
|
String topic = DEFAULT_TOPIC + stripIllegalTopicCharacters(manager.getUsername() + "/" + msg.getSubTopic());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue