Search in sources :

Example 1 with VideoCallNotificationHelper

use of com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper in project Applozic-Android-SDK by AppLozic.

the class MobiComMessageService method processMessage.

// Cleanup: private, MessageSendTimer is not used
public Message processMessage(final Message messageToProcess, String tofield, int index) {
    if (Message.MetaDataType.HIDDEN.getValue().equals(messageToProcess.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
        MessageWorker.enqueueWork(context, messageToProcess, null, null);
        return null;
    } else if (Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(messageToProcess.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
        BroadcastService.sendNotificationBroadcast(context, messageToProcess, index);
        MessageWorker.enqueueWork(context, messageToProcess, null, null);
        return null;
    }
    Message message = prepareMessage(messageToProcess, tofield);
    // download contacts in advance.
    if (message.getGroupId() != null) {
        Channel channel = ChannelService.getInstance(context).getChannelInfo(message.getGroupId());
        if (channel == null) {
            return null;
        }
    }
    if (message.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
        fileClientService.loadContactsvCard(message);
    }
    try {
        List<String> messageKeys = new ArrayList<>();
        if (message.getMetadata() != null && message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()) != null && !messageDatabaseService.isMessagePresent(message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()))) {
            messageKeys.add(message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
        }
        if (messageKeys != null && messageKeys.size() > 0) {
            Message[] replyMessageList = conversationService.getMessageListByKeyList(messageKeys);
            if (replyMessageList != null) {
                Message replyMessage = replyMessageList[0];
                if (replyMessage != null) {
                    if (replyMessage.hasAttachment() && !(replyMessage.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                        conversationService.setFilePathifExist(replyMessage);
                    }
                    if (replyMessage.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                        fileClientService.loadContactsvCard(replyMessage);
                    }
                    replyMessage.setReplyMessage(Message.ReplyMessage.HIDE_MESSAGE.getValue());
                    messageDatabaseService.createMessage(replyMessage);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (message.getType().equals(Message.MessageType.MT_INBOX.getValue())) {
        addMTMessage(message, index);
    } else if (message.getType().equals(Message.MessageType.MT_OUTBOX.getValue())) {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        messageDatabaseService.createMessage(message);
        if (!message.getCurrentId().equals(BroadcastService.currentUserId)) {
            MobiComUserPreference.getInstance(context).setNewMessageFlag(true);
        }
        if (message.isVideoNotificationMessage()) {
            Utils.printLog(context, TAG, "Got notifications for Video call...");
            VideoCallNotificationHelper helper = new VideoCallNotificationHelper(context);
            helper.handleVideoCallNotificationMessages(message);
        }
    }
    Utils.printLog(context, TAG, "processing message: " + message);
    return message;
}
Also used : PersonalizedMessage(com.applozic.mobicommons.personalization.PersonalizedMessage) VideoCallNotificationHelper(com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper) Channel(com.applozic.mobicommons.people.channel.Channel) ArrayList(java.util.ArrayList)

Example 2 with VideoCallNotificationHelper

use of com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper in project Applozic-Android-SDK by AppLozic.

the class MobiComMessageService method addMTMessage.

public Contact addMTMessage(Message message) {
    MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
    Contact receiverContact = null;
    message.processContactIds(context);
    String currentId = message.getCurrentId();
    if (message.getGroupId() == null) {
        receiverContact = baseContactService.getContactById(message.getContactIds());
    }
    if (message.getMessage() != null && PersonalizedMessage.isPersonalized(message.getMessage())) {
        message.setMessage(PersonalizedMessage.prepareMessageFromTemplate(message.getMessage(), receiverContact));
    }
    messageDatabaseService.createMessage(message);
    // Check if we are........container is already opened...don't send broadcast
    boolean isContainerOpened;
    if (message.getConversationId() != null && BroadcastService.isContextBasedChatEnabled()) {
        if (BroadcastService.currentConversationId == null) {
            BroadcastService.currentConversationId = message.getConversationId();
        }
        isContainerOpened = (currentId.equals(BroadcastService.currentUserId) && message.getConversationId().equals(BroadcastService.currentConversationId));
    } else {
        isContainerOpened = currentId.equals(BroadcastService.currentUserId);
    }
    if (message.isVideoNotificationMessage()) {
        Utils.printLog(context, TAG, "Got notifications for Video call...");
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        VideoCallNotificationHelper helper = new VideoCallNotificationHelper(context);
        helper.handleVideoCallNotificationMessages(message);
    } else if (message.isVideoCallMessage()) {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        VideoCallNotificationHelper.buildVideoCallNotification(context, message);
    } else if (!isContainerOpened) {
        if (message.isConsideredForCount()) {
            if (message.getTo() != null && message.getGroupId() == null) {
                messageDatabaseService.updateContactUnreadCount(message.getTo());
                BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
                Contact contact = new ContactDatabase(context).getContactById(message.getTo());
                if (contact != null && !contact.isNotificationMuted()) {
                    sendNotification(message);
                }
            }
            if (message.getGroupId() != null && !Message.GroupMessageMetaData.FALSE.getValue().equals(message.getMetaDataValueForKey(Message.GroupMessageMetaData.KEY.getValue()))) {
                if (!Message.ContentType.CHANNEL_CUSTOM_MESSAGE.getValue().equals(message.getContentType())) {
                    messageDatabaseService.updateChannelUnreadCount(message.getGroupId());
                }
                BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
                Channel currentChannel = ChannelService.getInstance(context).getChannelInfo(message.getGroupId());
                if (currentChannel != null && !currentChannel.isNotificationMuted()) {
                    sendNotification(message);
                }
            }
            MobiComUserPreference.getInstance(context).setNewMessageFlag(true);
        } else {
            BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        }
    } else {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
    }
    Utils.printLog(context, TAG, "Updating delivery status: " + message.getPairedMessageKeyString() + ", " + userPreferences.getUserId() + ", " + userPreferences.getContactNumber());
    messageClientService.updateDeliveryStatus(message.getPairedMessageKeyString(), userPreferences.getUserId(), userPreferences.getContactNumber());
    return receiverContact;
}
Also used : VideoCallNotificationHelper(com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Channel(com.applozic.mobicommons.people.channel.Channel) ContactDatabase(com.applozic.mobicomkit.contact.database.ContactDatabase) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 3 with VideoCallNotificationHelper

use of com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper in project Applozic-Android-SDK by AppLozic.

the class MobiComMessageService method processMessage.

public Message processMessage(final Message messageToProcess, String tofield) {
    try {
        if (!TextUtils.isEmpty(ApplozicClient.getInstance(context).getMessageMetaDataServiceName())) {
            Class serviceName = Class.forName(ApplozicClient.getInstance(context).getMessageMetaDataServiceName());
            Intent intentService = new Intent(context, serviceName);
            if (Message.MetaDataType.HIDDEN.getValue().equals(messageToProcess.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                intentService.putExtra(MobiComKitConstants.MESSAGE, messageToProcess);
                intentService.putExtra(MobiComKitConstants.HIDDEN, true);
                MessageIntentService.enqueueWork(context, intentService, null);
                return null;
            } else if (Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(messageToProcess.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                BroadcastService.sendNotificationBroadcast(context, messageToProcess);
                intentService.putExtra(MobiComKitConstants.MESSAGE, messageToProcess);
                intentService.putExtra(MobiComKitConstants.PUSH_NOTIFICATION, true);
                MessageIntentService.enqueueWork(context, intentService, null);
                return null;
            }
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    Message message = prepareMessage(messageToProcess, tofield);
    // download contacts in advance.
    if (message.getGroupId() != null) {
        Channel channel = ChannelService.getInstance(context).getChannelInfo(message.getGroupId());
        if (channel == null) {
            return null;
        }
    }
    if (message.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
        fileClientService.loadContactsvCard(message);
    }
    try {
        List<String> messageKeys = new ArrayList<>();
        if (message.getMetadata() != null && message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()) != null && !messageDatabaseService.isMessagePresent(message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()))) {
            messageKeys.add(message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
        }
        if (messageKeys != null && messageKeys.size() > 0) {
            Message[] replyMessageList = conversationService.getMessageListByKeyList(messageKeys);
            if (replyMessageList != null) {
                Message replyMessage = replyMessageList[0];
                if (replyMessage != null) {
                    if (replyMessage.hasAttachment() && !(replyMessage.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                        conversationService.setFilePathifExist(replyMessage);
                    }
                    if (replyMessage.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                        fileClientService.loadContactsvCard(replyMessage);
                    }
                    replyMessage.setReplyMessage(Message.ReplyMessage.HIDE_MESSAGE.getValue());
                    messageDatabaseService.createMessage(replyMessage);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (message.getType().equals(Message.MessageType.MT_INBOX.getValue())) {
        addMTMessage(message);
    } else if (message.getType().equals(Message.MessageType.MT_OUTBOX.getValue())) {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        messageDatabaseService.createMessage(message);
        if (!message.getCurrentId().equals(BroadcastService.currentUserId)) {
            MobiComUserPreference.getInstance(context).setNewMessageFlag(true);
        }
        if (message.isVideoNotificationMessage()) {
            Utils.printLog(context, TAG, "Got notifications for Video call...");
            VideoCallNotificationHelper helper = new VideoCallNotificationHelper(context);
            helper.handleVideoCallNotificationMessages(message);
        }
    }
    Utils.printLog(context, TAG, "processing message: " + message);
    return message;
}
Also used : PersonalizedMessage(com.applozic.mobicommons.personalization.PersonalizedMessage) VideoCallNotificationHelper(com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper) Channel(com.applozic.mobicommons.people.channel.Channel) ArrayList(java.util.ArrayList) Intent(android.content.Intent) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with VideoCallNotificationHelper

use of com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper in project Applozic-Android-SDK by AppLozic.

the class MobiComMessageService method addMTMessage.

// Cleanup: private
public Contact addMTMessage(Message message, int index) {
    MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
    Contact receiverContact = null;
    message.processContactIds(context);
    String currentId = message.getCurrentId();
    if (message.getGroupId() == null) {
        receiverContact = baseContactService.getContactById(message.getContactIds());
    }
    if (message.getMessage() != null && PersonalizedMessage.isPersonalized(message.getMessage()) && receiverContact != null) {
        message.setMessage(PersonalizedMessage.prepareMessageFromTemplate(message.getMessage(), receiverContact));
    }
    if (isHideActionMessage && message.isActionMessage()) {
        message.setHidden(true);
    }
    messageDatabaseService.createMessage(message);
    // Check if we are........container is already opened...don't send broadcast
    boolean isContainerOpened;
    if (message.getConversationId() != null && BroadcastService.isContextBasedChatEnabled()) {
        if (BroadcastService.currentConversationId == null) {
            BroadcastService.currentConversationId = message.getConversationId();
        }
        isContainerOpened = (currentId.equals(BroadcastService.currentUserId) && message.getConversationId().equals(BroadcastService.currentConversationId));
    } else {
        isContainerOpened = currentId.equals(BroadcastService.currentUserId);
    }
    if (message.isVideoNotificationMessage()) {
        Utils.printLog(context, TAG, "Got notifications for Video call...");
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        VideoCallNotificationHelper helper = new VideoCallNotificationHelper(context);
        helper.handleVideoCallNotificationMessages(message);
    } else if (message.isVideoCallMessage()) {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        VideoCallNotificationHelper.buildVideoCallNotification(context, message, index);
    } else if (!isContainerOpened) {
        if (message.isConsideredForCount() && !message.hasHideKey()) {
            if (message.getTo() != null && message.getGroupId() == null && !message.isHidden()) {
                messageDatabaseService.updateContactUnreadCount(message.getTo());
                BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
                Contact contact = new ContactDatabase(context).getContactById(message.getTo());
                if (contact != null && !contact.isNotificationMuted()) {
                    sendNotification(message, index);
                }
            }
            if (message.getGroupId() != null && !Message.GroupMessageMetaData.FALSE.getValue().equals(message.getMetaDataValueForKey(Message.GroupMessageMetaData.KEY.getValue()))) {
                if (!Message.ContentType.CHANNEL_CUSTOM_MESSAGE.getValue().equals(message.getContentType()) && !message.isHidden()) {
                    messageDatabaseService.updateChannelUnreadCount(message.getGroupId());
                }
                BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
                Channel currentChannel = ChannelService.getInstance(context).getChannelInfo(message.getGroupId());
                if (currentChannel != null && (!currentChannel.isNotificationMuted() || MentionHelper.isLoggedInUserMentionedInChannelMessage(context, message))) {
                    sendNotification(message, index);
                }
            }
            MobiComUserPreference.getInstance(context).setNewMessageFlag(true);
        } else {
            BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        }
    } else {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
    }
    return receiverContact;
}
Also used : VideoCallNotificationHelper(com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Channel(com.applozic.mobicommons.people.channel.Channel) ContactDatabase(com.applozic.mobicomkit.contact.database.ContactDatabase) Contact(com.applozic.mobicommons.people.contact.Contact)

Aggregations

VideoCallNotificationHelper (com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper)4 Channel (com.applozic.mobicommons.people.channel.Channel)4 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)2 ContactDatabase (com.applozic.mobicomkit.contact.database.ContactDatabase)2 Contact (com.applozic.mobicommons.people.contact.Contact)2 PersonalizedMessage (com.applozic.mobicommons.personalization.PersonalizedMessage)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 JSONException (org.json.JSONException)1