use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class MobiComPushReceiver method processMessage.
public static void processMessage(Context context, Bundle bundle, Map<String, String> data) {
try {
String payloadForDelivered = null, userConnected = null, userDisconnected = null, payloadDeliveredAndRead = null, messageKey = null, messageSent = null, deleteConversationForContact = null, deleteConversationForChannel = null, deleteMessage = null, conversationReadResponse = null, userBlockedResponse = null, userUnBlockedResponse = null, conversationReadForContact = null, conversationReadForChannel = null, conversationReadForSingleMessage = null, userDetailChanged = null, userDeleteNotification = null, messageMetadataUpdate = null, mutedUserListResponse = null;
SyncCallService syncCallService = SyncCallService.getInstance(context);
if (bundle != null) {
deleteConversationForContact = bundle.getString(notificationKeyList.get(5));
deleteMessage = bundle.getString(notificationKeyList.get(4));
payloadForDelivered = bundle.getString(notificationKeyList.get(3));
userConnected = bundle.getString(notificationKeyList.get(10));
userDisconnected = bundle.getString(notificationKeyList.get(11));
payloadDeliveredAndRead = bundle.getString(notificationKeyList.get(7));
messageSent = bundle.getString(notificationKeyList.get(1));
messageKey = bundle.getString(notificationKeyList.get(0));
conversationReadResponse = bundle.getString(notificationKeyList.get(9));
userBlockedResponse = bundle.getString(notificationKeyList.get(15));
userUnBlockedResponse = bundle.getString(notificationKeyList.get(16));
conversationReadForContact = bundle.getString(notificationKeyList.get(8));
conversationReadForChannel = bundle.getString(notificationKeyList.get(20));
deleteConversationForChannel = bundle.getString(notificationKeyList.get(22));
userDetailChanged = bundle.getString(notificationKeyList.get(29));
userDeleteNotification = bundle.getString(notificationKeyList.get(31));
messageMetadataUpdate = bundle.getString(notificationKeyList.get(30));
mutedUserListResponse = bundle.getString(notificationKeyList.get(32));
} else if (data != null) {
deleteConversationForContact = data.get(notificationKeyList.get(5));
deleteMessage = data.get(notificationKeyList.get(4));
payloadForDelivered = data.get(notificationKeyList.get(3));
userConnected = data.get(notificationKeyList.get(10));
userDisconnected = data.get(notificationKeyList.get(11));
payloadDeliveredAndRead = data.get(notificationKeyList.get(7));
messageSent = data.get(notificationKeyList.get(1));
messageKey = data.get(notificationKeyList.get(0));
conversationReadResponse = data.get(notificationKeyList.get(9));
userBlockedResponse = data.get(notificationKeyList.get(15));
userUnBlockedResponse = data.get(notificationKeyList.get(16));
conversationReadForContact = data.get(notificationKeyList.get(8));
conversationReadForChannel = data.get(notificationKeyList.get(20));
deleteConversationForChannel = data.get(notificationKeyList.get(22));
userDetailChanged = data.get(notificationKeyList.get(29));
userDeleteNotification = data.get(notificationKeyList.get(31));
messageMetadataUpdate = data.get(notificationKeyList.get(30));
mutedUserListResponse = data.get(notificationKeyList.get(32));
}
if (!TextUtils.isEmpty(payloadForDelivered)) {
MqttMessageResponse messageResponseForDelivered = (MqttMessageResponse) GsonUtils.getObjectFromJson(payloadForDelivered, MqttMessageResponse.class);
if (processPushNotificationId(messageResponseForDelivered.getId())) {
return;
}
addPushNotificationId(messageResponseForDelivered.getId());
String[] splitKeyString = (messageResponseForDelivered.getMessage()).toString().split(",");
String keyString = splitKeyString[0];
// String userId = splitKeyString[1];
syncCallService.updateDeliveryStatus(keyString);
}
if (!TextUtils.isEmpty(payloadDeliveredAndRead)) {
MqttMessageResponse messageResponseForDeliveredAndRead = (MqttMessageResponse) GsonUtils.getObjectFromJson(payloadDeliveredAndRead, MqttMessageResponse.class);
if (processPushNotificationId(messageResponseForDeliveredAndRead.getId())) {
return;
}
addPushNotificationId(messageResponseForDeliveredAndRead.getId());
String[] splitKeyString = (messageResponseForDeliveredAndRead.getMessage()).toString().split(",");
String keyString = splitKeyString[0];
// String userId = splitKeyString[1];
syncCallService.updateReadStatus(keyString);
}
if (!TextUtils.isEmpty(deleteConversationForContact)) {
MqttMessageResponse deleteConversationResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(deleteConversationForContact, MqttMessageResponse.class);
if (processPushNotificationId(deleteConversationResponse.getId())) {
return;
}
addPushNotificationId(deleteConversationResponse.getId());
MobiComConversationService conversationService = new MobiComConversationService(context);
conversationService.deleteConversationFromDevice(deleteConversationResponse.getMessage().toString());
BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), deleteConversationResponse.getMessage().toString(), 0, "success");
}
if (!TextUtils.isEmpty(deleteConversationForChannel)) {
InstantMessageResponse instantMessageResponse = (InstantMessageResponse) GsonUtils.getObjectFromJson(deleteConversationForChannel, InstantMessageResponse.class);
if (processPushNotificationId(instantMessageResponse.getId())) {
return;
}
addPushNotificationId(instantMessageResponse.getId());
syncCallService.deleteChannelConversationThread(instantMessageResponse.getMessage());
BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), null, Integer.valueOf(instantMessageResponse.getMessage()), "success");
}
if (!TextUtils.isEmpty(userConnected)) {
MqttMessageResponse userConnectedResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(userConnected, MqttMessageResponse.class);
if (processPushNotificationId(userConnectedResponse.getId())) {
return;
}
addPushNotificationId(userConnectedResponse.getId());
syncCallService.updateConnectedStatus(userConnectedResponse.getMessage().toString(), new Date(), true);
}
if (!TextUtils.isEmpty(userDisconnected)) {
MqttMessageResponse userDisconnectedResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(userDisconnected, MqttMessageResponse.class);
if (processPushNotificationId(userDisconnectedResponse.getId())) {
return;
}
addPushNotificationId(userDisconnectedResponse.getId());
String[] parts = userDisconnectedResponse.getMessage().toString().split(",");
String userId = parts[0];
Date lastSeenAt = new Date();
if (parts.length >= 2 && !parts[1].equals("null")) {
lastSeenAt = new Date(Long.valueOf(parts[1]));
}
syncCallService.updateConnectedStatus(userId, lastSeenAt, false);
}
if (!TextUtils.isEmpty(deleteMessage)) {
MqttMessageResponse deleteSingleMessageResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(deleteMessage, MqttMessageResponse.class);
if (processPushNotificationId(deleteSingleMessageResponse.getId())) {
return;
}
addPushNotificationId(deleteSingleMessageResponse.getId());
String deleteMessageKeyAndUserId = deleteSingleMessageResponse.getMessage().toString();
// String contactNumbers = deleteMessageKeyAndUserId.split(",").length > 1 ? deleteMessageKeyAndUserId.split(",")[1] : null;
syncCallService.deleteMessage(deleteMessageKeyAndUserId.split(",")[0]);
}
if (!TextUtils.isEmpty(messageSent)) {
GcmMessageResponse syncSentMessageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageSent, GcmMessageResponse.class);
if (processPushNotificationId(syncSentMessageResponse.getId())) {
return;
}
addPushNotificationId(syncSentMessageResponse.getId());
syncCallService.syncMessages(null);
}
GcmMessageResponse syncMessageResponse = null;
if (!TextUtils.isEmpty(messageKey)) {
syncMessageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageKey, GcmMessageResponse.class);
if (processPushNotificationId(syncMessageResponse.getId())) {
return;
}
addPushNotificationId(syncMessageResponse.getId());
Message messageObj = syncMessageResponse.getMessage();
if (!TextUtils.isEmpty(messageObj.getKeyString())) {
syncCallService.syncMessages(messageObj.getKeyString());
} else {
syncCallService.syncMessages(null);
}
}
if (!TextUtils.isEmpty(conversationReadResponse)) {
MqttMessageResponse updateDeliveryStatusForContactResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(conversationReadResponse, MqttMessageResponse.class);
if (notificationKeyList.get(9).equals(updateDeliveryStatusForContactResponse.getType())) {
if (processPushNotificationId(updateDeliveryStatusForContactResponse.getId())) {
return;
}
addPushNotificationId(updateDeliveryStatusForContactResponse.getId());
syncCallService.updateDeliveryStatusForContact(updateDeliveryStatusForContactResponse.getMessage().toString(), true);
}
}
if (!TextUtils.isEmpty(userBlockedResponse)) {
MqttMessageResponse syncUserBlock = (MqttMessageResponse) GsonUtils.getObjectFromJson(userBlockedResponse, MqttMessageResponse.class);
if (processPushNotificationId(syncUserBlock.getId())) {
return;
}
addPushNotificationId(syncUserBlock.getId());
SyncCallService.getInstance(context).syncBlockUsers();
}
if (!TextUtils.isEmpty(userUnBlockedResponse)) {
MqttMessageResponse syncUserUnBlock = (MqttMessageResponse) GsonUtils.getObjectFromJson(userUnBlockedResponse, MqttMessageResponse.class);
if (processPushNotificationId(syncUserUnBlock.getId())) {
return;
}
addPushNotificationId(syncUserUnBlock.getId());
SyncCallService.getInstance(context).syncBlockUsers();
}
if (!TextUtils.isEmpty(conversationReadForContact)) {
MqttMessageResponse conversationReadForContactResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(conversationReadForContact, MqttMessageResponse.class);
if (processPushNotificationId(conversationReadForContactResponse.getId())) {
return;
}
addPushNotificationId(conversationReadForContactResponse.getId());
syncCallService.updateConversationReadStatus(conversationReadForContactResponse.getMessage().toString(), false);
}
if (!TextUtils.isEmpty(conversationReadForChannel)) {
InstantMessageResponse conversationReadForChannelResponse = (InstantMessageResponse) GsonUtils.getObjectFromJson(conversationReadForChannel, InstantMessageResponse.class);
if (processPushNotificationId(conversationReadForChannelResponse.getId())) {
return;
}
addPushNotificationId(conversationReadForChannelResponse.getId());
syncCallService.updateConversationReadStatus(conversationReadForChannelResponse.getMessage(), true);
}
if (!TextUtils.isEmpty(userDetailChanged) || !TextUtils.isEmpty(userDeleteNotification)) {
MqttMessageResponse response = null;
if (!TextUtils.isEmpty(userDetailChanged)) {
response = (MqttMessageResponse) GsonUtils.getObjectFromJson(userDetailChanged, MqttMessageResponse.class);
} else if (!TextUtils.isEmpty(userDeleteNotification)) {
response = (MqttMessageResponse) GsonUtils.getObjectFromJson(userDeleteNotification, MqttMessageResponse.class);
}
if (processPushNotificationId(response.getId())) {
return;
}
addPushNotificationId(response.getId());
String userId = response.getMessage().toString();
syncCallService.syncUserDetail(userId);
}
if (!TextUtils.isEmpty(messageMetadataUpdate)) {
String keyString = null;
String id = null;
String deviceKey = null;
try {
GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageMetadataUpdate, GcmMessageResponse.class);
keyString = messageResponse.getMessage().getKeyString();
id = messageResponse.getId();
deviceKey = messageResponse.getMessage().getDeviceKeyString();
} catch (Exception e) {
try {
InstantMessageResponse response = (InstantMessageResponse) GsonUtils.getObjectFromJson(messageMetadataUpdate, InstantMessageResponse.class);
keyString = response.getMessage();
id = response.getId();
Message message = new MessageDatabaseService(context).getMessage(keyString);
if (message != null) {
deviceKey = message.getDeviceKeyString();
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
if (processPushNotificationId(id)) {
return;
}
addPushNotificationId(id);
if (deviceKey != null && deviceKey.equals(MobiComUserPreference.getInstance(context).getDeviceKeyString())) {
return;
}
syncCallService.syncMessageMetadataUpdate(keyString, true);
}
if (!TextUtils.isEmpty(mutedUserListResponse)) {
try {
InstantMessageResponse response = (InstantMessageResponse) GsonUtils.getObjectFromJson(mutedUserListResponse, InstantMessageResponse.class);
if (processPushNotificationId(response.getId())) {
return;
}
addPushNotificationId(response.getId());
if (response.getMessage() != null) {
String muteFlag = String.valueOf(response.getMessage().charAt(response.getMessage().length() - 1));
if ("1".equals(muteFlag)) {
syncCallService.syncMutedUserList(true, null);
} else if ("0".equals(muteFlag)) {
String userId = response.getMessage().substring(0, response.getMessage().length() - 2);
syncCallService.syncMutedUserList(true, userId);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class NotificationIntentService method onHandleWork.
@Override
protected void onHandleWork(@NonNull Intent intent) {
if (intent != null) {
final String action = intent.getAction();
if (ACTION_AL_NOTIFICATION.equals(action)) {
String messageKey = intent.getStringExtra(MobiComKitConstants.AL_MESSAGE_KEY);
Message message = messageDatabaseService.getMessage(messageKey);
if (message != null) {
int notificationId = Utils.getLauncherIcon(getApplicationContext());
final NotificationService notificationService = new NotificationService(notificationId == 0 ? resourceArray[0] : notificationId, NotificationIntentService.this, resourceArray[1], resourceArray[2], resourceArray[3]);
if (MobiComUserPreference.getInstance(NotificationIntentService.this).isLoggedIn()) {
Channel channel = ChannelService.getInstance(NotificationIntentService.this).getChannelInfo(message.getGroupId());
Contact contact = null;
if (message.getConversationId() != null) {
ConversationService.getInstance(NotificationIntentService.this).getConversation(message.getConversationId());
}
if (message.getGroupId() == null) {
contact = appContactService.getContactById(message.getContactIds());
}
if (ApplozicClient.getInstance(NotificationIntentService.this).isNotificationStacking()) {
notificationService.notifyUser(contact, channel, message);
} else {
notificationService.notifyUserForNormalMessage(contact, channel, message);
}
}
}
}
}
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class NotificationService method notifyUserForNormalMessage.
public void notifyUserForNormalMessage(Contact contact, Channel channel, Message message) {
if (ApplozicClient.getInstance(context).isNotificationDisabled()) {
Utils.printLog(context, TAG, "Notification is disabled");
return;
}
String title = null;
String notificationText;
Bitmap notificationIconBitmap = null;
Contact displayNameContact = null;
if (message.getGroupId() != null) {
if (channel == null) {
return;
}
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);
title = newContact.getDisplayName();
}
} else {
displayNameContact = appContactService.getContactById(message.getTo());
title = ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(context).getUserId());
notificationIconBitmap = appContactService.downloadGroupImage(context, channel);
}
} else {
title = contact.getDisplayName();
notificationIconBitmap = appContactService.downloadContactImage(context, contact);
}
if (message.getContentType() == Message.ContentType.LOCATION.getValue()) {
notificationText = MobiComKitConstants.LOCATION;
} else if (message.getContentType() == Message.ContentType.AUDIO_MSG.getValue()) {
notificationText = MobiComKitConstants.AUDIO;
} else if (message.getContentType() == Message.ContentType.VIDEO_MSG.getValue()) {
notificationText = MobiComKitConstants.VIDEO;
} else if (message.hasAttachment() && TextUtils.isEmpty(message.getMessage())) {
notificationText = MobiComKitConstants.ATTACHMENT;
} else {
notificationText = message.getMessage();
}
Class activity = null;
try {
activity = Class.forName(activityToOpen);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Integer smallIconResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) != null ? Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) : iconResourceId;
Intent intent = new Intent(context, activity);
intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
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, MobiComKitConstants.AL_PUSH_NOTIFICATION);
mBuilder.setSmallIcon(smallIconResourceId).setLargeIcon(ApplozicClient.getInstance(context).isShowAppIconInNotification() ? BitmapFactory.decodeResource(context.getResources(), iconResourceId) : notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(channel != null && !Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName()))).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(NotificationCompat.PRIORITY_MAX).setWhen(System.currentTimeMillis()).setContentTitle(title).setContentText(channel != null && !Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) ? displayNameContact.getDisplayName() + ": " + notificationText : notificationText).setSound(TextUtils.isEmpty(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()));
mBuilder.setContentIntent(pendingIntent);
mBuilder.setAutoCancel(true);
if (ApplozicClient.getInstance(context).isUnreadCountBadgeEnabled()) {
int totalCount = messageDatabaseService.getTotalUnreadCount();
if (totalCount != 0) {
mBuilder.setNumber(totalCount);
}
}
if (message.hasAttachment()) {
try {
FileMeta fileMeta = message.getFileMetas();
HttpURLConnection httpConn = null;
if (fileMeta.getThumbnailUrl() != null) {
httpConn = new MobiComKitClientService(context).openHttpConnection(fileMeta.getThumbnailUrl());
int response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
Bitmap bitmap = BitmapFactory.decodeStream(httpConn.getInputStream());
String imageName = FileUtils.getName(fileMeta.getName()) + message.getCreatedAtTime() + "." + FileUtils.getFileFormat(fileMeta.getName());
File file = FileClientService.getFilePath(imageName, context, "image", true);
ImageUtils.saveImageToInternalStorage(file, bitmap);
mBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap));
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
WearableNotificationWithVoice notificationWithVoice = new WearableNotificationWithVoice(mBuilder, wearable_action_title, wearable_action_label, wearable_send_icon, message.getGroupId() != null ? String.valueOf(message.getGroupId()).hashCode() : message.getContactIds().hashCode());
notificationWithVoice.setCurrentContext(context);
notificationWithVoice.setPendingIntent(pendingIntent);
try {
notificationWithVoice.sendNotification();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class VideoCallNotificationHelper method sendVideoCallEnd.
public void sendVideoCallEnd(Contact contact, String videoCallId, String duration) {
Message statusMessage = getVideoCallStatusMessage(contact);
statusMessage.setMetadata(getVideoCallEndMap(duration));
statusMessage.setMessage("Call End");
conversationService.sendMessage(statusMessage, MessageIntentService.class);
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class VideoCallNotificationHelper method sendCallMissed.
public void sendCallMissed(Contact contact, String videoCallId) {
this.videoCallId = videoCallId;
Message notificationMessage = getNotificationMessage(contact);
notificationMessage.setMetadata(getMissedCallMap());
notificationMessage.setMessage(videoCallId);
conversationService.sendMessage(notificationMessage, MessageIntentService.class);
}
Aggregations