Search in sources :

Example 36 with Channel

use of com.applozic.mobicommons.people.channel.Channel 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 37 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class MobiComMessageService method processInstantMessage.

public synchronized void processInstantMessage(Message message) {
    if (!message.hasAttachment()) {
        if (!baseContactService.isContactPresent(message.getContactIds())) {
            userService.processUserDetails(message.getContactIds());
        }
        Channel channel = ChannelService.getInstance(context).getChannelInfo(message.getGroupId());
        if (channel == null) {
            return;
        }
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
    }
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel)

Example 38 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class ApplozicMqttIntentService method onHandleWork.

@Override
protected void onHandleWork(@NonNull Intent intent) {
    if (intent == null) {
        return;
    }
    boolean subscribe = intent.getBooleanExtra(SUBSCRIBE, false);
    if (subscribe) {
        ApplozicMqttService.getInstance(getApplicationContext()).subscribe();
    }
    Contact contact = (Contact) intent.getSerializableExtra(CONTACT);
    Channel channel = (Channel) intent.getSerializableExtra(CHANNEL);
    boolean subscribeToTyping = intent.getBooleanExtra(SUBSCRIBE_TO_TYPING, false);
    if (subscribeToTyping) {
        ApplozicMqttService.getInstance(getApplicationContext()).subscribeToTypingTopic(channel);
        if (channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
            ApplozicMqttService.getInstance(getApplicationContext()).subscribeToOpenGroupTopic(channel);
        }
        return;
    }
    boolean unSubscribeToTyping = intent.getBooleanExtra(UN_SUBSCRIBE_TO_TYPING, false);
    if (unSubscribeToTyping) {
        ApplozicMqttService.getInstance(getApplicationContext()).unSubscribeToTypingTopic(channel);
        if (channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
            ApplozicMqttService.getInstance(getApplicationContext()).unSubscribeToOpenGroupTopic(channel);
        }
        return;
    }
    String userKeyString = intent.getStringExtra(USER_KEY_STRING);
    String deviceKeyString = intent.getStringExtra(DEVICE_KEY_STRING);
    if (!TextUtils.isEmpty(userKeyString) && !TextUtils.isEmpty(deviceKeyString)) {
        ApplozicMqttService.getInstance(getApplicationContext()).disconnectPublish(userKeyString, deviceKeyString, "0");
    }
    boolean connectedStatus = intent.getBooleanExtra(CONNECTED_PUBLISH, false);
    if (connectedStatus) {
        ApplozicMqttService.getInstance(getApplicationContext()).connectPublish(MobiComUserPreference.getInstance(getApplicationContext()).getSuUserKeyString(), MobiComUserPreference.getInstance(getApplicationContext()).getDeviceKeyString(), "1");
    }
    if (contact != null) {
        boolean stop = intent.getBooleanExtra(STOP_TYPING, false);
        if (stop) {
            ApplozicMqttService.getInstance(getApplicationContext()).typingStopped(contact, null);
        }
    }
    if (contact != null && (contact.isBlocked() || contact.isBlockedBy())) {
        return;
    }
    if (contact != null || channel != null) {
        boolean typing = intent.getBooleanExtra(TYPING, false);
        if (typing) {
            ApplozicMqttService.getInstance(getApplicationContext()).typingStarted(contact, channel);
        } else {
            ApplozicMqttService.getInstance(getApplicationContext()).typingStopped(contact, channel);
        }
    }
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 39 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class ConversationReadService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null) {
        return;
    }
    MessageClientService messageClientService = new MessageClientService(getApplicationContext());
    Integer unreadCount = intent.getIntExtra(UNREAD_COUNT, 0);
    boolean singleMessageRead = intent.getBooleanExtra(SINGLE_MESSAGE_READ, false);
    Contact contact = (Contact) intent.getSerializableExtra(CONTACT);
    Channel channel = (Channel) intent.getSerializableExtra(CHANNEL);
    if (unreadCount != 0) {
        Intent readIntent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(readIntent);
    }
    if (unreadCount != 0 || singleMessageRead) {
        messageClientService.updateReadStatus(contact, channel);
    }
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) Intent(android.content.Intent) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 40 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class ChannelService method processChannelList.

public synchronized void processChannelList(List<ChannelFeed> channelFeedList) {
    if (channelFeedList != null && channelFeedList.size() > 0) {
        for (ChannelFeed channelFeed : channelFeedList) {
            Set<String> memberUserIds = channelFeed.getMembersName();
            Set<String> userIds = new HashSet<>();
            Channel channel = getChannel(channelFeed);
            if (channelDatabaseService.isChannelPresent(channel.getKey())) {
                channelDatabaseService.updateChannel(channel);
                channelDatabaseService.deleteChannelUserMappers(channel.getKey());
            } else {
                channelDatabaseService.addChannel(channel);
            }
            if (memberUserIds != null && memberUserIds.size() > 0) {
                for (String userId : memberUserIds) {
                    ChannelUserMapper channelUserMapper = new ChannelUserMapper(channelFeed.getId(), userId);
                    channelDatabaseService.addChannelUserMapper(channelUserMapper);
                    if (!baseContactService.isContactExists(userId)) {
                        userIds.add(userId);
                    }
                }
                if (userIds != null && userIds.size() > 0) {
                    userService.processUserDetailsByUserIds(userIds);
                }
            }
            if (channelFeed.getGroupUsers() != null && channelFeed.getGroupUsers().size() > 0) {
                for (ChannelUsersFeed channelUsers : channelFeed.getGroupUsers()) {
                    if (channelUsers.getRole() != null) {
                        channelDatabaseService.updateRoleInChannelUserMapper(channelFeed.getId(), channelUsers.getUserId(), channelUsers.getRole());
                    }
                }
            }
        }
    }
}
Also used : ChannelUsersFeed(com.applozic.mobicomkit.feed.ChannelUsersFeed) Channel(com.applozic.mobicommons.people.channel.Channel) SyncChannelFeed(com.applozic.mobicomkit.sync.SyncChannelFeed) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) HashSet(java.util.HashSet)

Aggregations

Channel (com.applozic.mobicommons.people.channel.Channel)70 Contact (com.applozic.mobicommons.people.contact.Contact)26 Intent (android.content.Intent)12 ChannelFeed (com.applozic.mobicomkit.feed.ChannelFeed)10 ArrayList (java.util.ArrayList)10 Message (com.applozic.mobicomkit.api.conversation.Message)8 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)7 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)7 SyncChannelFeed (com.applozic.mobicomkit.sync.SyncChannelFeed)7 ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)7 NonNull (androidx.annotation.NonNull)6 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)6 Context (android.content.Context)4 Cursor (android.database.Cursor)4 Bitmap (android.graphics.Bitmap)4 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)4 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)4 ChannelUsersFeed (com.applozic.mobicomkit.feed.ChannelUsersFeed)4 Conversation (com.applozic.mobicommons.people.channel.Conversation)4 JSONException (org.json.JSONException)4