Search in sources :

Example 1 with MessageReceivedEvent

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);
    }
}
Also used : ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) MessageReceivedEvent(com.yellowmessenger.sdk.events.MessageReceivedEvent)

Example 2 with MessageReceivedEvent

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);
    }
}
Also used : TypingEvent(com.yellowmessenger.sdk.events.TypingEvent) ChatMessage(com.yellowmessenger.sdk.models.db.ChatMessage) ChatResponse(com.yellowmessenger.sdk.models.ChatResponse) SmackException(org.jivesoftware.smack.SmackException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageReceivedEvent(com.yellowmessenger.sdk.events.MessageReceivedEvent)

Aggregations

MessageReceivedEvent (com.yellowmessenger.sdk.events.MessageReceivedEvent)2 ChatMessage (com.yellowmessenger.sdk.models.db.ChatMessage)2 TypingEvent (com.yellowmessenger.sdk.events.TypingEvent)1 ChatResponse (com.yellowmessenger.sdk.models.ChatResponse)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SmackException (org.jivesoftware.smack.SmackException)1 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)1