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