Search in sources :

Example 1 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class MobiComMessageService method putMtextToDatabase.

public void putMtextToDatabase(String payloadForMtextReceived) {
    JSONObject json = null;
    try {
        json = new JSONObject(payloadForMtextReceived);
        String smsKeyString = json.getString("keyString");
        String receiverNumber = json.getString("contactNumber");
        String body = json.getString("message");
        Integer timeToLive = json.isNull("timeToLive") ? null : Integer.parseInt(json.getString("timeToLive"));
        Message mTextMessageReceived = new Message();
        mTextMessageReceived.setTo(json.getString("senderContactNumber"));
        mTextMessageReceived.setCreatedAtTime(System.currentTimeMillis());
        mTextMessageReceived.setMessage(body);
        mTextMessageReceived.setSendToDevice(Boolean.FALSE);
        mTextMessageReceived.setSent(Boolean.TRUE);
        mTextMessageReceived.setDeviceKeyString(MobiComUserPreference.getInstance(context).getDeviceKeyString());
        mTextMessageReceived.setType(Message.MessageType.MT_INBOX.getValue());
        mTextMessageReceived.setSource(Message.Source.MT_MOBILE_APP.getValue());
        mTextMessageReceived.setTimeToLive(timeToLive);
        /*   if (json.has("fileMetaKeyStrings")) {
                JSONArray fileMetaKeyStringsJSONArray = json.getJSONArray("fileMetaKeyStrings");
                List<String> fileMetaKeyStrings = new ArrayList<String>();
                for (int i = 0; i < fileMetaKeyStringsJSONArray.length(); i++) {
                    JSONObject fileMeta = fileMetaKeyStringsJSONArray.getJSONObject(i);
                    fileMetaKeyStrings.add(fileMeta.toString());
                }
                //mTextMessageReceived.setFileMetaKeyStrings(fileMetaKeyStrings);
            }*/
        mTextMessageReceived.processContactIds(context);
        mTextMessageReceived.setTo(mTextMessageReceived.getTo());
        Contact receiverContact = baseContactService.getContactById(receiverNumber);
        if (mTextMessageReceived.getMessage() != null && PersonalizedMessage.isPersonalized(mTextMessageReceived.getMessage())) {
            mTextMessageReceived.setMessage(PersonalizedMessage.prepareMessageFromTemplate(mTextMessageReceived.getMessage(), receiverContact));
        }
        try {
            messageClientService.sendMessageToServer(mTextMessageReceived, null);
        } catch (Exception ex) {
            Utils.printLog(context, TAG, "Received message error " + ex.getMessage());
        }
        messageClientService.updateDeliveryStatus(smsKeyString, null, receiverNumber);
    } catch (JSONException e) {
        e.printStackTrace();
        return;
    }
}
Also used : JSONObject(org.json.JSONObject) PersonalizedMessage(com.applozic.mobicommons.personalization.PersonalizedMessage) JSONException(org.json.JSONException) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 2 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class UserService method processUser.

public synchronized void processUser(UserDetail userDetail) {
    Contact contact = new Contact();
    contact.setUserId(userDetail.getUserId());
    contact.setContactNumber(userDetail.getPhoneNumber());
    contact.setConnected(userDetail.isConnected());
    contact.setStatus(userDetail.getStatusMessage());
    contact.setFullName(userDetail.getDisplayName());
    contact.setLastSeenAt(userDetail.getLastSeenAtTime());
    contact.setUserTypeId(userDetail.getUserTypeId());
    contact.setUnreadCount(0);
    contact.setLastMessageAtTime(userDetail.getLastMessageAtTime());
    contact.setMetadata(userDetail.getMetadata());
    contact.setRoleType(userDetail.getRoleType());
    if (!TextUtils.isEmpty(userDetail.getImageLink())) {
        contact.setImageURL(userDetail.getImageLink());
    }
    baseContactService.upsert(contact);
}
Also used : Contact(com.applozic.mobicommons.people.contact.Contact)

Example 3 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class MessageClientService method processMessage.

public void processMessage(Message message, Handler handler) throws Exception {
    boolean isBroadcast = (message.getMessageId() == null);
    MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
    message.setSent(Boolean.TRUE);
    message.setSendToDevice(Boolean.FALSE);
    message.setSuUserKeyString(userPreferences.getSuUserKeyString());
    message.processContactIds(context);
    Contact contact = null;
    Channel channel = null;
    boolean isBroadcastOneByOneGroupType = false;
    boolean isOpenGroup = false;
    boolean skipMessage = false;
    if (message.getGroupId() == null) {
        contact = baseContactService.getContactById(message.getContactIds());
    } else {
        channel = ChannelService.getInstance(context).getChannel(message.getGroupId());
        isOpenGroup = Channel.GroupType.OPEN.getValue().equals(channel.getType());
        isBroadcastOneByOneGroupType = Channel.GroupType.BROADCAST_ONE_BY_ONE.getValue().equals(channel.getType());
    }
    long messageId = -1;
    List<String> fileKeys = new ArrayList<String>();
    String keyString = null;
    if (!isBroadcastOneByOneGroupType) {
        keyString = UUID.randomUUID().toString();
        message.setKeyString(keyString);
        message.setSentToServer(false);
    } else {
        message.setSentToServer(true);
    }
    if (Message.MetaDataType.HIDDEN.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
        skipMessage = true;
    }
    if (!skipMessage && !isOpenGroup) {
        messageId = messageDatabaseService.createMessage(message);
    }
    if (isBroadcast && !skipMessage) {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
    }
    if (!isBroadcastOneByOneGroupType && message.isUploadRequired() && !isOpenGroup) {
        for (String filePath : message.getFilePaths()) {
            try {
                String fileMetaResponse = new FileClientService(context).uploadBlobImage(filePath, handler);
                if (fileMetaResponse == null) {
                    if (skipMessage) {
                        return;
                    }
                    if (handler != null) {
                        android.os.Message msg = handler.obtainMessage();
                        msg.what = MobiComConversationService.UPLOAD_COMPLETED;
                        msg.getData().putString("error", "Error while uploading");
                        msg.sendToTarget();
                    }
                    if (!message.isContactMessage()) {
                        messageDatabaseService.updateCanceledFlag(messageId, 1);
                    }
                    BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
                    return;
                }
                if (ApplozicClient.getInstance(context).isCustomStorageServiceEnabled()) {
                    if (!TextUtils.isEmpty(fileMetaResponse)) {
                        message.setFileMetas((FileMeta) GsonUtils.getObjectFromJson(fileMetaResponse, FileMeta.class));
                        if (handler != null) {
                            android.os.Message msg = handler.obtainMessage();
                            msg.what = MobiComConversationService.UPLOAD_COMPLETED;
                            msg.getData().putString("error", null);
                            msg.sendToTarget();
                        }
                    }
                } else {
                    JsonParser jsonParser = new JsonParser();
                    JsonObject jsonObject = jsonParser.parse(fileMetaResponse).getAsJsonObject();
                    if (jsonObject.has(FILE_META)) {
                        Gson gson = new Gson();
                        message.setFileMetas(gson.fromJson(jsonObject.get(FILE_META), FileMeta.class));
                        if (handler != null) {
                            android.os.Message msg = handler.obtainMessage();
                            msg.what = MobiComConversationService.UPLOAD_COMPLETED;
                            msg.getData().putString("error", null);
                            msg.sendToTarget();
                        }
                    }
                }
            } catch (Exception ex) {
                Utils.printLog(context, TAG, "Error uploading file to server: " + filePath);
                if (handler != null) {
                    android.os.Message msg = handler.obtainMessage();
                    msg.what = MobiComConversationService.UPLOAD_COMPLETED;
                    msg.getData().putString("error", "Error uploading file to server: " + filePath);
                    msg.sendToTarget();
                }
                /*  recentMessageSentToServer.remove(message);*/
                if (!message.isContactMessage() && !skipMessage) {
                    messageDatabaseService.updateCanceledFlag(messageId, 1);
                }
                if (!skipMessage) {
                    BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
                }
                return;
            }
        }
        if (messageId != -1 && !skipMessage) {
            messageDatabaseService.updateMessageFileMetas(messageId, message);
        }
    }
    Message newMessage = new Message();
    newMessage.setTo(message.getTo());
    newMessage.setKeyString(message.getKeyString());
    newMessage.setMessage(message.getMessage());
    newMessage.setFileMetas(message.getFileMetas());
    newMessage.setCreatedAtTime(message.getCreatedAtTime());
    newMessage.setRead(Boolean.TRUE);
    newMessage.setDeviceKeyString(message.getDeviceKeyString());
    newMessage.setSuUserKeyString(message.getSuUserKeyString());
    newMessage.setSent(message.isSent());
    newMessage.setType(message.getType());
    newMessage.setTimeToLive(message.getTimeToLive());
    newMessage.setSource(message.getSource());
    newMessage.setScheduledAt(message.getScheduledAt());
    newMessage.setStoreOnDevice(message.isStoreOnDevice());
    newMessage.setDelivered(message.getDelivered());
    newMessage.setStatus(message.getStatus());
    newMessage.setMetadata(message.getMetadata());
    newMessage.setSendToDevice(message.isSendToDevice());
    newMessage.setContentType(message.getContentType());
    newMessage.setConversationId(message.getConversationId());
    if (message.getGroupId() != null) {
        newMessage.setGroupId(message.getGroupId());
    }
    if (!TextUtils.isEmpty(message.getClientGroupId())) {
        newMessage.setClientGroupId(message.getClientGroupId());
    }
    if (contact != null && !TextUtils.isEmpty(contact.getApplicationId())) {
        newMessage.setApplicationId(contact.getApplicationId());
    } else {
        newMessage.setApplicationId(getApplicationKey(context));
    }
    try {
        if (!isBroadcastOneByOneGroupType) {
            String response = sendMessage(newMessage);
            if (message.hasAttachment() && TextUtils.isEmpty(response) && !message.isContactMessage() && !skipMessage && !isOpenGroup) {
                messageDatabaseService.updateCanceledFlag(messageId, 1);
                if (handler != null) {
                    android.os.Message msg = handler.obtainMessage();
                    msg.what = MobiComConversationService.UPLOAD_COMPLETED;
                    msg.getData().putString("error", "Error uploading file to server");
                    msg.sendToTarget();
                }
                BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
            }
            MessageResponse messageResponse = (MessageResponse) GsonUtils.getObjectFromJson(response, MessageResponse.class);
            keyString = messageResponse.getMessageKey();
            if (!TextUtils.isEmpty(keyString)) {
                message.setSentMessageTimeAtServer(Long.parseLong(messageResponse.getCreatedAtTime()));
                message.setConversationId(messageResponse.getConversationId());
                message.setSentToServer(true);
                message.setKeyString(keyString);
            }
            if (!skipMessage && !isOpenGroup) {
                messageDatabaseService.updateMessage(messageId, message.getSentMessageTimeAtServer(), keyString, message.isSentToServer());
            }
        } else {
            message.setSentMessageTimeAtServer(message.getCreatedAtTime());
            messageDatabaseService.updateMessage(messageId, message.getSentMessageTimeAtServer(), keyString, message.isSentToServer());
        }
        if (message.isSentToServer()) {
            if (handler != null) {
                android.os.Message msg = handler.obtainMessage();
                msg.what = MobiComConversationService.MESSAGE_SENT;
                msg.getData().putString("message", message.getKeyString());
                msg.sendToTarget();
            }
        }
        if (!TextUtils.isEmpty(keyString)) {
        // Todo: Handle server message add failure due to internet disconnect.
        } else {
        // Todo: If message type is mtext, tell user that internet is not working, else send update with db id.
        }
        if (!skipMessage || isOpenGroup) {
            BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.MESSAGE_SYNC_ACK_FROM_SERVER.toString(), message);
        }
    } catch (Exception e) {
        if (handler != null) {
            android.os.Message msg = handler.obtainMessage();
            msg.what = MobiComConversationService.UPLOAD_COMPLETED;
            msg.getData().putString("error", "Error uploading file");
            msg.sendToTarget();
        // handler.onCompleted(new ApplozicException("Error uploading file"));
        }
    }
/*  if (recentMessageSentToServer.size() > 20) {
            recentMessageSentToServer.subList(0, 10).clear();
        }*/
}
Also used : MessageResponse(com.applozic.mobicomkit.feed.MessageResponse) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Channel(com.applozic.mobicommons.people.channel.Channel) ArrayList(java.util.ArrayList) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Contact(com.applozic.mobicommons.people.contact.Contact) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta) JsonParser(com.google.gson.JsonParser)

Example 4 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class VideoCallNotificationHelper method buildVideoCallNotification.

public static void buildVideoCallNotification(Context context, Message message) {
    Map<String, String> metaDataMap = message.getMetadata();
    Contact contact = new AppContactService(context).getContactById(message.getContactIds());
    String audioORVideoCallPrefix = Boolean.valueOf(metaDataMap.get(CALL_AUDIO_ONLY)) ? "audio call " : "video call ";
    if (metaDataMap.get(VideoCallNotificationHelper.MSG_TYPE).equals(VideoCallNotificationHelper.CALL_MISSED)) {
        Message message1 = new Message(message);
        message1.setMessage("You missed " + audioORVideoCallPrefix + " from " + contact.getDisplayName());
        BroadcastService.sendNotificationBroadcast(context, message1);
    }
}
Also used : AppContactService(com.applozic.mobicomkit.contact.AppContactService) Message(com.applozic.mobicomkit.api.conversation.Message) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 5 with Contact

use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.

the class ContactDatabase method prepareContactValues.

public ContentValues prepareContactValues(Contact contact) {
    ContentValues contentValues = new ContentValues();
    Contact contactImage = null;
    contentValues.put(MobiComDatabaseHelper.FULL_NAME, getFullNameForUpdate(contact));
    if (!TextUtils.isEmpty(contact.getContactNumber())) {
        contentValues.put(MobiComDatabaseHelper.CONTACT_NO, contact.getContactNumber());
    }
    if (!TextUtils.isEmpty(contact.getImageURL())) {
        contentValues.put(MobiComDatabaseHelper.CONTACT_IMAGE_URL, contact.getImageURL());
        contactImage = getContactById(contact.getUserId());
    }
    if (contactImage != null && !TextUtils.isEmpty(contactImage.getImageURL()) && !TextUtils.isEmpty(contact.getImageURL()) && !contact.getImageURL().equals(contactImage.getImageURL())) {
        updateContactLocalImageURIToNull(contact.getUserId());
    }
    if (!TextUtils.isEmpty(contact.getLocalImageUrl())) {
        contentValues.put(MobiComDatabaseHelper.CONTACT_IMAGE_LOCAL_URI, contact.getLocalImageUrl());
    }
    contentValues.put(MobiComDatabaseHelper.USERID, contact.getUserId());
    if (!TextUtils.isEmpty(contact.getEmailId())) {
        contentValues.put(MobiComDatabaseHelper.EMAIL, contact.getEmailId());
    }
    if (!TextUtils.isEmpty(contact.getApplicationId())) {
        contentValues.put(MobiComDatabaseHelper.APPLICATION_ID, contact.getApplicationId());
    }
    contentValues.put(MobiComDatabaseHelper.CONNECTED, contact.isConnected() ? 1 : 0);
    if (contact.getLastSeenAt() != 0) {
        contentValues.put(MobiComDatabaseHelper.LAST_SEEN_AT_TIME, contact.getLastSeenAt());
    }
    if (contact.getUnreadCount() != null && contact.getUnreadCount() != 0) {
        contentValues.put(MobiComDatabaseHelper.UNREAD_COUNT, contact.getUnreadCount());
    }
    contentValues.put(MobiComDatabaseHelper.STATUS, contact.getStatus());
    if (contact.isBlocked()) {
        contentValues.put(MobiComDatabaseHelper.BLOCKED, contact.isBlocked());
    }
    if (contact.isBlockedBy()) {
        contentValues.put(MobiComDatabaseHelper.BLOCKED_BY, contact.isBlockedBy());
    }
    if (contact.getContactType() != 0) {
        contentValues.put(MobiComDatabaseHelper.CONTACT_TYPE, contact.getContactType());
    }
    if (contact.getNotificationAfterTime() != null && contact.getNotificationAfterTime() != 0) {
        contentValues.put(MobiComDatabaseHelper.NOTIFICATION_AFTER_TIME, contact.getNotificationAfterTime());
    }
    if (contact.getMetadata() != null && !contact.getMetadata().isEmpty()) {
        contentValues.put(MobiComDatabaseHelper.USER_METADATA, GsonUtils.getJsonFromObject(contact.getMetadata(), Map.class));
    }
    contentValues.put(MobiComDatabaseHelper.USER_ROLE_TYPE, contact.getRoleType());
    contentValues.put(MobiComDatabaseHelper.LAST_MESSAGED_AT, contact.getLastMessageAtTime());
    contentValues.put(MobiComDatabaseHelper.USER_TYPE_ID, contact.getUserTypeId());
    contentValues.put(MobiComDatabaseHelper.DELETED_AT, contact.getDeletedAtTime());
    return contentValues;
}
Also used : ContentValues(android.content.ContentValues) Map(java.util.Map) Contact(com.applozic.mobicommons.people.contact.Contact)

Aggregations

Contact (com.applozic.mobicommons.people.contact.Contact)107 Channel (com.applozic.mobicommons.people.channel.Channel)26 Message (com.applozic.mobicomkit.api.conversation.Message)18 Intent (android.content.Intent)17 AppContactService (com.applozic.mobicomkit.contact.AppContactService)17 ArrayList (java.util.ArrayList)15 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)14 UserDetail (com.applozic.mobicomkit.api.account.user.UserDetail)12 Test (org.junit.Test)12 Bitmap (android.graphics.Bitmap)11 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)10 Context (android.content.Context)9 SpannableString (android.text.SpannableString)8 NonNull (androidx.annotation.NonNull)8 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)8 ApiResponse (com.applozic.mobicomkit.feed.ApiResponse)8 SyncBlockUserApiResponse (com.applozic.mobicomkit.feed.SyncBlockUserApiResponse)8 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)7 ContactDatabase (com.applozic.mobicomkit.contact.database.ContactDatabase)7 RegisteredUsersApiResponse (com.applozic.mobicomkit.feed.RegisteredUsersApiResponse)7