Search in sources :

Example 1 with UserDetail

use of com.applozic.mobicomkit.api.account.user.UserDetail in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationService method processUserDetails.

public void processUserDetails(UserDetail[] userDetails) {
    if (userDetails != null && userDetails.length > 0) {
        for (UserDetail userDetail : userDetails) {
            Contact contact = new Contact();
            contact.setUserId(userDetail.getUserId());
            contact.setContactNumber(userDetail.getPhoneNumber());
            contact.setConnected(userDetail.isConnected());
            contact.setFullName(userDetail.getDisplayName());
            contact.setLastSeenAt(userDetail.getLastSeenAtTime());
            contact.setStatus(userDetail.getStatusMessage());
            contact.setUnreadCount(userDetail.getUnreadCount());
            contact.setUserTypeId(userDetail.getUserTypeId());
            contact.setImageURL(userDetail.getImageLink());
            contact.setDeletedAtTime(userDetail.getDeletedAtTime());
            contact.setLastMessageAtTime(userDetail.getLastMessageAtTime());
            contact.setMetadata(userDetail.getMetadata());
            contact.setRoleType(userDetail.getRoleType());
            baseContactService.upsert(contact);
        }
    }
}
Also used : UserDetail(com.applozic.mobicomkit.api.account.user.UserDetail) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 2 with UserDetail

use of com.applozic.mobicomkit.api.account.user.UserDetail in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationService method processUserDetails.

private void processUserDetails(SyncUserDetailsResponse userDetailsResponse) {
    for (UserDetail userDetail : userDetailsResponse.getResponse()) {
        Contact newContact = baseContactService.getContactById(userDetail.getUserId());
        Contact contact = new Contact();
        contact.setUserId(userDetail.getUserId());
        contact.setContactNumber(userDetail.getPhoneNumber());
        contact.setStatus(userDetail.getStatusMessage());
        // contact.setApplicationId(); Todo: set the application id
        contact.setConnected(userDetail.isConnected());
        contact.setFullName(userDetail.getDisplayName());
        contact.setLastSeenAt(userDetail.getLastSeenAtTime());
        if (userDetail.getUnreadCount() != null) {
            contact.setUnreadCount(userDetail.getUnreadCount());
        }
        if (!TextUtils.isEmpty(userDetail.getImageLink())) {
            contact.setImageURL(userDetail.getImageLink());
        }
        contact.setUserTypeId(userDetail.getUserTypeId());
        contact.setDeletedAtTime(userDetail.getDeletedAtTime());
        contact.setRoleType(userDetail.getRoleType());
        contact.setMetadata(userDetail.getMetadata());
        contact.setLastMessageAtTime(userDetail.getLastMessageAtTime());
        if (newContact != null) {
            if (newContact.isConnected() != contact.isConnected()) {
                BroadcastService.sendUpdateLastSeenAtTimeBroadcast(context, BroadcastService.INTENT_ACTIONS.UPDATE_LAST_SEEN_AT_TIME.toString(), contact.getContactIds());
            }
        }
        baseContactService.upsert(contact);
    }
    MobiComUserPreference.getInstance(context).setLastSeenAtSyncTime(userDetailsResponse.getGeneratedAt());
}
Also used : UserDetail(com.applozic.mobicomkit.api.account.user.UserDetail) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 3 with UserDetail

use of com.applozic.mobicomkit.api.account.user.UserDetail in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationService method getMessages.

public synchronized List<Message> getMessages(Long startTime, Long endTime, Contact contact, Channel channel, Integer conversationId, boolean isSkipRead) {
    List<Message> messageList = new ArrayList<Message>();
    List<Message> cachedMessageList = messageDatabaseService.getMessages(startTime, endTime, contact, channel, conversationId);
    boolean isServerCallNotRequired = false;
    if (channel != null) {
        Channel newChannel = ChannelService.getInstance(context).getChannelByChannelKey(channel.getKey());
        isServerCallNotRequired = (newChannel != null && !Channel.GroupType.OPEN.getValue().equals(newChannel.getType()));
    } else if (contact != null) {
        isServerCallNotRequired = true;
    }
    if (isServerCallNotRequired && (!cachedMessageList.isEmpty() && (cachedMessageList.size() > 1 || wasServerCallDoneBefore(contact, channel, conversationId)) || (contact == null && channel == null && cachedMessageList.isEmpty() && wasServerCallDoneBefore(contact, channel, conversationId)))) {
        Utils.printLog(context, TAG, "cachedMessageList size is : " + cachedMessageList.size());
        return cachedMessageList;
    }
    String data;
    try {
        data = messageClientService.getMessages(contact, channel, startTime, endTime, conversationId, isSkipRead);
        Utils.printLog(context, TAG, "Received response from server for Messages: " + data);
    } catch (Exception ex) {
        ex.printStackTrace();
        return cachedMessageList;
    }
    if (data == null || TextUtils.isEmpty(data) || data.equals("UnAuthorized Access") || !data.contains("{")) {
        // Note: currently not supporting syncing old channel messages from server
        if (channel != null && channel.getKey() != null) {
            return cachedMessageList;
        }
        return cachedMessageList;
    }
    updateServerCallDoneStatus(contact, channel, conversationId);
    try {
        Gson gson = new GsonBuilder().registerTypeAdapterFactory(new ArrayAdapterFactory()).setExclusionStrategies(new AnnotationExclusionStrategy()).create();
        JsonParser parser = new JsonParser();
        JSONObject jsonObject = new JSONObject(data);
        String channelFeedResponse = "";
        String conversationPxyResponse = "";
        String element = parser.parse(data).getAsJsonObject().get("message").toString();
        String userDetailsElement = parser.parse(data).getAsJsonObject().get("userDetails").toString();
        if (!TextUtils.isEmpty(userDetailsElement)) {
            UserDetail[] userDetails = (UserDetail[]) GsonUtils.getObjectFromJson(userDetailsElement, UserDetail[].class);
            processUserDetails(userDetails);
        }
        if (jsonObject.has("groupFeeds")) {
            channelFeedResponse = parser.parse(data).getAsJsonObject().get("groupFeeds").toString();
            ChannelFeed[] channelFeeds = (ChannelFeed[]) GsonUtils.getObjectFromJson(channelFeedResponse, ChannelFeed[].class);
            ChannelService.getInstance(context).processChannelFeedList(channelFeeds, false);
            if (channel != null && !isServerCallNotRequired) {
                BroadcastService.sendUpdate(context, BroadcastService.INTENT_ACTIONS.UPDATE_TITLE_SUBTITLE.toString());
            }
        }
        if (jsonObject.has("conversationPxys")) {
            conversationPxyResponse = parser.parse(data).getAsJsonObject().get("conversationPxys").toString();
            Conversation[] conversationPxy = (Conversation[]) GsonUtils.getObjectFromJson(conversationPxyResponse, Conversation[].class);
            ConversationService.getInstance(context).processConversationArray(conversationPxy, channel, contact);
        }
        Message[] messages = gson.fromJson(element, Message[].class);
        MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
        if (messages != null && messages.length > 0 && cachedMessageList.size() > 0 && cachedMessageList.get(0).isLocalMessage()) {
            if (cachedMessageList.get(0).equals(messages[0])) {
                Utils.printLog(context, TAG, "Both messages are same.");
                deleteMessage(cachedMessageList.get(0));
            }
        }
        for (Message message : messages) {
            if (!message.isCall() || userPreferences.isDisplayCallRecordEnable()) {
                // we have to figure out if it is a parsing problem or response from server.
                if (message.getTo() == null) {
                    continue;
                }
                if (message.hasAttachment() && !(message.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                    setFilePathifExist(message);
                }
                if (message.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                    FileClientService fileClientService = new FileClientService(context);
                    fileClientService.loadContactsvCard(message);
                }
                if (Message.MetaDataType.HIDDEN.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                    continue;
                }
                if (messageDatabaseService.isMessagePresent(message.getKeyString(), Message.ReplyMessage.HIDE_MESSAGE.getValue())) {
                    messageDatabaseService.updateMessageReplyType(message.getKeyString(), Message.ReplyMessage.NON_HIDDEN.getValue());
                } else {
                    if (isServerCallNotRequired || contact == null && channel == null) {
                        messageDatabaseService.createMessage(message);
                    }
                }
                if (contact == null && channel == null) {
                    if (message.isHidden()) {
                        if (message.getGroupId() != null) {
                            Channel newChannel = ChannelService.getInstance(context).getChannelByChannelKey(message.getGroupId());
                            if (newChannel != null) {
                                getMessages(null, null, null, newChannel, null, true);
                            }
                        } else {
                            getMessages(null, null, new Contact(message.getContactIds()), null, null, true);
                        }
                    }
                }
            }
            if (!isServerCallNotRequired) {
                messageList.add(message);
            }
        }
        if (contact == null && channel == null) {
            Intent intent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
            LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    /*   messageList.removeAll(cachedMessageList);
        messageList.addAll(cachedMessageList);

        Collections.sort(messageList, new Comparator<Message>() {
            @Override
            public int compare(Message lhs, Message rhs) {
                return lhs.getCreatedAtTime().compareTo(rhs.getCreatedAtTime());
            }
        });*/
    List<Message> finalMessageList = messageDatabaseService.getMessages(startTime, endTime, contact, channel, conversationId);
    List<String> messageKeys = new ArrayList<>();
    for (Message msg : finalMessageList) {
        if (msg.getTo() == null) {
            continue;
        }
        if (Message.MetaDataType.HIDDEN.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(msg.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
            continue;
        }
        if (msg.getMetadata() != null && msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()) != null && !messageDatabaseService.isMessagePresent(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()))) {
            messageKeys.add(msg.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
        }
    }
    if (messageKeys != null && messageKeys.size() > 0) {
        Message[] replyMessageList = getMessageListByKeyList(messageKeys);
        if (replyMessageList != null) {
            for (Message replyMessage : replyMessageList) {
                if (replyMessage.getTo() == null) {
                    continue;
                }
                if (Message.MetaDataType.HIDDEN.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(replyMessage.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
                    continue;
                }
                if (replyMessage.hasAttachment() && !(replyMessage.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                    setFilePathifExist(replyMessage);
                }
                if (replyMessage.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
                    FileClientService fileClientService = new FileClientService(context);
                    fileClientService.loadContactsvCard(replyMessage);
                }
                replyMessage.setReplyMessage(Message.ReplyMessage.HIDE_MESSAGE.getValue());
                if (isServerCallNotRequired || contact == null && channel == null) {
                    messageDatabaseService.createMessage(replyMessage);
                }
            }
        }
    }
    if (messageList != null && !messageList.isEmpty()) {
        Collections.sort(messageList, new Comparator<Message>() {

            @Override
            public int compare(Message lhs, Message rhs) {
                return lhs.getCreatedAtTime().compareTo(rhs.getCreatedAtTime());
            }
        });
    }
    return channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType()) ? messageList : finalMessageList;
}
Also used : MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Conversation(com.applozic.mobicommons.people.channel.Conversation) UserDetail(com.applozic.mobicomkit.api.account.user.UserDetail) AnnotationExclusionStrategy(com.applozic.mobicommons.json.AnnotationExclusionStrategy) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) JsonParser(com.google.gson.JsonParser) GsonBuilder(com.google.gson.GsonBuilder) Channel(com.applozic.mobicommons.people.channel.Channel) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) Intent(android.content.Intent) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) Contact(com.applozic.mobicommons.people.contact.Contact) ArrayAdapterFactory(com.applozic.mobicommons.json.ArrayAdapterFactory) JSONObject(org.json.JSONObject)

Example 4 with UserDetail

use of com.applozic.mobicomkit.api.account.user.UserDetail in project Applozic-Android-SDK by AppLozic.

the class MessageClientService method processUserStatus.

public void processUserStatus(String userId, boolean isProfileImageUpdated) {
    try {
        String contactNumberParameter = "";
        String response = "";
        try {
            contactNumberParameter = "?userIds=" + URLEncoder.encode(userId);
        } catch (Exception e) {
            contactNumberParameter = "?userIds=" + userId;
            e.printStackTrace();
        }
        response = httpRequestUtils.getResponse(getUserDetailUrl() + contactNumberParameter, "application/json", "application/json");
        Utils.printLog(context, TAG, "User details response is " + response);
        if (TextUtils.isEmpty(response) || response.contains("<html>")) {
            return;
        }
        UserDetail[] userDetails = (UserDetail[]) GsonUtils.getObjectFromJson(response, UserDetail[].class);
        if (userDetails != null) {
            for (UserDetail userDetail : userDetails) {
                Contact contact = new Contact();
                contact.setUserId(userDetail.getUserId());
                contact.setFullName(userDetail.getDisplayName());
                contact.setConnected(userDetail.isConnected());
                contact.setContactNumber(userDetail.getPhoneNumber());
                contact.setLastSeenAt(userDetail.getLastSeenAtTime());
                contact.setImageURL(userDetail.getImageLink());
                contact.setStatus(userDetail.getStatusMessage());
                contact.setUserTypeId(userDetail.getUserTypeId());
                contact.setDeletedAtTime(userDetail.getDeletedAtTime());
                contact.setUnreadCount(0);
                contact.setRoleType(userDetail.getRoleType());
                contact.setMetadata(userDetail.getMetadata());
                contact.setLastMessageAtTime(userDetail.getLastMessageAtTime());
                baseContactService.upsert(contact);
            }
            if (isProfileImageUpdated) {
                BroadcastService.sendUpdateUserDetailBroadcast(context, BroadcastService.INTENT_ACTIONS.UPDATE_USER_DETAIL.toString(), userId);
            } else {
                BroadcastService.sendUpdateLastSeenAtTimeBroadcast(context, BroadcastService.INTENT_ACTIONS.UPDATE_LAST_SEEN_AT_TIME.toString(), userId);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UserDetail(com.applozic.mobicomkit.api.account.user.UserDetail) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Contact(com.applozic.mobicommons.people.contact.Contact)

Aggregations

UserDetail (com.applozic.mobicomkit.api.account.user.UserDetail)4 Contact (com.applozic.mobicommons.people.contact.Contact)4 Intent (android.content.Intent)1 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)1 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)1 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)1 ChannelFeed (com.applozic.mobicomkit.feed.ChannelFeed)1 AnnotationExclusionStrategy (com.applozic.mobicommons.json.AnnotationExclusionStrategy)1 ArrayAdapterFactory (com.applozic.mobicommons.json.ArrayAdapterFactory)1 Channel (com.applozic.mobicommons.people.channel.Channel)1 Conversation (com.applozic.mobicommons.people.channel.Conversation)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonParser (com.google.gson.JsonParser)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1