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;
}
}
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);
}
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();
}*/
}
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);
}
}
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;
}
Aggregations