use of com.yellowmessenger.sdk.events.MessageReceivedEvent in project yellowmessenger-sdk by yellowmessenger.
the class XMPPService method processXMPPMessage.
public void processXMPPMessage(String sender, String name, String message) {
ChatMessage chatMessage = new ChatMessage(sender, message, name, false);
chatMessage.save();
if (XMPPService.this.username != null && sender.toLowerCase().equals(XMPPService.this.username.toLowerCase())) {
Log.d("Event posting: ", message);
EventBus.getDefault().post(new MessageReceivedEvent(chatMessage));
} else {
notifyMessage(sender, name, message);
}
}
use of com.yellowmessenger.sdk.events.MessageReceivedEvent in project yellowmessenger-sdk by yellowmessenger.
the class XMPPService method processMessage.
private void processMessage(String sender, String message) {
String name = PreferencesManager.getInstance(getApplicationContext()).getBusinessName(sender);
ChatResponse chatResponse = null;
try {
chatResponse = gson.fromJson(message, ChatResponse.class);
} catch (Exception e) {
// e.printStackTrace();
}
if (chatResponse != null) {
if (chatResponse.getTyping() != null) {
if (XMPPService.this.username != null && sender.toLowerCase().equals(XMPPService.this.username.toLowerCase())) {
Log.d("Event posting: ", message);
EventBus.getDefault().post(new TypingEvent(sender, chatResponse.getTyping()));
}
}
if (chatResponse.isValid()) {
ChatMessage chatMessage = new ChatMessage(sender, message, sender, false);
chatMessage.save();
if (XMPPService.this.username != null && sender.toLowerCase().equals(XMPPService.this.username.toLowerCase())) {
Log.d("Event posting: ", message);
EventBus.getDefault().post(new MessageReceivedEvent(chatMessage));
}
}
if (chatResponse.getTyping() == null && !(XMPPService.this.username != null && sender.toLowerCase().equals(XMPPService.this.username.toLowerCase()))) {
notifyMessage(sender, name, "...");
}
} else {
processXMPPMessage(sender, name, message);
}
}
Aggregations