Search in sources :

Example 1 with TypingEvent

use of com.yellowmessenger.sdk.events.TypingEvent 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)1 TypingEvent (com.yellowmessenger.sdk.events.TypingEvent)1 ChatResponse (com.yellowmessenger.sdk.models.ChatResponse)1 ChatMessage (com.yellowmessenger.sdk.models.db.ChatMessage)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SmackException (org.jivesoftware.smack.SmackException)1 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)1