Search in sources :

Example 26 with CometChatException

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

the class CometChatThreadMessageList method replyMessage.

/**
 * This method is used to send reply message by link previous message with new message.
 * @param baseMessage is a linked message
 * @param message is a String. It will be new message sent as reply.
 */
private void replyMessage(BaseMessage baseMessage, String message) {
    isReply = false;
    try {
        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);
        JSONObject jsonObject = new JSONObject();
        JSONObject replyObject = new JSONObject();
        if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
            replyObject.put("type", CometChatConstants.MESSAGE_TYPE_TEXT);
            replyObject.put("message", ((TextMessage) baseMessage).getText());
        } else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE)) {
            replyObject.put("type", CometChatConstants.MESSAGE_TYPE_IMAGE);
            replyObject.put("message", "image");
        } else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_VIDEO)) {
            replyObject.put("type", CometChatConstants.MESSAGE_TYPE_VIDEO);
            replyObject.put("message", "video");
        } else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_FILE)) {
            replyObject.put("type", CometChatConstants.MESSAGE_TYPE_FILE);
            replyObject.put("message", "file");
        } else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_AUDIO)) {
            replyObject.put("type", CometChatConstants.MESSAGE_TYPE_AUDIO);
            replyObject.put("message", "audio");
        }
        replyObject.put("name", baseMessage.getSender().getName());
        replyObject.put("avatar", baseMessage.getSender().getAvatar());
        jsonObject.put("reply", replyObject);
        textMessage.setParentMessageId(parentId);
        textMessage.setMetadata(jsonObject);
        sendTypingIndicator(true);
        CometChat.sendMessage(textMessage, new CometChat.CallbackListener<TextMessage>() {

            @Override
            public void onSuccess(TextMessage textMessage) {
                if (messageAdapter != null) {
                    MediaUtils.playSendSound(context, R.raw.outgoing_message);
                    messageAdapter.addMessage(textMessage);
                    scrollToBottom();
                }
            }

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

Example 27 with CometChatException

use of com.cometchat.pro.exceptions.CometChatException 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)

Example 28 with CometChatException

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

the class CometChatThreadMessageList method setReactionForParentMessage.

private void setReactionForParentMessage() {
    for (String key : reactionInfo.keySet()) {
        Chip chip = new Chip(context);
        chip.setChipStrokeWidth(2f);
        chip.setChipBackgroundColor(ColorStateList.valueOf(context.getResources().getColor(android.R.color.transparent)));
        chip.setChipStrokeColor(ColorStateList.valueOf(Color.parseColor(UIKitSettings.getColor())));
        chip.setText(key + " " + reactionInfo.get(key));
        reactionLayout.addView(chip);
        chip.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                JSONObject body = new JSONObject();
                try {
                    body.put("msgId", parentId);
                    body.put("emoji", key);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                CometChat.callExtension("reactions", "POST", "/v1/react", body, new CometChat.CallbackListener<JSONObject>() {

                    @Override
                    public void onSuccess(JSONObject responseObject) {
                        Log.e(TAG, "onSuccess: " + responseObject);
                    // ReactionModel added successfully.
                    }

                    @Override
                    public void onError(CometChatException e) {
                        CometChatSnackBar.show(context, rvChatListView, CometChatError.Extension.localized(e, "reactions"), CometChatSnackBar.ERROR);
                    // Some error occured.
                    }
                });
            }
        });
    }
    fetchSettings();
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONObject(org.json.JSONObject) Chip(com.google.android.material.chip.Chip) ImageView(android.widget.ImageView) NestedScrollView(androidx.core.widget.NestedScrollView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) VideoView(android.widget.VideoView) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException)

Example 29 with CometChatException

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

the class ThreadAdapter method setReactionSupport.

private void setReactionSupport(BaseMessage baseMessage, ChipGroup reactionLayout) {
    HashMap<String, String> reactionOnMessage = Extensions.getReactionsOnMessage(baseMessage);
    if (reactionOnMessage != null && reactionOnMessage.size() > 0) {
        reactionLayout.setVisibility(View.VISIBLE);
        reactionLayout.removeAllViews();
        for (String str : reactionOnMessage.keySet()) {
            // if (reactionLayout.getChildCount()<reactionOnMessage.size()) {
            Chip chip = new Chip(context);
            chip.setChipStrokeWidth(2f);
            chip.setChipBackgroundColor(ColorStateList.valueOf(context.getResources().getColor(android.R.color.transparent)));
            chip.setChipStrokeColor(ColorStateList.valueOf(Color.parseColor(UIKitSettings.getColor())));
            chip.setText(str + " " + reactionOnMessage.get(str));
            reactionLayout.addView(chip);
            chip.setOnLongClickListener(new View.OnLongClickListener() {

                @Override
                public boolean onLongClick(View view) {
                    Intent intent = new Intent(context, CometChatReactionInfoActivity.class);
                    intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, baseMessage.getMetadata().toString());
                    context.startActivity(intent);
                    return true;
                }
            });
            chip.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    JSONObject body = new JSONObject();
                    try {
                        body.put("msgId", baseMessage.getId());
                        body.put("emoji", str);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    CometChat.callExtension("reactions", "POST", "/v1/react", body, new CometChat.CallbackListener<JSONObject>() {

                        @Override
                        public void onSuccess(JSONObject responseObject) {
                        // ReactionModel added successfully.
                        }

                        @Override
                        public void onError(CometChatException e) {
                        // Some error occured.
                        }
                    });
                }
            });
        // }
        }
    }
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) Intent(android.content.Intent) Chip(com.google.android.material.chip.Chip) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) MaterialCardView(com.google.android.material.card.MaterialCardView) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) CometChatReactionInfoActivity(com.cometchat.pro.uikit.ui_components.messages.extensions.Reactions.CometChatReactionInfoActivity)

Example 30 with CometChatException

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

the class CometChatMessageList method sendReaction.

private void sendReaction(Reaction reaction) {
    JSONObject body = new JSONObject();
    try {
        body.put("msgId", baseMessage.getId());
        body.put("emoji", reaction.getName());
    } catch (JSONException e) {
        e.printStackTrace();
    }
    CometChat.callExtension("reactions", "POST", "/v1/react", body, new CometChat.CallbackListener<JSONObject>() {

        @Override
        public void onSuccess(JSONObject responseObject) {
            Log.e(TAG, "onSuccess: " + responseObject.toString());
        // ReactionModel added successfully.
        }

        @Override
        public void onError(CometChatException e) {
            Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
            Log.e(TAG, "onError: " + e.getCode() + e.getMessage() + e.getDetails());
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONObject(org.json.JSONObject) CometChat(com.cometchat.pro.core.CometChat) JSONException(org.json.JSONException)

Aggregations

CometChatException (com.cometchat.pro.exceptions.CometChatException)54 CometChat (com.cometchat.pro.core.CometChat)45 JSONObject (org.json.JSONObject)20 JSONException (org.json.JSONException)19 Intent (android.content.Intent)14 ArrayList (java.util.ArrayList)13 ProgressDialog (android.app.ProgressDialog)12 User (com.cometchat.pro.models.User)10 View (android.view.View)9 TextView (android.widget.TextView)9 TextMessage (com.cometchat.pro.models.TextMessage)9 List (java.util.List)8 ImageView (android.widget.ImageView)7 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 BaseMessage (com.cometchat.pro.models.BaseMessage)6 Call (com.cometchat.pro.core.Call)5 MediaMessage (com.cometchat.pro.models.MediaMessage)5 UsersRequest (com.cometchat.pro.core.UsersRequest)4 CometChatReactionDialog (com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog)4 MaterialCardView (com.google.android.material.card.MaterialCardView)4