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