Search in sources :

Example 1 with CometChat

use of com.cometchat.pro.core.CometChat in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatThreadMessageList method sendMessage.

/**
 * This method is used to send Text Message to other users and groups.
 *
 * @param message is a String which is been sent as message.
 * @see TextMessage
 * @see CometChat#sendMessage(TextMessage, CometChat.CallbackListener)
 */
private void sendMessage(String message) {
    TextMessage textMessage;
    if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        textMessage = new TextMessage(Id, message, CometChatConstants.RECEIVER_TYPE_USER);
    else
        textMessage = new TextMessage(Id, message, CometChatConstants.RECEIVER_TYPE_GROUP);
    textMessage.setParentMessageId(parentId);
    sendTypingIndicator(true);
    textMessage.setCategory(CometChatConstants.CATEGORY_MESSAGE);
    textMessage.setSender(loggedInUser);
    textMessage.setMuid(System.currentTimeMillis() + "");
    if (messageAdapter != null) {
        MediaUtils.playSendSound(context, R.raw.outgoing_message);
        messageAdapter.addMessage(textMessage);
        scrollToBottom();
    }
    noReplyMessages.setVisibility(GONE);
    isSmartReplyClicked = false;
    CometChat.sendMessage(textMessage, new CometChat.CallbackListener<TextMessage>() {

        @Override
        public void onSuccess(TextMessage textMessage) {
            if (messageAdapter != null) {
                setReply();
                messageAdapter.updateChangedMessage(textMessage);
            }
        }

        @Override
        public void onError(CometChatException e) {
            if (messageAdapter != null) {
                textMessage.setSentAt(-1);
                messageAdapter.updateChangedMessage(textMessage);
            }
            if (getActivity() != null) {
                CometChatSnackBar.show(context, rvChatListView, CometChatError.localized(e), CometChatSnackBar.ERROR);
            }
            Log.d(TAG, "onError: " + e.getMessage());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) CometChat(com.cometchat.pro.core.CometChat) TextMessage(com.cometchat.pro.models.TextMessage)

Example 2 with CometChat

use of com.cometchat.pro.core.CometChat in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatThreadMessageList method sendMediaMessage.

/**
 * This method is used to send media messages to other users and group.
 *
 * @param file     is an object of File which is been sent within the message.
 * @param filetype is a string which indicate a type of file been sent within the message.
 * @see CometChat#sendMediaMessage(MediaMessage, CometChat.CallbackListener)
 * @see MediaMessage
 */
private void sendMediaMessage(File file, String filetype) {
    MediaMessage mediaMessage;
    if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        mediaMessage = new MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_USER);
    else
        mediaMessage = new MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_GROUP);
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("path", file.getAbsolutePath());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    mediaMessage.setMetadata(jsonObject);
    mediaMessage.setMuid("" + System.currentTimeMillis());
    mediaMessage.setCategory(CometChatConstants.CATEGORY_MESSAGE);
    mediaMessage.setSender(loggedInUser);
    if (messageAdapter != null) {
        messageAdapter.addMessage(mediaMessage);
        scrollToBottom();
    }
    mediaMessage.setParentMessageId(parentId);
    CometChat.sendMediaMessage(mediaMessage, new CometChat.CallbackListener<MediaMessage>() {

        @Override
        public void onSuccess(MediaMessage mediaMessage) {
            noReplyMessages.setVisibility(GONE);
            Log.d(TAG, "sendMediaMessage onSuccess: " + mediaMessage.toString());
            if (messageAdapter != null) {
                setReply();
                messageAdapter.updateChangedMessage(mediaMessage);
            }
        }

        @Override
        public void onError(CometChatException e) {
            if (messageAdapter != null) {
                mediaMessage.setSentAt(-1);
                messageAdapter.updateChangedMessage(mediaMessage);
            }
            if (getActivity() != null) {
                CometChatSnackBar.show(context, rvChatListView, CometChatError.localized(e), CometChatSnackBar.ERROR);
            }
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) MediaMessage(com.cometchat.pro.models.MediaMessage) JSONObject(org.json.JSONObject) CometChat(com.cometchat.pro.core.CometChat) JSONException(org.json.JSONException)

Example 3 with CometChat

use of com.cometchat.pro.core.CometChat in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatMessageList method editMessage.

/**
 * This method is used to edit the message. This methods takes old message and change text of old
 * message with new message i.e String and update it.
 *
 * @param baseMessage is an object of BaseMessage, It is a old message which is going to be edited.
 * @param message     is String, It is a new message which will be replaced with text of old message.
 * @see TextMessage
 * @see BaseMessage
 * @see CometChat#editMessage(BaseMessage, CometChat.CallbackListener)
 */
private void editMessage(BaseMessage baseMessage, String message) {
    isEdit = false;
    TextMessage textMessage;
    if (baseMessage.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        textMessage = new TextMessage(baseMessage.getReceiverUid(), message, CometChatConstants.RECEIVER_TYPE_USER);
    else
        textMessage = new TextMessage(baseMessage.getReceiverUid(), message, CometChatConstants.RECEIVER_TYPE_GROUP);
    sendTypingIndicator(true);
    textMessage.setId(baseMessage.getId());
    CometChat.editMessage(textMessage, new CometChat.CallbackListener<BaseMessage>() {

        @Override
        public void onSuccess(BaseMessage message) {
            if (messageAdapter != null) {
                Log.e(TAG, "onSuccess: " + message.toString());
                messageAdapter.setUpdatedMessage(message);
            }
        }

        @Override
        public void onError(CometChatException e) {
            Log.d(TAG, "onError: " + e.getMessage());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) BaseMessage(com.cometchat.pro.models.BaseMessage) CometChat(com.cometchat.pro.core.CometChat) TextMessage(com.cometchat.pro.models.TextMessage)

Example 4 with CometChat

use of com.cometchat.pro.core.CometChat in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatMessageList method sendMediaMessage.

/**
 * This method is used to send media messages to other users and group.
 *
 * @param file     is an object of File which is been sent within the message.
 * @param filetype is a string which indicate a type of file been sent within the message.
 * @see CometChat#sendMediaMessage(MediaMessage, CometChat.CallbackListener)
 * @see MediaMessage
 */
private void sendMediaMessage(File file, String filetype) {
    MediaMessage mediaMessage;
    if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        mediaMessage = new MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_USER);
    else
        mediaMessage = new MediaMessage(Id, file, filetype, CometChatConstants.RECEIVER_TYPE_GROUP);
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("path", file.getAbsolutePath());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    mediaMessage.setMetadata(jsonObject);
    mediaMessage.setMuid("" + System.currentTimeMillis());
    mediaMessage.setCategory(CometChatConstants.CATEGORY_MESSAGE);
    mediaMessage.setSender(loggedInUser);
    if (messageAdapter != null) {
        messageAdapter.addMessage(mediaMessage);
        scrollToBottom();
    }
    CometChat.sendMediaMessage(mediaMessage, new CometChat.CallbackListener<MediaMessage>() {

        @Override
        public void onSuccess(MediaMessage mediaMessage) {
            Log.d(TAG, "sendMediaMessage onSuccess: " + mediaMessage.toString());
            if (messageAdapter != null) {
                messageAdapter.updateChangedMessage(mediaMessage);
                rvSmartReply.setVisibility(GONE);
            }
        }

        @Override
        public void onError(CometChatException e) {
            e.printStackTrace();
            if (messageAdapter != null) {
                mediaMessage.setSentAt(-1);
                messageAdapter.updateChangedMessage(mediaMessage);
            }
            if (getActivity() != null) {
                CometChatSnackBar.show(context, rvChatListView, e.getMessage(), CometChatSnackBar.ERROR);
            }
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) MediaMessage(com.cometchat.pro.models.MediaMessage) JSONObject(org.json.JSONObject) CometChat(com.cometchat.pro.core.CometChat) JSONException(org.json.JSONException)

Example 5 with CometChat

use of com.cometchat.pro.core.CometChat in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatThreadMessageList method editMessage.

/**
 * This method is used to edit the message. This methods takes old message and change text of old
 * message with new message i.e String and update it.
 *
 * @param baseMessage is an object of BaseMessage, It is a old message which is going to be edited.
 * @param message     is String, It is a new message which will be replaced with text of old message.
 * @see TextMessage
 * @see BaseMessage
 * @see CometChat#editMessage(BaseMessage, CometChat.CallbackListener)
 */
private void editMessage(BaseMessage baseMessage, String message) {
    isEdit = false;
    isParent = true;
    TextMessage textMessage;
    if (baseMessage.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        textMessage = new TextMessage(baseMessage.getReceiverUid(), message, CometChatConstants.RECEIVER_TYPE_USER);
    else
        textMessage = new TextMessage(baseMessage.getReceiverUid(), message, CometChatConstants.RECEIVER_TYPE_GROUP);
    sendTypingIndicator(true);
    textMessage.setId(baseMessage.getId());
    CometChat.editMessage(textMessage, new CometChat.CallbackListener<BaseMessage>() {

        @Override
        public void onSuccess(BaseMessage message) {
            if (messageAdapter != null) {
                Log.e(TAG, "onSuccess: " + message.toString());
                messageAdapter.setUpdatedMessage(message);
            }
        }

        @Override
        public void onError(CometChatException e) {
            CometChatSnackBar.show(context, rvChatListView, CometChatError.localized(e), CometChatSnackBar.ERROR);
            Log.d(TAG, "onError: " + e.getMessage());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) BaseMessage(com.cometchat.pro.models.BaseMessage) CometChat(com.cometchat.pro.core.CometChat) TextMessage(com.cometchat.pro.models.TextMessage)

Aggregations

CometChat (com.cometchat.pro.core.CometChat)9 CometChatException (com.cometchat.pro.exceptions.CometChatException)9 TextMessage (com.cometchat.pro.models.TextMessage)4 ProgressDialog (android.app.ProgressDialog)2 BaseMessage (com.cometchat.pro.models.BaseMessage)2 MediaMessage (com.cometchat.pro.models.MediaMessage)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 Call (com.cometchat.pro.core.Call)1 User (com.cometchat.pro.models.User)1