Search in sources :

Example 1 with TextMessage

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

the class PushNotificationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_push_notification);
    if (!Utils.hasPermissions(this, permissions)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(permissions, UIKitConstants.RequestCode.RECORD);
        }
    }
    progressDialog = new ProgressDialog(this);
    progressDialog.setTitle(getResources().getString(R.string.please_wait));
    progressDialog.setMessage(getResources().getString(R.string.media_uploading));
    progressDialog.setCancelable(false);
    moreBtn = findViewById(R.id.more_btn);
    titleTv = findViewById(R.id.title_tv);
    messageTv = findViewById(R.id.message_tv);
    uid = findViewById(R.id.uid);
    uidLayout = findViewById(R.id.uid_layout);
    recieverType = findViewById(R.id.reciever_type);
    user = findViewById(R.id.users);
    group = findViewById(R.id.groups);
    message = findViewById(R.id.message);
    textMessage = findViewById(R.id.text_message);
    mediaMessage = findViewById(R.id.media_message);
    audioCall = findViewById(R.id.audio_call);
    videoCall = findViewById(R.id.video_call);
    customMessage = findViewById(R.id.custom_message);
    recieverType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup g, int checkedId) {
            if (user.isChecked()) {
                uidLayout.setHint(getResources().getString(R.string.enter_uid));
                receiver = CometChatConstants.RECEIVER_TYPE_USER;
            }
            if (group.isChecked()) {
                uidLayout.setHint(getResources().getString(R.string.enter_guid));
                receiver = CometChatConstants.RECEIVER_TYPE_GROUP;
            }
        }
    });
    moreBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MoreActionFragment moreActionFragment = new MoreActionFragment();
            moreActionFragment.show(getSupportFragmentManager(), moreActionFragment.getTag());
        }
    });
    textMessage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (uid.getText().toString().trim().isEmpty()) {
                uid.setError(getResources().getString(R.string.fill_this_field));
            } else if (message.getText().toString().isEmpty()) {
                message.setError(getResources().getString(R.string.fill_this_field));
            } else {
                // subscribePushNotification();
                TextMessage textMessage = new TextMessage(uid.getText().toString(), message.getText().toString(), receiver);
                sendMessage(textMessage);
                message.setText("");
            }
        }
    });
    mediaMessage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (uid.getText().toString().isEmpty())
                uid.setError(getResources().getString(R.string.fill_this_field));
            else {
                if (Utils.hasPermissions(PushNotificationActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE })) {
                    startActivityForResult(MediaUtils.openGallery(PushNotificationActivity.this), UIKitConstants.RequestCode.GALLERY);
                } else {
                    requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE }, UIKitConstants.RequestCode.GALLERY);
                }
            }
        }
    });
    customMessage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (uid.getText().toString().isEmpty())
                uid.setError(getResources().getString(R.string.fill_this_field));
            else {
                try {
                    // subscribePushNotification();
                    JSONObject customData = new JSONObject();
                    customData.put("latitude", "19.0760");
                    customData.put("longitude", "72.8777");
                    CustomMessage customMessage = new CustomMessage(uid.getText().toString(), receiver, "location", customData);
                    JSONObject metaData = new JSONObject();
                    metaData.put("pushNotification", "You Received Custom Message");
                    customMessage.setMetadata(metaData);
                    sendMessage(customMessage);
                } catch (Exception e) {
                    Log.e(TAG, "onClick: " + e.getMessage());
                }
            }
        }
    });
    audioCall.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (uid.getText().toString().isEmpty()) {
                uid.setError(getResources().getString(R.string.fill_this_field));
            } else {
                Call call = new Call(uid.getText().toString(), receiver, CometChatConstants.CALL_TYPE_AUDIO);
                initiateCall(call);
            }
        }
    });
    videoCall.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (uid.getText().toString().isEmpty()) {
                uid.setError(getResources().getString(R.string.fill_this_field));
            } else {
                Call call = new Call(uid.getText().toString(), receiver, CometChatConstants.CALL_TYPE_VIDEO);
                initiateCall(call);
            }
        }
    });
    checkDarkMode();
}
Also used : Call(com.cometchat.pro.core.Call) RadioGroup(android.widget.RadioGroup) ProgressDialog(android.app.ProgressDialog) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONObject(org.json.JSONObject) CustomMessage(com.cometchat.pro.models.CustomMessage) TextMessage(com.cometchat.pro.models.TextMessage)

Example 2 with TextMessage

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

the class MessageAdapter method setLinkData.

private void setLinkData(LinkMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    String url = null;
    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());
            }
        }
        if (baseMessage.getDeletedAt() == 0) {
            HashMap<String, JSONObject> extensionList = Extensions.extensionCheck(baseMessage);
            if (extensionList != null) {
                if (extensionList.containsKey("linkPreview")) {
                    JSONObject linkPreviewJsonObject = extensionList.get("linkPreview");
                    try {
                        String description = linkPreviewJsonObject.getString("description");
                        String image = linkPreviewJsonObject.getString("image");
                        String title = linkPreviewJsonObject.getString("title");
                        url = linkPreviewJsonObject.getString("url");
                        Log.e("setLinkData: ", baseMessage.toString() + "\n\n" + url + "\n" + description + "\n" + image);
                        viewHolder.linkTitle.setText(title);
                        viewHolder.linkSubtitle.setText(description);
                        Glide.with(context).load(Uri.parse(image)).timeout(1000).into(viewHolder.linkImg);
                        if (url.contains("youtu.be") || url.contains("youtube")) {
                            viewHolder.videoLink.setVisibility(View.VISIBLE);
                            viewHolder.linkVisit.setText(context.getResources().getString(R.string.view_on_youtube));
                        } else {
                            viewHolder.videoLink.setVisibility(View.GONE);
                            viewHolder.linkVisit.setText(context.getResources().getString(R.string.visit));
                        }
                        String messageStr = ((TextMessage) baseMessage).getText();
                        if (((TextMessage) baseMessage).getText().equals(url) || ((TextMessage) baseMessage).getText().equals(url + "/")) {
                            viewHolder.message.setVisibility(View.GONE);
                        } else {
                            viewHolder.message.setVisibility(View.VISIBLE);
                        }
                        viewHolder.message.setText(messageStr);
                    } catch (Exception e) {
                        Log.e("setLinkData: ", 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.MESSAGE_CATEGORY, baseMessage.getCategory());
            intent.putExtra(UIKitConstants.IntentStrings.REACTION_INFO, Extensions.getReactionsOnMessage(baseMessage));
            intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
            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.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);
        });
        PatternUtils.setHyperLinkSupport(context, viewHolder.message);
        showMessageTime(viewHolder, baseMessage);
        String finalUrl = url;
        viewHolder.linkVisit.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (finalUrl != null) {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(finalUrl));
                    context.startActivity(intent);
                }
            }
        });
        // if (selectedItemList.contains(baseMessage.getId()))
        viewHolder.txtTime.setVisibility(View.VISIBLE);
        // else
        // viewHolder.txtTime.setVisibility(View.GONE);
        // if (i < selectedItems.length && selectedItems[i] == 0) {
        // viewHolder.txtTime.setVisibility(View.GONE);
        // } else
        // viewHolder.txtTime.setVisibility(View.VISIBLE);
        setColorFilter(baseMessage, viewHolder.cvMessageView);
        viewHolder.rlMessageBubble.setOnClickListener(view -> {
            if (isLongClickEnabled && !isImageMessageClick) {
                setLongClickSelectedItem(baseMessage);
                messageLongClick.setLongMessageClick(longselectedItemList);
            } else {
                setSelectedMessage(baseMessage.getId());
            }
            notifyItemChanged(i);
        });
        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;
            }
        });
        viewHolder.reactionLayout.setVisibility(View.GONE);
        setReactionSupport(baseMessage, viewHolder.reactionLayout);
        viewHolder.itemView.setTag(R.string.message, baseMessage);
    }
}
Also used : MediaMessage(com.cometchat.pro.models.MediaMessage) 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)

Example 3 with TextMessage

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

the class CometChatThreadMessageList method showBottomSheet.

private void showBottomSheet(CometChatMessageActions messageActionFragment) {
    messageActionFragment.show(getFragmentManager(), messageActionFragment.getTag());
    messageActionFragment.setMessageActionListener(new CometChatMessageActions.MessageActionListener() {

        @Override
        public void onPrivateReplyToUser() {
            if (baseMessage != null) {
                User user = baseMessage.getSender();
                Intent intent = new Intent(context, CometChatMessageListActivity.class);
                intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
                intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
                intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
                intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
                intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
                intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER);
                startActivity(intent);
                if (getActivity() != null)
                    getActivity().finish();
            }
        }

        @Override
        public void onThreadMessageClick() {
        }

        @Override
        public void onEditMessageClick() {
            if (isParent)
                editParentMessage();
            else
                editThreadMessage();
        }

        @Override
        public void onReplyMessageClick() {
        }

        @Override
        public void onReplyMessagePrivately() {
        }

        @Override
        public void onForwardMessageClick() {
            if (isParent)
                startForwardThreadActivity();
            else
                startForwardMessageActivity();
        }

        @Override
        public void onDeleteMessageClick() {
            deleteMessage(baseMessage);
            if (messageAdapter != null) {
                messageAdapter.clearLongClickSelectedItem();
                messageAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onCopyMessageClick() {
            String copyMessage = "";
            if (isParent) {
                copyMessage = message;
                isParent = true;
            } else {
                for (BaseMessage bMessage : baseMessages) {
                    if (bMessage.getDeletedAt() == 0 && bMessage instanceof TextMessage) {
                        copyMessage = copyMessage + "[" + Utils.getLastMessageDate(context, bMessage.getSentAt()) + "] " + bMessage.getSender().getName() + ": " + ((TextMessage) bMessage).getText();
                    }
                }
                isParent = false;
            }
            Log.e(TAG, "onCopy: " + message);
            ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("ThreadMessageAdapter", copyMessage);
            clipboardManager.setPrimaryClip(clipData);
            Toast.makeText(context, getResources().getString(R.string.text_copied), Toast.LENGTH_LONG).show();
            if (messageAdapter != null) {
                messageAdapter.clearLongClickSelectedItem();
                messageAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onShareMessageClick() {
            shareMessage();
        }

        @Override
        public void onMessageInfoClick() {
            Intent intent = new Intent(context, CometChatMessageInfoScreenActivity.class);
            if (isParent) {
            } else {
                intent.putExtra(UIKitConstants.IntentStrings.ID, baseMessage.getId());
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
                intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
                if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
                    intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.checkProfanityMessage(context, baseMessage));
                } else if (baseMessage.getCategory().equals(CometChatConstants.CATEGORY_CUSTOM)) {
                    if (((CustomMessage) baseMessage).getCustomData() != null)
                        intent.putExtra(UIKitConstants.IntentStrings.CUSTOM_MESSAGE, ((CustomMessage) baseMessage).getCustomData().toString());
                    if (baseMessage.getType().equals(UIKitConstants.IntentStrings.LOCATION)) {
                        intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.LOCATION);
                    }
                } else {
                    boolean isImageNotSafe = Extensions.getImageModeration(context, baseMessage);
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((MediaMessage) baseMessage).getAttachment().getFileName());
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, ((MediaMessage) baseMessage).getAttachment().getFileExtension());
                    intent.putExtra(UIKitConstants.IntentStrings.IMAGE_MODERATION, isImageNotSafe);
                }
            }
            context.startActivity(intent);
        }

        @Override
        public void onReactionClick(Reaction reaction) {
            if (reaction.getName().equals("add_emoji")) {
                CometChatReactionDialog reactionDialog = new CometChatReactionDialog();
                reactionDialog.setOnEmojiClick(new OnReactionClickListener() {

                    @Override
                    public void onEmojiClicked(Reaction emojicon) {
                        sendReaction(emojicon);
                        reactionDialog.dismiss();
                    }
                });
                reactionDialog.show(getFragmentManager(), "ReactionDialog");
            } else {
                sendReaction(reaction);
            }
        }

        @Override
        public void onTranslateMessageClick() {
            try {
                String localeLanguage = Locale.getDefault().getLanguage();
                JSONObject body = new JSONObject();
                JSONArray languages = new JSONArray();
                languages.put(localeLanguage);
                if (isParent) {
                    body.put("msgId", parentId);
                    body.put("text", textMessage.getText().toString());
                } else {
                    body.put("msgId", baseMessage.getId());
                    body.put("text", ((TextMessage) baseMessage).getText());
                }
                body.put("languages", languages);
                CometChat.callExtension("message-translation", "POST", "/v2/translate", body, new CometChat.CallbackListener<JSONObject>() {

                    @Override
                    public void onSuccess(JSONObject jsonObject) {
                        if (isParent) {
                            if (Extensions.isMessageTranslated(jsonObject, textMessage.getText().toString())) {
                                String translatedMessage = Extensions.getTextFromTranslatedMessage(jsonObject, textMessage.getText().toString());
                                textMessage.setText(translatedMessage);
                            } else {
                                CometChatSnackBar.show(context, rvChatListView, getString(R.string.no_translation_available), CometChatSnackBar.INFO);
                            }
                        } else {
                            if (Extensions.isMessageTranslated(jsonObject, ((TextMessage) baseMessage).getText())) {
                                if (baseMessage.getMetadata() != null) {
                                    JSONObject meta = baseMessage.getMetadata();
                                    try {
                                        meta.accumulate("values", jsonObject);
                                        baseMessage.setMetadata(meta);
                                        updateMessage(baseMessage);
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                } else {
                                    baseMessage.setMetadata(jsonObject);
                                    updateMessage(baseMessage);
                                }
                            } else {
                                CometChatSnackBar.show(context, rvChatListView, getString(R.string.no_translation_available), CometChatSnackBar.INFO);
                            }
                        }
                    }

                    @Override
                    public void onError(CometChatException e) {
                        CometChatSnackBar.show(context, rvChatListView, CometChatError.Extension.localized(e, "message-translation"), CometChatSnackBar.ERROR);
                    }
                });
            } catch (Exception e) {
                Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onRetryClick() {
        }
    });
}
Also used : ClipboardManager(android.content.ClipboardManager) OnReactionClickListener(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.listener.OnReactionClickListener) CometChatException(com.cometchat.pro.exceptions.CometChatException) User(com.cometchat.pro.models.User) MediaMessage(com.cometchat.pro.models.MediaMessage) CometChatMessageListActivity(com.cometchat.pro.uikit.ui_components.messages.message_list.CometChatMessageListActivity) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Intent(android.content.Intent) Reaction(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.model.Reaction) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) CometChatReactionDialog(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog) BaseMessage(com.cometchat.pro.models.BaseMessage) JSONObject(org.json.JSONObject) CometChatMessageInfoScreenActivity(com.cometchat.pro.uikit.ui_components.messages.message_information.CometChatMessageInfoScreenActivity) CometChatMessageActions(com.cometchat.pro.uikit.ui_components.messages.message_actions.CometChatMessageActions) ClipData(android.content.ClipData) TextMessage(com.cometchat.pro.models.TextMessage)

Example 4 with TextMessage

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

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

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