Search in sources :

Example 1 with MqttMessageResponse

use of com.applozic.mobicomkit.feed.MqttMessageResponse in project Applozic-Android-SDK by AppLozic.

the class ApplozicMqttService method messageArrived.

@Override
public void messageArrived(final String s, final MqttMessage mqttMessage) throws Exception {
    Utils.printLog(context, TAG, "Received MQTT message: " + new String(mqttMessage.getPayload()));
    try {
        if (!TextUtils.isEmpty(s) && s.startsWith(TYPINGTOPIC)) {
            String[] typingResponse = mqttMessage.toString().split(",");
            String applicationId = typingResponse[0];
            String userId = User.getDecodedUserId(typingResponse[1]);
            String isTypingStatus = typingResponse[2];
            BroadcastService.sendUpdateTypingBroadcast(context, BroadcastService.INTENT_ACTIONS.UPDATE_TYPING_STATUS.toString(), applicationId, userId, isTypingStatus);
        } else {
            Thread thread = new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        final MqttMessageResponse mqttMessageResponse;
                        String messageDataString = null;
                        if (!TextUtils.isEmpty(MobiComUserPreference.getInstance(context).getUserEncryptionKey()) && !TextUtils.isEmpty(s) && s.startsWith(MQTT_ENCRYPTION_TOPIC)) {
                            if (!TextUtils.isEmpty(MobiComUserPreference.getInstance(context).getUserEncryptionKey())) {
                                messageDataString = EncryptionUtils.decrypt(MobiComUserPreference.getInstance(context).getUserEncryptionKey(), mqttMessage.toString());
                            }
                            if (TextUtils.isEmpty(messageDataString.trim())) {
                                return;
                            }
                            mqttMessageResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(messageDataString, MqttMessageResponse.class);
                        } else {
                            messageDataString = mqttMessage.toString();
                            mqttMessageResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(messageDataString, MqttMessageResponse.class);
                        }
                        if (mqttMessageResponse != null) {
                            if (MobiComPushReceiver.processPushNotificationId(mqttMessageResponse.getId())) {
                                return;
                            }
                            final SyncCallService syncCallService = SyncCallService.getInstance(context);
                            MobiComPushReceiver.addPushNotificationId(mqttMessageResponse.getId());
                            AlEventManager.getInstance().postMqttEventData(mqttMessageResponse);
                            Utils.printLog(context, TAG, "MQTT message type: " + mqttMessageResponse.getType());
                            if (NOTIFICATION_TYPE.MESSAGE_RECEIVED.getValue().equals(mqttMessageResponse.getType()) || "MESSAGE_RECEIVED".equals(mqttMessageResponse.getType())) {
                                GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageDataString, GcmMessageResponse.class);
                                if (messageResponse == null) {
                                    return;
                                }
                                Message message = messageResponse.getMessage();
                                if (message.getGroupId() != null) {
                                    Channel channel = ChannelService.getInstance(context).getChannelByChannelKey(message.getGroupId());
                                    if (channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
                                        if (!MobiComUserPreference.getInstance(context).getDeviceKeyString().equals(message.getDeviceKeyString())) {
                                            syncCallService.syncMessages(message.getKeyString(), message);
                                        }
                                    } else {
                                        if (message.isGroupDeleteAction()) {
                                            syncCallService.deleteChannelConversationThread(message.getGroupId());
                                            BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), null, message.getGroupId(), "success");
                                        }
                                        syncCallService.syncMessages(null);
                                    }
                                } else {
                                    syncCallService.syncMessages(null);
                                }
                            }
                            if (NOTIFICATION_TYPE.MESSAGE_DELIVERED.getValue().equals(mqttMessageResponse.getType()) || "MT_MESSAGE_DELIVERED".equals(mqttMessageResponse.getType())) {
                                String[] splitKeyString = (mqttMessageResponse.getMessage()).toString().split(",");
                                String keyString = splitKeyString[0];
                                // String userId = splitKeyString[1];
                                syncCallService.updateDeliveryStatus(keyString);
                            }
                            if (NOTIFICATION_TYPE.MESSAGE_DELIVERED_AND_READ.getValue().equals(mqttMessageResponse.getType()) || "MT_MESSAGE_DELIVERED_READ".equals(mqttMessageResponse.getType())) {
                                String[] splitKeyString = (mqttMessageResponse.getMessage()).toString().split(",");
                                String keyString = splitKeyString[0];
                                syncCallService.updateReadStatus(keyString);
                            }
                            if (NOTIFICATION_TYPE.CONVERSATION_DELIVERED_AND_READ.getValue().equals(mqttMessageResponse.getType())) {
                                String contactId = mqttMessageResponse.getMessage().toString();
                                syncCallService.updateDeliveryStatusForContact(contactId, true);
                            }
                            if (NOTIFICATION_TYPE.CONVERSATION_READ.getValue().equals(mqttMessageResponse.getType())) {
                                syncCallService.updateConversationReadStatus(mqttMessageResponse.getMessage().toString(), false);
                            }
                            if (NOTIFICATION_TYPE.GROUP_CONVERSATION_READ.getValue().equals(mqttMessageResponse.getType())) {
                                InstantMessageResponse instantMessageResponse = (InstantMessageResponse) GsonUtils.getObjectFromJson(messageDataString, InstantMessageResponse.class);
                                syncCallService.updateConversationReadStatus(instantMessageResponse.getMessage(), true);
                            }
                            if (NOTIFICATION_TYPE.USER_CONNECTED.getValue().equals(mqttMessageResponse.getType())) {
                                syncCallService.updateConnectedStatus(mqttMessageResponse.getMessage().toString(), new Date(), true);
                            }
                            if (NOTIFICATION_TYPE.USER_DISCONNECTED.getValue().equals(mqttMessageResponse.getType())) {
                                // disconnect comes with timestamp, ranjeet,1449866097000
                                String[] parts = mqttMessageResponse.getMessage().toString().split(",");
                                String userId = parts[0];
                                Date lastSeenAt = new Date();
                                if (parts.length >= 2 && !parts[1].equals("null")) {
                                    lastSeenAt = new Date(Long.parseLong(parts[1]));
                                }
                                syncCallService.updateConnectedStatus(userId, lastSeenAt, false);
                            }
                            if (NOTIFICATION_TYPE.CONVERSATION_DELETED.getValue().equals(mqttMessageResponse.getType())) {
                                syncCallService.deleteConversationThread(mqttMessageResponse.getMessage().toString());
                                BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), mqttMessageResponse.getMessage().toString(), 0, "success");
                            }
                            if (NOTIFICATION_TYPE.GROUP_CONVERSATION_DELETED.getValue().equals(mqttMessageResponse.getType())) {
                                InstantMessageResponse instantMessageResponse = (InstantMessageResponse) GsonUtils.getObjectFromJson(messageDataString, InstantMessageResponse.class);
                                syncCallService.deleteChannelConversationThread(instantMessageResponse.getMessage());
                                BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), null, Integer.valueOf(instantMessageResponse.getMessage()), "success");
                            }
                            if (NOTIFICATION_TYPE.MESSAGE_DELETED.getValue().equals(mqttMessageResponse.getType())) {
                                String messageKey = mqttMessageResponse.getMessage().toString().split(",")[0];
                                syncCallService.deleteMessage(messageKey);
                                BroadcastService.sendMessageDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_MESSAGE.toString(), messageKey, null);
                            }
                            if (NOTIFICATION_TYPE.MESSAGE_SENT.getValue().equals(mqttMessageResponse.getType())) {
                                GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageDataString, GcmMessageResponse.class);
                                Message sentMessageSync = messageResponse.getMessage();
                                syncCallService.syncMessages(sentMessageSync.getKeyString());
                            }
                            if (NOTIFICATION_TYPE.USER_BLOCKED.getValue().equals(mqttMessageResponse.getType()) || NOTIFICATION_TYPE.USER_UN_BLOCKED.getValue().equals(mqttMessageResponse.getType())) {
                                syncCallService.syncBlockUsers();
                            }
                            if (NOTIFICATION_TYPE.USER_DETAIL_CHANGED.getValue().equals(mqttMessageResponse.getType()) || NOTIFICATION_TYPE.USER_DELETE_NOTIFICATION.getValue().equals(mqttMessageResponse.getType())) {
                                String userId = mqttMessageResponse.getMessage().toString();
                                syncCallService.syncUserDetail(userId);
                                if (isMqttResponseForLoggedInUserDelete(context, mqttMessageResponse)) {
                                    syncCallService.processLoggedUserDelete();
                                }
                            }
                            if (NOTIFICATION_TYPE.MESSAGE_METADATA_UPDATE.getValue().equals(mqttMessageResponse.getType())) {
                                try {
                                    GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageDataString, GcmMessageResponse.class);
                                    String keyString = messageResponse.getMessage().getKeyString();
                                    Message messageObject = messageResponse.getMessage();
                                    syncCallService.syncMessageMetadataUpdate(keyString, false, messageObject);
                                } catch (Exception e) {
                                    Utils.printLog(context, TAG, e.getMessage());
                                }
                            }
                            if (NOTIFICATION_TYPE.USER_MUTE_NOTIFICATION.getValue().equals(mqttMessageResponse.getType())) {
                                try {
                                    InstantMessageResponse response = (InstantMessageResponse) GsonUtils.getObjectFromJson(messageDataString, InstantMessageResponse.class);
                                    if (response.getMessage() != null) {
                                        String muteFlag = String.valueOf(response.getMessage().charAt(response.getMessage().length() - 1));
                                        if ("1".equals(muteFlag)) {
                                            syncCallService.syncMutedUserList(false, null);
                                        } else if ("0".equals(muteFlag)) {
                                            String userId = response.getMessage().substring(0, response.getMessage().length() - 2);
                                            syncCallService.syncMutedUserList(false, userId);
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            if (NOTIFICATION_TYPE.MUTE_NOTIFICATIONS.getValue().equals(mqttMessageResponse.getType())) {
                                try {
                                    GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageDataString, GcmMessageResponse.class);
                                    if (messageResponse.getMessage() != null && messageResponse.getMessage().getMessage() != null) {
                                        long notificationAfterTime = Long.parseLong(messageResponse.getMessage().getMessage());
                                        ALSpecificSettings.getInstance(context).setNotificationAfterTime(notificationAfterTime);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            if (NOTIFICATION_TYPE.GROUP_MUTE_NOTIFICATION.getValue().equals(mqttMessageResponse.getType())) {
                                try {
                                    InstantMessageResponse response = (InstantMessageResponse) GsonUtils.getObjectFromJson(messageDataString, InstantMessageResponse.class);
                                    if (!TextUtils.isEmpty(response.getMessage())) {
                                        String[] parts = response.getMessage().split(":");
                                        if (parts.length > 0) {
                                            Integer groupId = Integer.parseInt(parts[0]);
                                            if (parts.length == 2) {
                                                Long notificationMuteTillTime = Long.parseLong(parts[1]);
                                                ChannelService.getInstance(context).updateNotificationAfterTime(groupId, notificationMuteTillTime);
                                                BroadcastService.sendUpdateGroupMuteForGroupId(context, groupId, BroadcastService.INTENT_ACTIONS.GROUP_MUTE.toString());
                                            }
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            if (NOTIFICATION_TYPE.ACTIVATED.getValue().equals(mqttMessageResponse.getType())) {
                                BroadcastService.sendUserActivatedBroadcast(context, AlMessageEvent.ActionType.USER_ACTIVATED);
                            }
                            if (NOTIFICATION_TYPE.DEACTIVATED.getValue().equals(mqttMessageResponse.getType())) {
                                BroadcastService.sendUserActivatedBroadcast(context, AlMessageEvent.ActionType.USER_DEACTIVATED);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
            thread.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) Message(com.applozic.mobicomkit.api.conversation.Message) MqttMessageResponse(com.applozic.mobicomkit.feed.MqttMessageResponse) GcmMessageResponse(com.applozic.mobicomkit.feed.GcmMessageResponse) Channel(com.applozic.mobicommons.people.channel.Channel) InstantMessageResponse(com.applozic.mobicomkit.feed.InstantMessageResponse) Date(java.util.Date) MqttException(org.eclipse.paho.client.mqttv3.MqttException) SyncCallService(com.applozic.mobicomkit.api.conversation.SyncCallService)

Example 2 with MqttMessageResponse

use of com.applozic.mobicomkit.feed.MqttMessageResponse in project Applozic-Android-SDK by AppLozic.

the class MobiComPushReceiver method processMessage.

// the MqttMessageResponse objects used in this class are not actual MQTT responses, but just their data model is used
public static void processMessage(@NonNull Context context, @Nullable Bundle bundle, @Nullable Map<String, String> data) {
    try {
        String payloadForDelivered = null, userConnected = null, userDisconnected = null, payloadDeliveredAndRead = null, messageKey = null, messageSent = null, deleteConversationForContact = null, deleteConversationForChannel = null, deleteMessage = null, conversationReadResponse = null, userBlockedResponse = null, userUnBlockedResponse = null, conversationReadForContact = null, conversationReadForChannel = null, conversationReadForSingleMessage = null, userDetailChanged = null, userDeleteNotification = null, messageMetadataUpdate = null, mutedUserListResponse = null, contactSync = null, muteAllNotificationResponse = null, groupMuteNotificationResponse = null, userActivated = null, userDeactivated = null;
        SyncCallService syncCallService = SyncCallService.getInstance(context);
        if (bundle != null) {
            deleteConversationForContact = bundle.getString(notificationKeyList.get(5));
            deleteMessage = bundle.getString(notificationKeyList.get(4));
            payloadForDelivered = bundle.getString(notificationKeyList.get(3));
            userConnected = bundle.getString(notificationKeyList.get(10));
            userDisconnected = bundle.getString(notificationKeyList.get(11));
            payloadDeliveredAndRead = bundle.getString(notificationKeyList.get(7));
            messageSent = bundle.getString(notificationKeyList.get(1));
            messageKey = bundle.getString(notificationKeyList.get(0));
            conversationReadResponse = bundle.getString(notificationKeyList.get(9));
            userBlockedResponse = bundle.getString(notificationKeyList.get(15));
            userUnBlockedResponse = bundle.getString(notificationKeyList.get(16));
            conversationReadForContact = bundle.getString(notificationKeyList.get(8));
            conversationReadForChannel = bundle.getString(notificationKeyList.get(20));
            deleteConversationForChannel = bundle.getString(notificationKeyList.get(22));
            userDetailChanged = bundle.getString(notificationKeyList.get(29));
            userDeleteNotification = bundle.getString(notificationKeyList.get(31));
            messageMetadataUpdate = bundle.getString(notificationKeyList.get(30));
            mutedUserListResponse = bundle.getString(notificationKeyList.get(32));
            muteAllNotificationResponse = bundle.getString(notificationKeyList.get(33));
            groupMuteNotificationResponse = bundle.getString(notificationKeyList.get(34));
            userActivated = bundle.getString(notificationKeyList.get(17));
            userDeactivated = bundle.getString(notificationKeyList.get(18));
        } else if (data != null) {
            deleteConversationForContact = data.get(notificationKeyList.get(5));
            deleteMessage = data.get(notificationKeyList.get(4));
            payloadForDelivered = data.get(notificationKeyList.get(3));
            userConnected = data.get(notificationKeyList.get(10));
            userDisconnected = data.get(notificationKeyList.get(11));
            payloadDeliveredAndRead = data.get(notificationKeyList.get(7));
            messageSent = data.get(notificationKeyList.get(1));
            messageKey = data.get(notificationKeyList.get(0));
            conversationReadResponse = data.get(notificationKeyList.get(9));
            userBlockedResponse = data.get(notificationKeyList.get(15));
            userUnBlockedResponse = data.get(notificationKeyList.get(16));
            conversationReadForContact = data.get(notificationKeyList.get(8));
            conversationReadForChannel = data.get(notificationKeyList.get(20));
            deleteConversationForChannel = data.get(notificationKeyList.get(22));
            userDetailChanged = data.get(notificationKeyList.get(29));
            userDeleteNotification = data.get(notificationKeyList.get(31));
            messageMetadataUpdate = data.get(notificationKeyList.get(30));
            mutedUserListResponse = data.get(notificationKeyList.get(32));
            muteAllNotificationResponse = data.get(notificationKeyList.get(33));
            groupMuteNotificationResponse = data.get(notificationKeyList.get(34));
            userActivated = data.get(notificationKeyList.get(17));
            userDeactivated = data.get(notificationKeyList.get(18));
        }
        if (!TextUtils.isEmpty(payloadForDelivered)) {
            MqttMessageResponse messageResponseForDelivered = (MqttMessageResponse) GsonUtils.getObjectFromJson(payloadForDelivered, MqttMessageResponse.class);
            if (processPushNotificationId(messageResponseForDelivered.getId())) {
                return;
            }
            addPushNotificationId(messageResponseForDelivered.getId());
            String[] splitKeyString = (messageResponseForDelivered.getMessage()).toString().split(",");
            String keyString = splitKeyString[0];
            // String userId = splitKeyString[1];
            syncCallService.updateDeliveryStatus(keyString);
        }
        if (!TextUtils.isEmpty(payloadDeliveredAndRead)) {
            MqttMessageResponse messageResponseForDeliveredAndRead = (MqttMessageResponse) GsonUtils.getObjectFromJson(payloadDeliveredAndRead, MqttMessageResponse.class);
            if (processPushNotificationId(messageResponseForDeliveredAndRead.getId())) {
                return;
            }
            addPushNotificationId(messageResponseForDeliveredAndRead.getId());
            String[] splitKeyString = (messageResponseForDeliveredAndRead.getMessage()).toString().split(",");
            String keyString = splitKeyString[0];
            // String userId = splitKeyString[1];
            syncCallService.updateReadStatus(keyString);
        }
        if (!TextUtils.isEmpty(deleteConversationForContact)) {
            MqttMessageResponse deleteConversationResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(deleteConversationForContact, MqttMessageResponse.class);
            if (processPushNotificationId(deleteConversationResponse.getId())) {
                return;
            }
            addPushNotificationId(deleteConversationResponse.getId());
            MobiComConversationService conversationService = new MobiComConversationService(context);
            conversationService.deleteConversationFromDevice(deleteConversationResponse.getMessage().toString());
            BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), deleteConversationResponse.getMessage().toString(), 0, "success");
        }
        if (!TextUtils.isEmpty(deleteConversationForChannel)) {
            InstantMessageResponse instantMessageResponse = (InstantMessageResponse) GsonUtils.getObjectFromJson(deleteConversationForChannel, InstantMessageResponse.class);
            if (processPushNotificationId(instantMessageResponse.getId())) {
                return;
            }
            addPushNotificationId(instantMessageResponse.getId());
            syncCallService.deleteChannelConversationThread(instantMessageResponse.getMessage());
            BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), null, Integer.valueOf(instantMessageResponse.getMessage()), "success");
        }
        if (!TextUtils.isEmpty(userConnected)) {
            MqttMessageResponse userConnectedResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(userConnected, MqttMessageResponse.class);
            if (processPushNotificationId(userConnectedResponse.getId())) {
                return;
            }
            addPushNotificationId(userConnectedResponse.getId());
            syncCallService.updateConnectedStatus(userConnectedResponse.getMessage().toString(), new Date(), true);
        }
        if (!TextUtils.isEmpty(userDisconnected)) {
            MqttMessageResponse userDisconnectedResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(userDisconnected, MqttMessageResponse.class);
            if (processPushNotificationId(userDisconnectedResponse.getId())) {
                return;
            }
            addPushNotificationId(userDisconnectedResponse.getId());
            String[] parts = userDisconnectedResponse.getMessage().toString().split(",");
            String userId = parts[0];
            Date lastSeenAt = new Date();
            if (parts.length >= 2 && !parts[1].equals("null")) {
                lastSeenAt = new Date(Long.valueOf(parts[1]));
            }
            syncCallService.updateConnectedStatus(userId, lastSeenAt, false);
        }
        if (!TextUtils.isEmpty(deleteMessage)) {
            MqttMessageResponse deleteSingleMessageResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(deleteMessage, MqttMessageResponse.class);
            if (processPushNotificationId(deleteSingleMessageResponse.getId())) {
                return;
            }
            addPushNotificationId(deleteSingleMessageResponse.getId());
            String deleteMessageKeyAndUserId = deleteSingleMessageResponse.getMessage().toString();
            // String contactNumbers = deleteMessageKeyAndUserId.split(",").length > 1 ? deleteMessageKeyAndUserId.split(",")[1] : null;
            syncCallService.deleteMessage(deleteMessageKeyAndUserId.split(",")[0]);
        }
        if (!TextUtils.isEmpty(messageSent)) {
            GcmMessageResponse syncSentMessageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageSent, GcmMessageResponse.class);
            if (processPushNotificationId(syncSentMessageResponse.getId())) {
                return;
            }
            addPushNotificationId(syncSentMessageResponse.getId());
            syncCallService.syncMessages(null);
        }
        GcmMessageResponse syncMessageResponse = null;
        if (!TextUtils.isEmpty(messageKey)) {
            syncMessageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageKey, GcmMessageResponse.class);
            if (processPushNotificationId(syncMessageResponse.getId())) {
                return;
            }
            addPushNotificationId(syncMessageResponse.getId());
            Message messageObj = syncMessageResponse.getMessage();
            if (!TextUtils.isEmpty(messageObj.getKeyString())) {
                syncCallService.syncMessages(messageObj.getKeyString());
                if (messageObj.getGroupId() != null && messageObj.isGroupDeleteAction()) {
                    syncCallService.deleteChannelConversationThread(messageObj.getGroupId());
                    BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), null, messageObj.getGroupId(), "success");
                }
            } else {
                syncCallService.syncMessages(null);
            }
        }
        if (!TextUtils.isEmpty(conversationReadResponse)) {
            MqttMessageResponse updateDeliveryStatusForContactResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(conversationReadResponse, MqttMessageResponse.class);
            if (notificationKeyList.get(9).equals(updateDeliveryStatusForContactResponse.getType())) {
                if (processPushNotificationId(updateDeliveryStatusForContactResponse.getId())) {
                    return;
                }
                addPushNotificationId(updateDeliveryStatusForContactResponse.getId());
                syncCallService.updateDeliveryStatusForContact(updateDeliveryStatusForContactResponse.getMessage().toString(), true);
            }
        }
        if (!TextUtils.isEmpty(userBlockedResponse)) {
            MqttMessageResponse syncUserBlock = (MqttMessageResponse) GsonUtils.getObjectFromJson(userBlockedResponse, MqttMessageResponse.class);
            if (processPushNotificationId(syncUserBlock.getId())) {
                return;
            }
            addPushNotificationId(syncUserBlock.getId());
            SyncCallService.getInstance(context).syncBlockUsers();
        }
        if (!TextUtils.isEmpty(userUnBlockedResponse)) {
            MqttMessageResponse syncUserUnBlock = (MqttMessageResponse) GsonUtils.getObjectFromJson(userUnBlockedResponse, MqttMessageResponse.class);
            if (processPushNotificationId(syncUserUnBlock.getId())) {
                return;
            }
            addPushNotificationId(syncUserUnBlock.getId());
            SyncCallService.getInstance(context).syncBlockUsers();
        }
        if (!TextUtils.isEmpty(conversationReadForContact)) {
            MqttMessageResponse conversationReadForContactResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(conversationReadForContact, MqttMessageResponse.class);
            if (processPushNotificationId(conversationReadForContactResponse.getId())) {
                return;
            }
            addPushNotificationId(conversationReadForContactResponse.getId());
            syncCallService.updateConversationReadStatus(conversationReadForContactResponse.getMessage().toString(), false);
        }
        if (!TextUtils.isEmpty(conversationReadForChannel)) {
            InstantMessageResponse conversationReadForChannelResponse = (InstantMessageResponse) GsonUtils.getObjectFromJson(conversationReadForChannel, InstantMessageResponse.class);
            if (processPushNotificationId(conversationReadForChannelResponse.getId())) {
                return;
            }
            addPushNotificationId(conversationReadForChannelResponse.getId());
            syncCallService.updateConversationReadStatus(conversationReadForChannelResponse.getMessage(), true);
        }
        if (!TextUtils.isEmpty(userDetailChanged) || !TextUtils.isEmpty(userDeleteNotification)) {
            MqttMessageResponse response = null;
            if (!TextUtils.isEmpty(userDetailChanged)) {
                response = (MqttMessageResponse) GsonUtils.getObjectFromJson(userDetailChanged, MqttMessageResponse.class);
            } else if (!TextUtils.isEmpty(userDeleteNotification)) {
                response = (MqttMessageResponse) GsonUtils.getObjectFromJson(userDeleteNotification, MqttMessageResponse.class);
            }
            if (processPushNotificationId(response.getId())) {
                return;
            }
            addPushNotificationId(response.getId());
            String userId = response.getMessage().toString();
            syncCallService.syncUserDetail(userId);
            if (isPushMessageForLoggedUserDelete(context, userDeleteNotification, response)) {
                syncCallService.processLoggedUserDelete();
            }
        }
        if (!TextUtils.isEmpty(messageMetadataUpdate)) {
            String keyString = null;
            String id = null;
            try {
                GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageMetadataUpdate, GcmMessageResponse.class);
                keyString = messageResponse.getMessage().getKeyString();
                Message messageObject = messageResponse.getMessage();
                id = messageResponse.getId();
                if (processPushNotificationId(id)) {
                    return;
                }
                addPushNotificationId(id);
                syncCallService.syncMessageMetadataUpdate(keyString, true, messageObject);
            } catch (Exception e) {
                Utils.printLog(context, TAG, e.getMessage());
            }
        }
        if (!TextUtils.isEmpty(mutedUserListResponse)) {
            try {
                InstantMessageResponse response = (InstantMessageResponse) GsonUtils.getObjectFromJson(mutedUserListResponse, InstantMessageResponse.class);
                if (processPushNotificationId(response.getId())) {
                    return;
                }
                addPushNotificationId(response.getId());
                if (response.getMessage() != null) {
                    String muteFlag = String.valueOf(response.getMessage().charAt(response.getMessage().length() - 1));
                    if ("1".equals(muteFlag)) {
                        syncCallService.syncMutedUserList(true, null);
                    } else if ("0".equals(muteFlag)) {
                        String userId = response.getMessage().substring(0, response.getMessage().length() - 2);
                        syncCallService.syncMutedUserList(true, userId);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (!TextUtils.isEmpty(muteAllNotificationResponse)) {
            try {
                GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(muteAllNotificationResponse, GcmMessageResponse.class);
                if (processPushNotificationId(messageResponse.getId())) {
                    return;
                }
                addPushNotificationId(messageResponse.getId());
                if (messageResponse.getMessage() != null && messageResponse.getMessage().getMessage() != null) {
                    long notificationAfterTime = Long.parseLong(messageResponse.getMessage().getMessage());
                    ALSpecificSettings.getInstance(context).setNotificationAfterTime(notificationAfterTime);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (!TextUtils.isEmpty(groupMuteNotificationResponse)) {
            try {
                InstantMessageResponse response = (InstantMessageResponse) GsonUtils.getObjectFromJson(groupMuteNotificationResponse, InstantMessageResponse.class);
                if (processPushNotificationId(response.getId())) {
                    return;
                }
                addPushNotificationId(response.getId());
                if (!TextUtils.isEmpty(response.getMessage())) {
                    String[] parts = response.getMessage().split(":");
                    if (parts.length > 0) {
                        Integer groupId = Integer.parseInt(parts[0]);
                        if (parts.length == 2) {
                            Long notificationMuteTillTime = Long.parseLong(parts[1]);
                            ChannelService.getInstance(context).updateNotificationAfterTime(groupId, notificationMuteTillTime);
                            BroadcastService.sendUpdateGroupMuteForGroupId(context, groupId, BroadcastService.INTENT_ACTIONS.GROUP_MUTE.toString());
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (!TextUtils.isEmpty(userActivated)) {
            BroadcastService.sendUserActivatedBroadcast(context, AlMessageEvent.ActionType.USER_ACTIVATED);
        }
        if (!TextUtils.isEmpty(userDeactivated)) {
            BroadcastService.sendUserActivatedBroadcast(context, AlMessageEvent.ActionType.USER_DEACTIVATED);
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) MqttMessageResponse(com.applozic.mobicomkit.feed.MqttMessageResponse) GcmMessageResponse(com.applozic.mobicomkit.feed.GcmMessageResponse) InstantMessageResponse(com.applozic.mobicomkit.feed.InstantMessageResponse) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) Date(java.util.Date) SyncCallService(com.applozic.mobicomkit.api.conversation.SyncCallService)

Aggregations

Message (com.applozic.mobicomkit.api.conversation.Message)2 SyncCallService (com.applozic.mobicomkit.api.conversation.SyncCallService)2 GcmMessageResponse (com.applozic.mobicomkit.feed.GcmMessageResponse)2 InstantMessageResponse (com.applozic.mobicomkit.feed.InstantMessageResponse)2 MqttMessageResponse (com.applozic.mobicomkit.feed.MqttMessageResponse)2 Date (java.util.Date)2 MobiComConversationService (com.applozic.mobicomkit.api.conversation.MobiComConversationService)1 Channel (com.applozic.mobicommons.people.channel.Channel)1 MqttException (org.eclipse.paho.client.mqttv3.MqttException)1 MqttMessage (org.eclipse.paho.client.mqttv3.MqttMessage)1