use of com.applozic.mobicomkit.api.conversation.MobiComConversationService in project Applozic-Android-SDK by AppLozic.
the class ChannelService method processChannelDeleteConversation.
/**
* Delete channel along with all messages. Use with caution.
*
* @return "success" or error
*/
public synchronized String processChannelDeleteConversation(@NonNull Channel channel, @NonNull Context context) {
String response = new MobiComConversationService(context).deleteSync(null, channel, null);
if (!TextUtils.isEmpty(response) && "success".equals(response)) {
channelDatabaseService.deleteChannelUserMappers(channel.getKey());
channelDatabaseService.deleteChannel(channel.getKey());
}
return response;
}
use of com.applozic.mobicomkit.api.conversation.MobiComConversationService in project Applozic-Android-SDK by AppLozic.
the class VideoCallNotificationHelper method init.
public void init() {
this.conversationService = new MobiComConversationService(context);
this.baseContactService = new AppContactService(context);
}
use of com.applozic.mobicomkit.api.conversation.MobiComConversationService in project Applozic-Android-SDK by AppLozic.
the class AlUIService method deleteConversationThread.
/**
* This method deletes the conversation with a contact or channel.
*
* @param contact The contact object whose conversation thread is to be deleted
* @param channel The group object whose conversation thread is to be deleted
*/
public void deleteConversationThread(final Contact contact, final Channel channel) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context).setPositiveButton(R.string.delete_conversation, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
AlTask.execute(new DeleteConversationAsyncTask(new MobiComConversationService(context), contact, channel, null, context));
}
});
alertDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
String name = "";
if (channel != null) {
if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
String userId = ChannelService.getInstance(context).getGroupOfTwoReceiverUserId(channel.getKey());
if (!TextUtils.isEmpty(userId)) {
Contact withUserContact = contactService.getContactById(userId);
name = withUserContact.getDisplayName();
}
} else {
name = ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(context).getUserId());
}
} else {
name = contact.getDisplayName();
}
alertDialog.setTitle(context.getString(R.string.dialog_delete_conversation_title).replace("[name]", name));
alertDialog.setMessage(context.getString(R.string.dialog_delete_conversation_confir).replace("[name]", name));
alertDialog.setCancelable(true);
alertDialog.create().show();
}
use of com.applozic.mobicomkit.api.conversation.MobiComConversationService in project Applozic-Android-SDK by AppLozic.
the class MessageServiceTest method setup.
@Before
public void setup() {
context = getTargetContext();
MockitoAnnotations.initMocks(this);
mobiComConversationService = new MobiComConversationService(context);
mobiComConversationService.setContactService(appContactService);
mobiComConversationService.setMessageClientService(messageClientService);
mobiComConversationService.setMessageDatabaseService(messageDatabaseService);
mobiComConversationService.setConversationService(conversationService);
}
use of com.applozic.mobicomkit.api.conversation.MobiComConversationService in project Applozic-Android-SDK by AppLozic.
the class MobiComPushReceiver method processMessage.
// the MqttMessageResponse objects used in this class are not actual MQTT responses, but just their data model is used
public static void processMessage(@NonNull Context context, @Nullable Bundle bundle, @Nullable 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, contactSync = null, muteAllNotificationResponse = null, groupMuteNotificationResponse = null, userActivated = null, userDeactivated = 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));
muteAllNotificationResponse = bundle.getString(notificationKeyList.get(33));
groupMuteNotificationResponse = bundle.getString(notificationKeyList.get(34));
userActivated = bundle.getString(notificationKeyList.get(17));
userDeactivated = bundle.getString(notificationKeyList.get(18));
} 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));
muteAllNotificationResponse = data.get(notificationKeyList.get(33));
groupMuteNotificationResponse = data.get(notificationKeyList.get(34));
userActivated = data.get(notificationKeyList.get(17));
userDeactivated = data.get(notificationKeyList.get(18));
}
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());
if (messageObj.getGroupId() != null && messageObj.isGroupDeleteAction()) {
syncCallService.deleteChannelConversationThread(messageObj.getGroupId());
BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), null, messageObj.getGroupId(), "success");
}
} 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 (isPushMessageForLoggedUserDelete(context, userDeleteNotification, response)) {
syncCallService.processLoggedUserDelete();
}
}
if (!TextUtils.isEmpty(messageMetadataUpdate)) {
String keyString = null;
String id = null;
try {
GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageMetadataUpdate, GcmMessageResponse.class);
keyString = messageResponse.getMessage().getKeyString();
Message messageObject = messageResponse.getMessage();
id = messageResponse.getId();
if (processPushNotificationId(id)) {
return;
}
addPushNotificationId(id);
syncCallService.syncMessageMetadataUpdate(keyString, true, messageObject);
} catch (Exception e) {
Utils.printLog(context, TAG, e.getMessage());
}
}
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();
}
}
if (!TextUtils.isEmpty(muteAllNotificationResponse)) {
try {
GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(muteAllNotificationResponse, GcmMessageResponse.class);
if (processPushNotificationId(messageResponse.getId())) {
return;
}
addPushNotificationId(messageResponse.getId());
if (messageResponse.getMessage() != null && messageResponse.getMessage().getMessage() != null) {
long notificationAfterTime = Long.parseLong(messageResponse.getMessage().getMessage());
ALSpecificSettings.getInstance(context).setNotificationAfterTime(notificationAfterTime);
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (!TextUtils.isEmpty(groupMuteNotificationResponse)) {
try {
InstantMessageResponse response = (InstantMessageResponse) GsonUtils.getObjectFromJson(groupMuteNotificationResponse, InstantMessageResponse.class);
if (processPushNotificationId(response.getId())) {
return;
}
addPushNotificationId(response.getId());
if (!TextUtils.isEmpty(response.getMessage())) {
String[] parts = response.getMessage().split(":");
if (parts.length > 0) {
Integer groupId = Integer.parseInt(parts[0]);
if (parts.length == 2) {
Long notificationMuteTillTime = Long.parseLong(parts[1]);
ChannelService.getInstance(context).updateNotificationAfterTime(groupId, notificationMuteTillTime);
BroadcastService.sendUpdateGroupMuteForGroupId(context, groupId, BroadcastService.INTENT_ACTIONS.GROUP_MUTE.toString());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (!TextUtils.isEmpty(userActivated)) {
BroadcastService.sendUserActivatedBroadcast(context, AlMessageEvent.ActionType.USER_ACTIVATED);
}
if (!TextUtils.isEmpty(userDeactivated)) {
BroadcastService.sendUserActivatedBroadcast(context, AlMessageEvent.ActionType.USER_DEACTIVATED);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
Aggregations