Search in sources :

Example 16 with CometChatException

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

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

the class CometChatThreadMessageList method editThread.

private void editThread(String editMessage) {
    isEdit = false;
    TextMessage textmessage;
    if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        textmessage = new TextMessage(Id, editMessage, CometChatConstants.RECEIVER_TYPE_USER);
    else
        textmessage = new TextMessage(Id, editMessage, CometChatConstants.RECEIVER_TYPE_GROUP);
    sendTypingIndicator(true);
    textmessage.setId(parentId);
    CometChat.editMessage(textmessage, new CometChat.CallbackListener<BaseMessage>() {

        @Override
        public void onSuccess(BaseMessage baseMessage) {
            textMessage.setText(((TextMessage) baseMessage).getText());
            message = ((TextMessage) baseMessage).getText();
        }

        @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 18 with CometChatException

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

the class CometChatGroupList method searchGroup.

/**
 *  This method is used to search groups present in your App_ID.
 *  For more detail please visit our official documentation {@link "https://prodocs.cometchat.com/docs/android-groups-retrieve-groups" }
 *
 * @param s is a string used to get groups matches with this string.
 * @see GroupsRequest
 */
private void searchGroup(String s) {
    GroupsRequest groupsRequest = new GroupsRequest.GroupsRequestBuilder().setSearchKeyWord(s).setLimit(100).build();
    groupsRequest.fetchNext(new CometChat.CallbackListener<List<Group>>() {

        @Override
        public void onSuccess(List<Group> groups) {
            // sets the groups in rvGroupList i.e CometChatGroupList Component.
            rvGroupList.searchGroupList(groups);
        }

        @Override
        public void onError(CometChatException e) {
            Toast.makeText(getContext(), CometChatError.localized(e), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : GroupsRequest(com.cometchat.pro.core.GroupsRequest) CometChatException(com.cometchat.pro.exceptions.CometChatException) Group(com.cometchat.pro.models.Group) ViewGroup(android.view.ViewGroup) CometChat(com.cometchat.pro.core.CometChat) ArrayList(java.util.ArrayList) ColorStateList(android.content.res.ColorStateList) List(java.util.List)

Example 19 with CometChatException

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

the class Extensions method translateSmartReplyMessage.

public static List<String> translateSmartReplyMessage(BaseMessage baseMessage, JSONObject replyObject, ExtensionResponseListener extensionResponseListener) {
    List<String> resultList = new ArrayList<>();
    try {
        for (int i = 0; i < replyObject.length(); i++) {
            String localeLanguage = Locale.getDefault().getLanguage();
            JSONObject body = new JSONObject();
            JSONArray languages = new JSONArray();
            languages.put(localeLanguage);
            body.put("msgId", baseMessage.getId());
            body.put("languages", languages);
            if (i == 0)
                body.put("text", replyObject.getString("reply_positive"));
            else if (i == 1)
                body.put("text", replyObject.getString("reply_neutral"));
            else
                body.put("text", replyObject.getString("reply_negative"));
            final String str = body.getString("text");
            CometChat.callExtension("message-translation", "POST", "/v2/translate", body, new CometChat.CallbackListener<JSONObject>() {

                @Override
                public void onSuccess(JSONObject jsonObject) {
                    if (Extensions.isMessageTranslated(jsonObject, str)) {
                        String translatedMessage = Extensions.getTextFromTranslatedMessage(jsonObject, str);
                        resultList.add(translatedMessage);
                    } else {
                        Log.e(TAG, "onSuccess: No Translation available");
                    }
                }

                @Override
                public void onError(CometChatException e) {
                    Log.e(TAG, "onError: " + e.getMessage() + "\n" + e.getCode());
                }
            });
        }
        extensionResponseListener.OnResponseSuccess(resultList);
    } catch (Exception e) {
        extensionResponseListener.OnResponseFailed(new CometChatException("ERR_TRANSLATION_FAILED", "Not able to translate smart reply"));
        Log.e(TAG, "translateSmartReplyMessage: " + e.getMessage());
    }
    return resultList;
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONObject(org.json.JSONObject) CometChat(com.cometchat.pro.core.CometChat) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException)

Example 20 with CometChatException

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

the class Extensions method callWriteBoardExtension.

public static void callWriteBoardExtension(String receiverId, String receiverType, ExtensionResponseListener extensionResponseListener) {
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("receiver", receiverId);
        jsonObject.put("receiverType", receiverType);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    CometChat.callExtension("document", "POST", "/v1/create", jsonObject, new CometChat.CallbackListener<JSONObject>() {

        @Override
        public void onSuccess(JSONObject jsonObject) {
            extensionResponseListener.OnResponseSuccess(jsonObject);
        }

        @Override
        public void onError(CometChatException e) {
            extensionResponseListener.OnResponseFailed(e);
        }
    });
}
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