Search in sources :

Example 1 with Channel

use of com.applozic.mobicommons.people.channel.Channel 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();
        }*/
}
Also used : MessageResponse(com.applozic.mobicomkit.feed.MessageResponse) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Channel(com.applozic.mobicommons.people.channel.Channel) ArrayList(java.util.ArrayList) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Contact(com.applozic.mobicommons.people.contact.Contact) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta) JsonParser(com.google.gson.JsonParser)

Example 2 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class NotificationService method notifyUser.

public void notifyUser(Contact contact, Channel channel, Message message) {
    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 {
            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;
    Intent intent;
    if (count < 2) {
        intent = new Intent(context, activity);
        intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
    } else {
        intent = new Intent(context, activity);
        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, MobiComKitConstants.AL_PUSH_NOTIFICATION).setSmallIcon(smallIconResourceId).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(NotificationCompat.PRIORITY_MAX).setWhen(System.currentTimeMillis());
    mBuilder.setSound(TextUtils.isEmpty(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()));
    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()) {
        mBuilder.setVibrate(pattern);
    }
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    // Sets a title for the Inbox in expanded layout
    inboxStyle.setBigContentTitle(getNotificationTitle(count, contact, channel));
    // 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(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(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));
    mBuilder.setStyle(inboxStyle);
    if (message.hasAttachment()) {
        try {
            InputStream in;
            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) {
                    in = httpConn.getInputStream();
                    Bitmap bitmap = BitmapFactory.decodeStream(in);
                    String imageName = FileUtils.getName(fileMeta.getName()) + message.getCreatedAtTime() + "." + FileUtils.getFileFormat(fileMeta.getName());
                    File file = FileClientService.getFilePath(imageName, context, "image", true);
                    ImageUtils.saveImageToInternalStorage(file, bitmap);
                    if (unReadMessageList != null && unReadMessageList.size() < 2) {
                        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, NOTIFICATION_ID);
    notificationWithVoice.setCurrentContext(context);
    notificationWithVoice.setPendingIntent(pendingIntent);
    try {
        if (unReadMessageList != null && unReadMessageList.size() > 0) {
            notificationWithVoice.sendNotification();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) InputStream(java.io.InputStream) Channel(com.applozic.mobicommons.people.channel.Channel) MobiComKitClientService(com.applozic.mobicomkit.api.MobiComKitClientService) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Contact(com.applozic.mobicommons.people.contact.Contact) Bitmap(android.graphics.Bitmap) HttpURLConnection(java.net.HttpURLConnection) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) File(java.io.File) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta)

Example 3 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class ConversationRunnables method syncConversation.

private void syncConversation() {
    try {
        MobiComConversationService mobiComConversationService = new MobiComConversationService(context);
        List<Message> messages = mobiComConversationService.getLatestMessagesGroupByPeople();
        UserService.getInstance(context).processSyncUserBlock();
        for (Message message : messages.subList(0, Math.min(PRE_FETCH_MESSAGES_FOR, messages.size()))) {
            Contact contact = null;
            Channel channel = null;
            if (message.getGroupId() != null) {
                channel = new Channel(message.getGroupId());
            } else {
                contact = new Contact(message.getContactIds());
            }
            mobiComConversationService.getMessagesWithNetworkMetaData(1L, null, contact, channel, null, true, false);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Channel(com.applozic.mobicommons.people.channel.Channel) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 4 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class ApplozicMqttService method messageArrived.

@Override
public void messageArrived(final String s, final MqttMessage mqttMessage) throws Exception {
    Utils.printLog(context, TAG, "Received MQTT message: " + new String(mqttMessage.getPayload()));
    try {
        if (!TextUtils.isEmpty(s) && s.startsWith(TYPINGTOPIC)) {
            String[] typingResponse = mqttMessage.toString().split(",");
            String applicationId = typingResponse[0];
            String userId = User.getDecodedUserId(typingResponse[1]);
            String isTypingStatus = typingResponse[2];
            BroadcastService.sendUpdateTypingBroadcast(context, BroadcastService.INTENT_ACTIONS.UPDATE_TYPING_STATUS.toString(), applicationId, userId, isTypingStatus);
        } else {
            Thread thread = new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        final MqttMessageResponse mqttMessageResponse;
                        String messageDataString = null;
                        if (!TextUtils.isEmpty(MobiComUserPreference.getInstance(context).getUserEncryptionKey()) && !TextUtils.isEmpty(s) && s.startsWith(MQTT_ENCRYPTION_TOPIC)) {
                            if (!TextUtils.isEmpty(MobiComUserPreference.getInstance(context).getUserEncryptionKey())) {
                                messageDataString = EncryptionUtils.decrypt(MobiComUserPreference.getInstance(context).getUserEncryptionKey(), mqttMessage.toString());
                            }
                            if (TextUtils.isEmpty(messageDataString.trim())) {
                                return;
                            }
                            mqttMessageResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(messageDataString, MqttMessageResponse.class);
                        } else {
                            messageDataString = mqttMessage.toString();
                            mqttMessageResponse = (MqttMessageResponse) GsonUtils.getObjectFromJson(messageDataString, MqttMessageResponse.class);
                        }
                        if (mqttMessageResponse != null) {
                            if (MobiComPushReceiver.processPushNotificationId(mqttMessageResponse.getId())) {
                                return;
                            }
                            final SyncCallService syncCallService = SyncCallService.getInstance(context);
                            MobiComPushReceiver.addPushNotificationId(mqttMessageResponse.getId());
                            AlEventManager.getInstance().postMqttEventData(mqttMessageResponse);
                            Utils.printLog(context, TAG, "MQTT message type: " + mqttMessageResponse.getType());
                            if (NOTIFICATION_TYPE.MESSAGE_RECEIVED.getValue().equals(mqttMessageResponse.getType()) || "MESSAGE_RECEIVED".equals(mqttMessageResponse.getType())) {
                                GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageDataString, GcmMessageResponse.class);
                                if (messageResponse == null) {
                                    return;
                                }
                                Message message = messageResponse.getMessage();
                                if (message.getGroupId() != null) {
                                    Channel channel = ChannelService.getInstance(context).getChannelByChannelKey(message.getGroupId());
                                    if (channel != null && Channel.GroupType.OPEN.getValue().equals(channel.getType())) {
                                        if (!MobiComUserPreference.getInstance(context).getDeviceKeyString().equals(message.getDeviceKeyString())) {
                                            syncCallService.syncMessages(message.getKeyString(), message);
                                        }
                                    } else {
                                        if (message.isGroupDeleteAction()) {
                                            syncCallService.deleteChannelConversationThread(message.getGroupId());
                                            BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), null, message.getGroupId(), "success");
                                        }
                                        syncCallService.syncMessages(null);
                                    }
                                } else {
                                    syncCallService.syncMessages(null);
                                }
                            }
                            if (NOTIFICATION_TYPE.MESSAGE_DELIVERED.getValue().equals(mqttMessageResponse.getType()) || "MT_MESSAGE_DELIVERED".equals(mqttMessageResponse.getType())) {
                                String[] splitKeyString = (mqttMessageResponse.getMessage()).toString().split(",");
                                String keyString = splitKeyString[0];
                                // String userId = splitKeyString[1];
                                syncCallService.updateDeliveryStatus(keyString);
                            }
                            if (NOTIFICATION_TYPE.MESSAGE_DELIVERED_AND_READ.getValue().equals(mqttMessageResponse.getType()) || "MT_MESSAGE_DELIVERED_READ".equals(mqttMessageResponse.getType())) {
                                String[] splitKeyString = (mqttMessageResponse.getMessage()).toString().split(",");
                                String keyString = splitKeyString[0];
                                syncCallService.updateReadStatus(keyString);
                            }
                            if (NOTIFICATION_TYPE.CONVERSATION_DELIVERED_AND_READ.getValue().equals(mqttMessageResponse.getType())) {
                                String contactId = mqttMessageResponse.getMessage().toString();
                                syncCallService.updateDeliveryStatusForContact(contactId, true);
                            }
                            if (NOTIFICATION_TYPE.CONVERSATION_READ.getValue().equals(mqttMessageResponse.getType())) {
                                syncCallService.updateConversationReadStatus(mqttMessageResponse.getMessage().toString(), false);
                            }
                            if (NOTIFICATION_TYPE.GROUP_CONVERSATION_READ.getValue().equals(mqttMessageResponse.getType())) {
                                InstantMessageResponse instantMessageResponse = (InstantMessageResponse) GsonUtils.getObjectFromJson(messageDataString, InstantMessageResponse.class);
                                syncCallService.updateConversationReadStatus(instantMessageResponse.getMessage(), true);
                            }
                            if (NOTIFICATION_TYPE.USER_CONNECTED.getValue().equals(mqttMessageResponse.getType())) {
                                syncCallService.updateConnectedStatus(mqttMessageResponse.getMessage().toString(), new Date(), true);
                            }
                            if (NOTIFICATION_TYPE.USER_DISCONNECTED.getValue().equals(mqttMessageResponse.getType())) {
                                // disconnect comes with timestamp, ranjeet,1449866097000
                                String[] parts = mqttMessageResponse.getMessage().toString().split(",");
                                String userId = parts[0];
                                Date lastSeenAt = new Date();
                                if (parts.length >= 2 && !parts[1].equals("null")) {
                                    lastSeenAt = new Date(Long.parseLong(parts[1]));
                                }
                                syncCallService.updateConnectedStatus(userId, lastSeenAt, false);
                            }
                            if (NOTIFICATION_TYPE.CONVERSATION_DELETED.getValue().equals(mqttMessageResponse.getType())) {
                                syncCallService.deleteConversationThread(mqttMessageResponse.getMessage().toString());
                                BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), mqttMessageResponse.getMessage().toString(), 0, "success");
                            }
                            if (NOTIFICATION_TYPE.GROUP_CONVERSATION_DELETED.getValue().equals(mqttMessageResponse.getType())) {
                                InstantMessageResponse instantMessageResponse = (InstantMessageResponse) GsonUtils.getObjectFromJson(messageDataString, InstantMessageResponse.class);
                                syncCallService.deleteChannelConversationThread(instantMessageResponse.getMessage());
                                BroadcastService.sendConversationDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString(), null, Integer.valueOf(instantMessageResponse.getMessage()), "success");
                            }
                            if (NOTIFICATION_TYPE.MESSAGE_DELETED.getValue().equals(mqttMessageResponse.getType())) {
                                String messageKey = mqttMessageResponse.getMessage().toString().split(",")[0];
                                syncCallService.deleteMessage(messageKey);
                                BroadcastService.sendMessageDeleteBroadcast(context, BroadcastService.INTENT_ACTIONS.DELETE_MESSAGE.toString(), messageKey, null);
                            }
                            if (NOTIFICATION_TYPE.MESSAGE_SENT.getValue().equals(mqttMessageResponse.getType())) {
                                GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageDataString, GcmMessageResponse.class);
                                Message sentMessageSync = messageResponse.getMessage();
                                syncCallService.syncMessages(sentMessageSync.getKeyString());
                            }
                            if (NOTIFICATION_TYPE.USER_BLOCKED.getValue().equals(mqttMessageResponse.getType()) || NOTIFICATION_TYPE.USER_UN_BLOCKED.getValue().equals(mqttMessageResponse.getType())) {
                                syncCallService.syncBlockUsers();
                            }
                            if (NOTIFICATION_TYPE.USER_DETAIL_CHANGED.getValue().equals(mqttMessageResponse.getType()) || NOTIFICATION_TYPE.USER_DELETE_NOTIFICATION.getValue().equals(mqttMessageResponse.getType())) {
                                String userId = mqttMessageResponse.getMessage().toString();
                                syncCallService.syncUserDetail(userId);
                                if (isMqttResponseForLoggedInUserDelete(context, mqttMessageResponse)) {
                                    syncCallService.processLoggedUserDelete();
                                }
                            }
                            if (NOTIFICATION_TYPE.MESSAGE_METADATA_UPDATE.getValue().equals(mqttMessageResponse.getType())) {
                                try {
                                    GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageDataString, GcmMessageResponse.class);
                                    String keyString = messageResponse.getMessage().getKeyString();
                                    Message messageObject = messageResponse.getMessage();
                                    syncCallService.syncMessageMetadataUpdate(keyString, false, messageObject);
                                } catch (Exception e) {
                                    Utils.printLog(context, TAG, e.getMessage());
                                }
                            }
                            if (NOTIFICATION_TYPE.USER_MUTE_NOTIFICATION.getValue().equals(mqttMessageResponse.getType())) {
                                try {
                                    InstantMessageResponse response = (InstantMessageResponse) GsonUtils.getObjectFromJson(messageDataString, InstantMessageResponse.class);
                                    if (response.getMessage() != null) {
                                        String muteFlag = String.valueOf(response.getMessage().charAt(response.getMessage().length() - 1));
                                        if ("1".equals(muteFlag)) {
                                            syncCallService.syncMutedUserList(false, null);
                                        } else if ("0".equals(muteFlag)) {
                                            String userId = response.getMessage().substring(0, response.getMessage().length() - 2);
                                            syncCallService.syncMutedUserList(false, userId);
                                        }
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            if (NOTIFICATION_TYPE.MUTE_NOTIFICATIONS.getValue().equals(mqttMessageResponse.getType())) {
                                try {
                                    GcmMessageResponse messageResponse = (GcmMessageResponse) GsonUtils.getObjectFromJson(messageDataString, GcmMessageResponse.class);
                                    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 (NOTIFICATION_TYPE.GROUP_MUTE_NOTIFICATION.getValue().equals(mqttMessageResponse.getType())) {
                                try {
                                    InstantMessageResponse response = (InstantMessageResponse) GsonUtils.getObjectFromJson(messageDataString, InstantMessageResponse.class);
                                    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 (NOTIFICATION_TYPE.ACTIVATED.getValue().equals(mqttMessageResponse.getType())) {
                                BroadcastService.sendUserActivatedBroadcast(context, AlMessageEvent.ActionType.USER_ACTIVATED);
                            }
                            if (NOTIFICATION_TYPE.DEACTIVATED.getValue().equals(mqttMessageResponse.getType())) {
                                BroadcastService.sendUserActivatedBroadcast(context, AlMessageEvent.ActionType.USER_DEACTIVATED);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
            thread.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MqttMessage(org.eclipse.paho.client.mqttv3.MqttMessage) Message(com.applozic.mobicomkit.api.conversation.Message) MqttMessageResponse(com.applozic.mobicomkit.feed.MqttMessageResponse) GcmMessageResponse(com.applozic.mobicomkit.feed.GcmMessageResponse) Channel(com.applozic.mobicommons.people.channel.Channel) InstantMessageResponse(com.applozic.mobicomkit.feed.InstantMessageResponse) Date(java.util.Date) MqttException(org.eclipse.paho.client.mqttv3.MqttException) SyncCallService(com.applozic.mobicomkit.api.conversation.SyncCallService)

Example 5 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class ChannelInfoActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    LocalBroadcastManager.getInstance(this).registerReceiver(mobiComKitBroadcastReceiver, BroadcastService.getIntentFilter());
    LocalBroadcastManager.getInstance(this).registerReceiver(refreshBroadcast, getIntentFilter());
    if (channel != null) {
        BroadcastService.currentInfoId = String.valueOf(channel.getKey());
        Channel newChannel = ChannelService.getInstance(this).getChannelByChannelKey(channel.getKey());
        if (newChannel != null && TextUtils.isEmpty(newChannel.getImageUrl())) {
            if (!channel.isBroadcastMessage()) {
                channelImage.setImageResource(R.drawable.applozic_group_icon);
            } else {
                channelImage.setImageResource(R.drawable.applozic_ic_applozic_broadcast);
            }
        }
    }
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel)

Aggregations

Channel (com.applozic.mobicommons.people.channel.Channel)70 Contact (com.applozic.mobicommons.people.contact.Contact)26 Intent (android.content.Intent)12 ChannelFeed (com.applozic.mobicomkit.feed.ChannelFeed)10 ArrayList (java.util.ArrayList)10 Message (com.applozic.mobicomkit.api.conversation.Message)8 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)7 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)7 SyncChannelFeed (com.applozic.mobicomkit.sync.SyncChannelFeed)7 ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)7 NonNull (androidx.annotation.NonNull)6 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)6 Context (android.content.Context)4 Cursor (android.database.Cursor)4 Bitmap (android.graphics.Bitmap)4 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)4 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)4 ChannelUsersFeed (com.applozic.mobicomkit.feed.ChannelUsersFeed)4 Conversation (com.applozic.mobicommons.people.channel.Conversation)4 JSONException (org.json.JSONException)4