use of com.applozic.mobicommons.people.contact.Contact 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());
if (!TextUtils.isEmpty(userDetail.getDisplayName())) {
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());
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationService method getMessagesWithNetworkMetaData.
// Cleanup: try to get to default
public synchronized NetworkListDecorator<Message> getMessagesWithNetworkMetaData(Long startTime, Long endTime, Contact contact, Channel channel, Integer conversationId, boolean isSkipRead, boolean isForSearch) {
if (isForSearch) {
return getMessagesForParticularThreadWithNetworkMetaData(startTime, endTime, contact, channel, conversationId, 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() && ApplozicClient.getInstance(context).wasServerCallDoneBefore(contact, channel, conversationId) || (contact == null && channel == null && cachedMessageList.isEmpty() && ApplozicClient.getInstance(context).wasServerCallDoneBefore(contact, channel, conversationId)))) {
Utils.printLog(context, TAG, "cachedMessageList size is : " + cachedMessageList.size());
return new NetworkListDecorator<>(cachedMessageList, false);
}
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 new NetworkListDecorator<>(cachedMessageList, true);
}
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 new NetworkListDecorator<>(cachedMessageList, true);
}
return new NetworkListDecorator<>(cachedMessageList, true);
}
ApplozicClient.getInstance(context).updateServerCallDoneStatus(contact, channel, conversationId);
// for the try catch
boolean wasNetworkFail = false;
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;
}
message.setHidden(isHideActionMessage && message.isActionMessage());
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.hasHideKey()) {
if (message.getGroupId() != null) {
Channel newChannel = ChannelService.getInstance(context).getChannelByChannelKey(message.getGroupId());
if (newChannel != null) {
getMessagesWithNetworkMetaData(null, null, null, newChannel, null, true, isForSearch);
}
} else {
getMessagesWithNetworkMetaData(null, null, new Contact(message.getContactIds()), null, null, true, isForSearch);
}
}
}
}
if (!isServerCallNotRequired && !message.isHidden()) {
messageList.add(message);
}
}
if (contact == null && channel == null) {
Intent intent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
} catch (JsonSyntaxException | JSONException jsonException) {
jsonException.printStackTrace();
wasNetworkFail = true;
} catch (Exception exception) {
exception.printStackTrace();
}
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 new NetworkListDecorator<>(channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType()) ? messageList : finalMessageList, wasNetworkFail);
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class MobiComConversationService method processUserDetails.
// Cleanup: private
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());
if (!TextUtils.isEmpty(userDetail.getDisplayName())) {
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);
}
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class MessageSearchCache method processUserDetails.
public static void processUserDetails(UserDetail[] userDetails) {
if (userDetails != null) {
if (contactMap == null) {
contactMap = new HashMap<>();
}
for (UserDetail userDetail : userDetails) {
Contact contact = new Contact();
contact.setUserId(userDetail.getUserId());
contact.setContactNumber(userDetail.getPhoneNumber());
contact.setConnected(userDetail.isConnected());
contact.setStatus(userDetail.getStatusMessage());
if (!TextUtils.isEmpty(userDetail.getDisplayName())) {
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());
contact.setDeletedAtTime(userDetail.getDeletedAtTime());
contact.setEmailId(userDetail.getEmailId());
if (!TextUtils.isEmpty(userDetail.getImageLink())) {
contact.setImageURL(userDetail.getImageLink());
}
contact.setContactType(Contact.ContactType.APPLOZIC.getValue());
contactMap.put(userDetail.getUserId(), contact);
}
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class NotificationService method notifyUser.
// Cleanup: rename to a public api name eg: createApplozicNotification()
public void notifyUser(Contact contact, Channel channel, Message message, int index) {
if (ApplozicClient.getInstance(context).isNotificationDisabled()) {
Utils.printLog(context, TAG, "Notification is disabled !!");
return;
}
Bitmap notificationIconBitmap = null;
unReadMessageList = messageDatabaseService.getUnreadMessages();
int count = appContactService.getChatConversationCount() + appContactService.getGroupConversationCount();
int totalCount = messageDatabaseService.getTotalUnreadCount();
Class activity = null;
try {
activity = Class.forName(activityToOpen);
} catch (Exception e) {
e.printStackTrace();
}
if (message.getGroupId() != null) {
if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
String userId = ChannelService.getInstance(context).getGroupOfTwoReceiverUserId(channel.getKey());
if (!TextUtils.isEmpty(userId)) {
Contact newContact = appContactService.getContactById(userId);
notificationIconBitmap = appContactService.downloadContactImage(context, newContact);
}
} else if (Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) {
String userId = message.getTo();
if (!TextUtils.isEmpty(userId)) {
Contact newContact = appContactService.getContactById(userId);
notificationIconBitmap = appContactService.downloadContactImage(context, newContact);
}
} else {
notificationIconBitmap = appContactService.downloadGroupImage(context, channel);
}
} else {
notificationIconBitmap = appContactService.downloadContactImage(context, contact);
}
Integer smallIconResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) != null ? Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) : iconResourceId;
int colorResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_COLOR_METADATA) != null ? Utils.getMetaDataValueForResources(context, NOTIFICATION_COLOR_METADATA) : -1;
Intent intent;
intent = new Intent(context, activity);
if (count < 2) {
intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
} else {
intent.putExtra(MobiComKitConstants.QUICK_LIST, true);
}
if (applozicClient.isChatListOnNotificationIsHidden()) {
intent.putExtra("takeOrder", true);
}
if (applozicClient.isContextBasedChat()) {
intent.putExtra("contextBasedChat", true);
}
intent.putExtra("sms_body", "text");
intent.setType("vnd.android-dir/mms-sms");
PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) (System.currentTimeMillis() & 0xfffffff), intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, notificationChannels.getDefaultChannelId(muteNotifications(index))).setSmallIcon(smallIconResourceId).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(muteNotifications(index) ? NotificationCompat.PRIORITY_LOW : NotificationCompat.PRIORITY_HIGH).setWhen(System.currentTimeMillis());
if (colorResourceId > 0) {
mBuilder.setColor(context.getResources().getColor(colorResourceId));
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
mBuilder.setGroup(GROUP_KEY);
mBuilder.setGroupSummary(true);
} else {
if (totalCount != 0) {
mBuilder.setNumber(totalCount);
}
}
mBuilder.setContentIntent(pendingIntent);
mBuilder.setAutoCancel(true);
if (ApplozicClient.getInstance(context).getVibrationOnNotification() && !muteNotifications(index)) {
mBuilder.setVibrate(pattern);
}
if (!muteNotifications(index)) {
mBuilder.setSound(TextUtils.isEmpty(notificationFilePath) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(notificationFilePath));
}
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle(getNotificationTitle(count, contact, channel, message));
// Moves events into the expanded layout
try {
if (unReadMessageList != null) {
for (Message messageString : unReadMessageList) {
if (messageString.getGroupId() != null) {
Channel unreadChannel = ChannelService.getInstance(context).getChannelByChannelKey(messageString.getGroupId());
if (unreadChannel != null && unreadChannel.getUnreadCount() == 0) {
continue;
}
} else {
Contact unreadCount = appContactService.getContactById(messageString.getContactIds());
if (unreadCount != null && unreadCount.getUnreadCount() == 0) {
continue;
}
}
inboxStyle.addLine(getSpannedText(getMessageBody(messageString, count, channel, contact)));
}
}
// Moves the expanded layout object into the notification object.
} catch (Exception e) {
e.printStackTrace();
}
String summaryText = "";
if (count < 1) {
summaryText = "";
mBuilder.setLargeIcon(notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(message.getGroupId() != null ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName())));
mBuilder.setContentText(getSpannedText(getMessageBody(message, count, channel, contact)));
} else if (count >= 1 && count < 2) {
summaryText = totalCount < 2 ? totalCount + " new message " : totalCount + " new messages ";
mBuilder.setLargeIcon(notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(message.getGroupId() != null ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName())));
mBuilder.setContentText(summaryText);
} else {
summaryText = totalCount + " messages from " + count + " chats";
mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), iconResourceId));
mBuilder.setContentText(summaryText);
}
inboxStyle.setSummaryText(summaryText);
mBuilder.setContentTitle(getNotificationTitle(count, contact, channel, message));
mBuilder.setStyle(inboxStyle);
if (message.hasAttachment()) {
try {
InputStream in;
FileMeta fileMeta = message.getFileMetas();
HttpURLConnection httpConn = null;
if (fileMeta.getThumbnailBlobKey() != null) {
Bitmap bitmap = new FileClientService(context).downloadAndSaveThumbnailImage(context, message, 200, 200);
mBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap));
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
WearableNotificationWithVoice notificationWithVoice = new WearableNotificationWithVoice(mBuilder, wearable_action_title, wearable_action_label, wearable_send_icon, NOTIFICATION_ID);
notificationWithVoice.setCurrentContext(context);
notificationWithVoice.setPendingIntent(pendingIntent);
try {
if (unReadMessageList != null && unReadMessageList.size() > 0) {
notificationWithVoice.sendNotification();
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations