Search in sources :

Example 11 with TextMessage

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

the class MessageAdapter method setTextData.

/**
 * This method is called whenever viewType of item is TextMessage. It is used to bind
 * TextMessageViewHolder content with TextMessage at given position.
 * It shows text of a message if deletedAt = 0 else it shows "message deleted"
 *
 * @param viewHolder is a object of TextMessageViewHolder.
 * @param i is postion of item in recyclerView.
 * @see TextMessage
 * @see BaseMessage
 */
private void setTextData(TextMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    if (baseMessage != null) {
        if (!baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
            if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
                viewHolder.tvUser.setVisibility(View.GONE);
                viewHolder.ivUser.setVisibility(View.GONE);
            } else if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP)) {
                if (isUserDetailVisible) {
                    viewHolder.tvUser.setVisibility(View.VISIBLE);
                    viewHolder.ivUser.setVisibility(View.VISIBLE);
                } else {
                    viewHolder.tvUser.setVisibility(View.GONE);
                    viewHolder.ivUser.setVisibility(View.INVISIBLE);
                }
                setAvatar(viewHolder.ivUser, baseMessage.getSender().getAvatar(), baseMessage.getSender().getName());
                viewHolder.tvUser.setText(baseMessage.getSender().getName());
            }
            boolean isSentimentNegative = Extensions.checkSentiment(baseMessage);
            if (isSentimentNegative) {
                viewHolder.txtMessage.setVisibility(View.GONE);
                viewHolder.sentimentVw.setVisibility(View.VISIBLE);
            } else {
                viewHolder.txtMessage.setVisibility(View.VISIBLE);
                viewHolder.sentimentVw.setVisibility(View.GONE);
            }
            viewHolder.viewSentimentMessage.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    AlertDialog.Builder sentimentAlert = new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.sentiment_alert)).setMessage(context.getResources().getString(R.string.sentiment_alert_message)).setPositiveButton(context.getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            viewHolder.txtMessage.setVisibility(View.VISIBLE);
                            viewHolder.sentimentVw.setVisibility(View.GONE);
                        }
                    }).setNegativeButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
                    sentimentAlert.create().show();
                }
            });
        }
        if (baseMessage.getMetadata() != null) {
            try {
                JSONObject metaData = baseMessage.getMetadata();
                if (metaData.has("reply-message")) {
                    JSONObject replyMessageJSON = metaData.getJSONObject("reply-message");
                    BaseMessage replyMessage = CometChatHelper.processMessage(replyMessageJSON);
                    String messageType = replyMessage.getType();
                    viewHolder.replyLayout.setVisibility(View.VISIBLE);
                    viewHolder.replyUser.setVisibility(View.VISIBLE);
                    if (replyMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER))
                        viewHolder.replyUser.setText(replyMessage.getSender().getName());
                    else
                        viewHolder.replyUser.setText(replyMessage.getSender().getName() + " ~ " + ((Group) replyMessage.getReceiver()).getName());
                    if (messageType.equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
                        String message = ((TextMessage) replyMessage).getText();
                        if (CometChat.isExtensionEnabled("profanity-filter")) {
                            message = Extensions.checkProfanityMessage(context, replyMessage);
                        }
                        if (CometChat.isExtensionEnabled("data-masking")) {
                            message = Extensions.checkDataMasking(context, replyMessage);
                        }
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(message);
                    } else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_IMAGE)) {
                        viewHolder.replyMessage.setText(context.getResources().getString(R.string.message_image));
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                    } else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_AUDIO)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getResources().getString(R.string.message_audio));
                    } else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_VIDEO)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getResources().getString(R.string.message_video));
                    } else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_FILE)) {
                        viewHolder.replyMessage.setText(context.getResources().getString(R.string.message_file));
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                    } else if (messageType.equals(UIKitConstants.IntentStrings.LOCATION)) {
                        viewHolder.replyMessage.setText(R.string.custom_message_location);
                        viewHolder.replyMessageImage.setImageResource(R.drawable.default_map);
                    } else if (messageType.equals(UIKitConstants.IntentStrings.POLLS)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getString(R.string.custom_message_poll));
                    } else if (messageType.equals(UIKitConstants.IntentStrings.STICKERS)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(String.format(context.getString(R.string.custom_message_sticker)));
                    } else if (messageType.equals(UIKitConstants.IntentStrings.WHITEBOARD)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getString(R.string.custom_message_whiteboard));
                    } else if (messageType.equals(UIKitConstants.IntentStrings.WRITEBOARD)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getString(R.string.custom_message_document));
                    } else if (messageType.equals(UIKitConstants.IntentStrings.GROUP_CALL)) {
                        viewHolder.replyMessageImage.setVisibility(View.GONE);
                        viewHolder.replyMessage.setText(context.getString(R.string.custom_message_meeting));
                    }
                    viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {

                        @Override
                        public boolean onLongClick(View view) {
                            if (!isImageMessageClick) {
                                isLongClickEnabled = true;
                                isTextMessageClick = true;
                                setLongClickSelectedItem(baseMessage);
                                messageLongClick.setLongMessageClick(longselectedItemList);
                                notifyItemChanged(i);
                            }
                            return true;
                        }
                    });
                } else {
                    viewHolder.replyLayout.setVisibility(View.GONE);
                }
            } catch (Exception e) {
                Log.e(TAG, "setTextData: " + e.getMessage());
            }
        }
        FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

            @Override
            public void onSuccess(Boolean booleanVal) {
                if (baseMessage.getReplyCount() != 0 && booleanVal) {
                    viewHolder.tvThreadReplyCount.setVisibility(View.VISIBLE);
                    viewHolder.tvThreadReplyCount.setText(baseMessage.getReplyCount() + " " + context.getResources().getString(R.string.replies));
                } else {
                    viewHolder.tvThreadReplyCount.setVisibility(View.GONE);
                }
            }
        });
        viewHolder.tvThreadReplyCount.setOnClickListener(view -> {
            Intent intent = new Intent(context, CometChatThreadMessageListActivity.class);
            // intent.putExtra(StringContract.IntentStrings.PARENT_BASEMESSAGE,baseMessage.toString());
            intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
            intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().getAvatar());
            intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount());
            intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getName());
            intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
            intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
            intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
            intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, ((TextMessage) baseMessage).getText());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory());
            intent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType());
            if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP)) {
                intent.putExtra(UIKitConstants.IntentStrings.GUID, baseMessage.getReceiverUid());
            } else {
                if (baseMessage.getReceiverUid().equals(loggedInUser.getUid()))
                    intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getUid());
                else
                    intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getReceiverUid());
            }
            context.startActivity(intent);
        });
        String txtMessage = ((TextMessage) baseMessage).getText().trim();
        viewHolder.txtMessage.setTextSize(16f);
        int count = 0;
        CharSequence processed = EmojiCompat.get().process(txtMessage, 0, txtMessage.length() - 1, Integer.MAX_VALUE, EmojiCompat.REPLACE_STRATEGY_ALL);
        if (processed instanceof Spannable) {
            Spannable spannable = (Spannable) processed;
            count = spannable.getSpans(0, spannable.length() - 1, EmojiSpan.class).length;
            if (PatternUtils.removeEmojiAndSymbol(txtMessage).trim().length() == 0) {
                int tempcount = count;
                FeatureRestriction.isLargeSizeEmojisEnabled(new FeatureRestriction.OnSuccessListener() {

                    @Override
                    public void onSuccess(Boolean booleanVal) {
                        if (booleanVal) {
                            if (tempcount == 1) {
                                viewHolder.txtMessage.setTextSize((int) Utils.dpToPx(context, 32));
                            } else if (tempcount == 2) {
                                viewHolder.txtMessage.setTextSize((int) Utils.dpToPx(context, 24));
                            }
                        }
                    }
                });
            }
        }
        String message = txtMessage;
        if (CometChat.isExtensionEnabled("profanity-filter")) {
            message = Extensions.checkProfanityMessage(context, baseMessage);
        }
        if (CometChat.isExtensionEnabled("data-masking")) {
            message = Extensions.checkDataMasking(context, baseMessage);
        }
        if (baseMessage.getMetadata() != null && baseMessage.getMetadata().has("values")) {
            try {
                if (Extensions.isMessageTranslated(baseMessage.getMetadata().getJSONObject("values"), ((TextMessage) baseMessage).getText())) {
                    String translatedMessage = Extensions.getTranslatedMessage(baseMessage);
                    message = message + "\n(" + translatedMessage + ")";
                }
            } catch (JSONException e) {
                Toast.makeText(context, context.getString(R.string.no_translation_available), Toast.LENGTH_SHORT).show();
            }
        }
        viewHolder.txtMessage.setText(message);
        viewHolder.txtMessage.setTypeface(fontUtils.getTypeFace(FontUtils.robotoRegular));
        PatternUtils.setHyperLinkSupport(context, viewHolder.txtMessage);
        viewHolder.txtMessage.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                if (!isImageMessageClick) {
                    isLongClickEnabled = true;
                    isTextMessageClick = true;
                    setLongClickSelectedItem(baseMessage);
                    messageLongClick.setLongMessageClick(longselectedItemList);
                    notifyItemChanged(i);
                }
                return true;
            }
        });
        if (baseMessage.getSender().getUid().equals(loggedInUser.getUid()))
            viewHolder.txtMessage.setTextColor(context.getResources().getColor(R.color.textColorWhite));
        else
            viewHolder.txtMessage.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
        showMessageTime(viewHolder, baseMessage);
        // if (messageList.get(messageList.size()-1).equals(baseMessage))
        // {
        // selectedItemList.add(baseMessage.getId());
        // }
        // if (selectedItemList.contains(baseMessage.getId()))
        viewHolder.txtTime.setVisibility(View.VISIBLE);
        // else
        // viewHolder.txtTime.setVisibility(View.GONE);
        setColorFilter(baseMessage, viewHolder.cvMessageView);
        // viewHolder.rlMessageBubble.setOnClickListener(view -> {
        // if (isLongClickEnabled && !isImageMessageClick) {
        // setLongClickSelectedItem(baseMessage);
        // messageLongClick.setLongMessageClick(longselectedItemList);
        // }
        // else {
        // setSelectedMessage(baseMessage.getId());
        // }
        // notifyDataSetChanged();
        // 
        // });
        // viewHolder.rlMessageBubble.setOnLongClickListener(new View.OnLongClickListener() {
        // @Override
        // public boolean onLongClick(View view) {
        // if (!isImageMessageClick) {
        // isLongClickEnabled = true;
        // isTextMessageClick = true;
        // setLongClickSelectedItem(baseMessage);
        // messageLongClick.setLongMessageClick(longselectedItemList);
        // notifyDataSetChanged();
        // }
        // return true;
        // }
        // });
        viewHolder.reactionLayout.setVisibility(View.GONE);
        setReactionSupport(baseMessage, viewHolder.reactionLayout);
        viewHolder.itemView.setTag(R.string.message, baseMessage);
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) JSONException(org.json.JSONException) Intent(android.content.Intent) 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) BaseMessage(com.cometchat.pro.models.BaseMessage) JSONObject(org.json.JSONObject) FeatureRestriction(com.cometchat.pro.uikit.ui_settings.FeatureRestriction) TextMessage(com.cometchat.pro.models.TextMessage) Spannable(android.text.Spannable)

Example 12 with TextMessage

use of com.cometchat.pro.models.TextMessage 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 13 with TextMessage

use of com.cometchat.pro.models.TextMessage 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 14 with TextMessage

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

the class CometChatMessageList method startThreadActivity.

private void startThreadActivity() {
    Intent intent = new Intent(getContext(), CometChatThreadMessageListActivity.class);
    intent.putExtra(UIKitConstants.IntentStrings.CONVERSATION_NAME, name);
    intent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
    intent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getName());
    intent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().getAvatar());
    intent.putExtra(UIKitConstants.IntentStrings.PARENT_ID, baseMessage.getId());
    intent.putExtra(UIKitConstants.IntentStrings.REPLY_COUNT, baseMessage.getReplyCount());
    intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
    intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
    if (baseMessage.getCategory().equalsIgnoreCase(CometChatConstants.CATEGORY_MESSAGE)) {
        intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
        if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT))
            intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, ((TextMessage) baseMessage).getText());
        else {
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((MediaMessage) baseMessage).getAttachment().getFileName());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, ((MediaMessage) baseMessage).getAttachment().getFileExtension());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_MIME_TYPE, ((MediaMessage) baseMessage).getAttachment().getFileMimeType());
        }
    } else {
        try {
            if (baseMessage.getType().equals(UIKitConstants.IntentStrings.LOCATION)) {
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.LOCATION);
                intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LATITUDE, ((CustomMessage) baseMessage).getCustomData().getDouble("latitude"));
                intent.putExtra(UIKitConstants.IntentStrings.LOCATION_LONGITUDE, ((CustomMessage) baseMessage).getCustomData().getDouble("longitude"));
            } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.STICKERS)) {
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((CustomMessage) baseMessage).getCustomData().getString("name"));
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((CustomMessage) baseMessage).getCustomData().getString("url"));
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.STICKERS);
            } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WHITEBOARD)) {
                intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWhiteBoardUrl(baseMessage));
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.WHITEBOARD);
            } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WRITEBOARD)) {
                intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWriteBoardUrl(baseMessage));
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.WRITEBOARD);
            } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.POLLS)) {
                JSONObject options = ((CustomMessage) baseMessage).getCustomData().getJSONObject("options");
                intent.putExtra(UIKitConstants.IntentStrings.POLL_QUESTION, ((CustomMessage) baseMessage).getCustomData().getString("question"));
                intent.putExtra(UIKitConstants.IntentStrings.POLL_OPTION, options.toString());
                intent.putExtra(UIKitConstants.IntentStrings.POLL_VOTE_COUNT, Extensions.getVoteCount(baseMessage));
                intent.putExtra(UIKitConstants.IntentStrings.POLL_RESULT, Extensions.getVoterInfo(baseMessage, options.length()));
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.POLLS);
            }
        } catch (Exception e) {
            Log.e(TAG, "startThreadActivityError: " + e.getMessage());
        }
    }
    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_CATEGORY, baseMessage.getCategory());
    intent.putExtra(UIKitConstants.IntentStrings.TYPE, type);
    if (type.equals(CometChatConstants.CONVERSATION_TYPE_GROUP)) {
        intent.putExtra(UIKitConstants.IntentStrings.GUID, Id);
    } else {
        intent.putExtra(UIKitConstants.IntentStrings.UID, Id);
    }
    startActivity(intent);
}
Also used : MediaMessage(com.cometchat.pro.models.MediaMessage) JSONObject(org.json.JSONObject) CustomMessage(com.cometchat.pro.models.CustomMessage) Intent(android.content.Intent) TextMessage(com.cometchat.pro.models.TextMessage) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException)

Example 15 with TextMessage

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

the class CometChatMessageList 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 replyObject = new JSONObject();
        replyObject.put("reply-message", baseMessage.getRawMessage());
        textMessage.setMetadata(replyObject);
        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();
        }
        isSmartReplyClicked = false;
        rvSmartReply.setVisibility(GONE);
        CometChat.sendMessage(textMessage, new CometChat.CallbackListener<TextMessage>() {

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

            @Override
            public void onError(CometChatException e) {
                if (e.getCode().equalsIgnoreCase("ERROR_INTERNET_UNAVAILABLE")) {
                    CometChatSnackBar.show(context, rvChatListView, getString(R.string.no_internet_available), CometChatSnackBar.ERROR);
                } else if (!e.getCode().equalsIgnoreCase("ERR_BLOCKED_BY_EXTENSION")) {
                    if (messageAdapter == null) {
                        Log.e(TAG, "onError: MessageAdapter is null");
                    } else {
                        textMessage.setSentAt(-1);
                        messageAdapter.updateChangedMessage(textMessage);
                    }
                } else if (messageAdapter != null) {
                    messageAdapter.remove(textMessage);
                }
            }
        });
    } 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)

Aggregations

TextMessage (com.cometchat.pro.models.TextMessage)19 CometChatException (com.cometchat.pro.exceptions.CometChatException)17 JSONObject (org.json.JSONObject)13 JSONException (org.json.JSONException)12 BaseMessage (com.cometchat.pro.models.BaseMessage)8 Intent (android.content.Intent)7 CometChat (com.cometchat.pro.core.CometChat)7 View (android.view.View)5 ImageView (android.widget.ImageView)5 MediaMessage (com.cometchat.pro.models.MediaMessage)5 TextView (android.widget.TextView)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 CardView (androidx.cardview.widget.CardView)3 CustomMessage (com.cometchat.pro.models.CustomMessage)3 User (com.cometchat.pro.models.User)3 FeatureRestriction (com.cometchat.pro.uikit.ui_settings.FeatureRestriction)3 ArrayList (java.util.ArrayList)3 ClipData (android.content.ClipData)2 ClipboardManager (android.content.ClipboardManager)2 Conversation (com.cometchat.pro.models.Conversation)2