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());
}
});
}
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);
}
}
});
}
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());
}
});
}
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);
}
}
});
}
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());
}
});
}
Aggregations