use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class MobiComMessageService method processMessage.
public Message processMessage(final Message messageToProcess, String tofield) {
try {
if (!TextUtils.isEmpty(ApplozicClient.getInstance(context).getMessageMetaDataServiceName())) {
Class serviceName = Class.forName(ApplozicClient.getInstance(context).getMessageMetaDataServiceName());
Intent intentService = new Intent(context, serviceName);
if (Message.MetaDataType.HIDDEN.getValue().equals(messageToProcess.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
intentService.putExtra(MobiComKitConstants.MESSAGE, messageToProcess);
intentService.putExtra(MobiComKitConstants.HIDDEN, true);
MessageIntentService.enqueueWork(context, intentService, null);
return null;
} else if (Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(messageToProcess.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
BroadcastService.sendNotificationBroadcast(context, messageToProcess);
intentService.putExtra(MobiComKitConstants.MESSAGE, messageToProcess);
intentService.putExtra(MobiComKitConstants.PUSH_NOTIFICATION, true);
MessageIntentService.enqueueWork(context, intentService, null);
return null;
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Message message = prepareMessage(messageToProcess, tofield);
// download contacts in advance.
if (message.getGroupId() != null) {
Channel channel = ChannelService.getInstance(context).getChannelInfo(message.getGroupId());
if (channel == null) {
return null;
}
}
if (message.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
fileClientService.loadContactsvCard(message);
}
try {
List<String> messageKeys = new ArrayList<>();
if (message.getMetadata() != null && message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()) != null && !messageDatabaseService.isMessagePresent(message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()))) {
messageKeys.add(message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
}
if (messageKeys != null && messageKeys.size() > 0) {
Message[] replyMessageList = conversationService.getMessageListByKeyList(messageKeys);
if (replyMessageList != null) {
Message replyMessage = replyMessageList[0];
if (replyMessage != null) {
if (replyMessage.hasAttachment() && !(replyMessage.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
conversationService.setFilePathifExist(replyMessage);
}
if (replyMessage.getContentType() == Message.ContentType.CONTACT_MSG.getValue()) {
fileClientService.loadContactsvCard(replyMessage);
}
replyMessage.setReplyMessage(Message.ReplyMessage.HIDE_MESSAGE.getValue());
messageDatabaseService.createMessage(replyMessage);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (message.getType().equals(Message.MessageType.MT_INBOX.getValue())) {
addMTMessage(message);
} else if (message.getType().equals(Message.MessageType.MT_OUTBOX.getValue())) {
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
messageDatabaseService.createMessage(message);
if (!message.getCurrentId().equals(BroadcastService.currentUserId)) {
MobiComUserPreference.getInstance(context).setNewMessageFlag(true);
}
if (message.isVideoNotificationMessage()) {
Utils.printLog(context, TAG, "Got notifications for Video call...");
VideoCallNotificationHelper helper = new VideoCallNotificationHelper(context);
helper.handleVideoCallNotificationMessages(message);
}
}
Utils.printLog(context, TAG, "processing message: " + message);
return message;
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class MobiComMessageService method processInstantMessage.
public synchronized void processInstantMessage(Message message) {
if (!message.hasAttachment()) {
if (!baseContactService.isContactPresent(message.getContactIds())) {
userService.processUserDetails(message.getContactIds());
}
Channel channel = ChannelService.getInstance(context).getChannelInfo(message.getGroupId());
if (channel == null) {
return;
}
BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
}
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ApplozicMqttIntentService method onHandleWork.
@Override
protected void onHandleWork(@NonNull Intent intent) {
if (intent == null) {
return;
}
boolean subscribe = intent.getBooleanExtra(SUBSCRIBE, false);
if (subscribe) {
ApplozicMqttService.getInstance(getApplicationContext()).subscribe();
}
Contact contact = (Contact) intent.getSerializableExtra(CONTACT);
Channel channel = (Channel) intent.getSerializableExtra(CHANNEL);
boolean subscribeToTyping = intent.getBooleanExtra(SUBSCRIBE_TO_TYPING, false);
if (subscribeToTyping) {
ApplozicMqttService.getInstance(getApplicationContext()).subscribeToTypingTopic(channel);
if (channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
ApplozicMqttService.getInstance(getApplicationContext()).subscribeToOpenGroupTopic(channel);
}
return;
}
boolean unSubscribeToTyping = intent.getBooleanExtra(UN_SUBSCRIBE_TO_TYPING, false);
if (unSubscribeToTyping) {
ApplozicMqttService.getInstance(getApplicationContext()).unSubscribeToTypingTopic(channel);
if (channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
ApplozicMqttService.getInstance(getApplicationContext()).unSubscribeToOpenGroupTopic(channel);
}
return;
}
String userKeyString = intent.getStringExtra(USER_KEY_STRING);
String deviceKeyString = intent.getStringExtra(DEVICE_KEY_STRING);
if (!TextUtils.isEmpty(userKeyString) && !TextUtils.isEmpty(deviceKeyString)) {
ApplozicMqttService.getInstance(getApplicationContext()).disconnectPublish(userKeyString, deviceKeyString, "0");
}
boolean connectedStatus = intent.getBooleanExtra(CONNECTED_PUBLISH, false);
if (connectedStatus) {
ApplozicMqttService.getInstance(getApplicationContext()).connectPublish(MobiComUserPreference.getInstance(getApplicationContext()).getSuUserKeyString(), MobiComUserPreference.getInstance(getApplicationContext()).getDeviceKeyString(), "1");
}
if (contact != null) {
boolean stop = intent.getBooleanExtra(STOP_TYPING, false);
if (stop) {
ApplozicMqttService.getInstance(getApplicationContext()).typingStopped(contact, null);
}
}
if (contact != null && (contact.isBlocked() || contact.isBlockedBy())) {
return;
}
if (contact != null || channel != null) {
boolean typing = intent.getBooleanExtra(TYPING, false);
if (typing) {
ApplozicMqttService.getInstance(getApplicationContext()).typingStarted(contact, channel);
} else {
ApplozicMqttService.getInstance(getApplicationContext()).typingStopped(contact, channel);
}
}
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ConversationReadService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
if (intent == null) {
return;
}
MessageClientService messageClientService = new MessageClientService(getApplicationContext());
Integer unreadCount = intent.getIntExtra(UNREAD_COUNT, 0);
boolean singleMessageRead = intent.getBooleanExtra(SINGLE_MESSAGE_READ, false);
Contact contact = (Contact) intent.getSerializableExtra(CONTACT);
Channel channel = (Channel) intent.getSerializableExtra(CHANNEL);
if (unreadCount != 0) {
Intent readIntent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(readIntent);
}
if (unreadCount != 0 || singleMessageRead) {
messageClientService.updateReadStatus(contact, channel);
}
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelService method processChannelList.
public synchronized void processChannelList(List<ChannelFeed> channelFeedList) {
if (channelFeedList != null && channelFeedList.size() > 0) {
for (ChannelFeed channelFeed : channelFeedList) {
Set<String> memberUserIds = channelFeed.getMembersName();
Set<String> userIds = new HashSet<>();
Channel channel = getChannel(channelFeed);
if (channelDatabaseService.isChannelPresent(channel.getKey())) {
channelDatabaseService.updateChannel(channel);
channelDatabaseService.deleteChannelUserMappers(channel.getKey());
} else {
channelDatabaseService.addChannel(channel);
}
if (memberUserIds != null && memberUserIds.size() > 0) {
for (String userId : memberUserIds) {
ChannelUserMapper channelUserMapper = new ChannelUserMapper(channelFeed.getId(), userId);
channelDatabaseService.addChannelUserMapper(channelUserMapper);
if (!baseContactService.isContactExists(userId)) {
userIds.add(userId);
}
}
if (userIds != null && userIds.size() > 0) {
userService.processUserDetailsByUserIds(userIds);
}
}
if (channelFeed.getGroupUsers() != null && channelFeed.getGroupUsers().size() > 0) {
for (ChannelUsersFeed channelUsers : channelFeed.getGroupUsers()) {
if (channelUsers.getRole() != null) {
channelDatabaseService.updateRoleInChannelUserMapper(channelFeed.getId(), channelUsers.getUserId(), channelUsers.getRole());
}
}
}
}
}
}
Aggregations