use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method removeContact.
/**
* Remove contact with the user id
*
* @param userId id of the user that we want to remove from contact list
*/
@Deprecated
public String removeContact(long userId) {
String uniqueId = generateUniqueId();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("uniqueId", uniqueId);
jsonObject.addProperty("id", userId);
jsonObject.addProperty("tokenIssuer", 1);
showLog("SEND_REMOVE_CONTACT", getJsonForLog(jsonObject));
Observable<Response<ContactRemove>> removeContactObservable;
if (chatReady) {
if (Util.isNullOrEmpty(getTypeCode())) {
removeContactObservable = contactApi.removeContact(getToken(), 1, userId);
} else {
removeContactObservable = contactApi.removeContact(getToken(), 1, userId, getTypeCode());
}
removeContactObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(response -> {
Log.d("MTAG", response.raw().toString());
if (response.body() != null && response.isSuccessful()) {
ContactRemove contactRemove = response.body();
if (!contactRemove.getHasError()) {
ChatResponse<ResultRemoveContact> chatResponse = new ChatResponse<>();
chatResponse.setUniqueId(uniqueId);
ResultRemoveContact resultRemoveContact = new ResultRemoveContact();
resultRemoveContact.setResult(contactRemove.isResult());
chatResponse.setResult(resultRemoveContact);
String json = gson.toJson(chatResponse);
if (cache) {
dataSource.deleteContactById(userId);
// messageDatabaseHelper.deleteContactById(userId);
}
listenerManager.callOnRemoveContact(json, chatResponse);
showLog("RECEIVED_REMOVE_CONTACT", json);
} else {
captureError(contactRemove.getErrorMessage(), contactRemove.getErrorCode(), uniqueId);
}
}
}, (Throwable throwable) -> captureError(throwable.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, uniqueId, throwable));
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
return uniqueId;
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method uploadImageToThread.
// new upload image function
private void uploadImageToThread(RequestUploadImage request, String userGroupHash, String uniqueId, @Nullable ProgressHandler.onProgress handler, OnWorkDone listener) {
if (needReadStoragePermission(request.getActivity())) {
String jsonError = captureError(ChatConstant.ERROR_READ_EXTERNAL_STORAGE_PERMISSION, ChatConstant.ERROR_CODE_READ_EXTERNAL_STORAGE_PERMISSION, uniqueId);
ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_READ_EXTERNAL_STORAGE_PERMISSION, ChatConstant.ERROR_CODE_READ_EXTERNAL_STORAGE_PERMISSION, uniqueId);
if (handler != null) {
handler.onError(jsonError, error);
}
listener.onWorkDone(null);
return;
}
if (!chatReady) {
onChatNotReady(uniqueId);
listener.onWorkDone(null);
return;
}
if (getPodSpaceServer() == null) {
listener.onWorkDone(null);
captureError("File server is null", 0, uniqueId);
return;
}
try {
Subscription subscription = PodUploader.uploadToPodSpace(uniqueId, request.getFileUri(), userGroupHash, context, getPodSpaceServer(), getToken(), TOKEN_ISSUER, String.valueOf(request.getxC()), String.valueOf(request.getyC()), String.valueOf(request.gethC()), String.valueOf(request.getwC()), new PodUploader.IPodUploadFileToPodSpace() {
@Override
public void onSuccess(UploadToPodSpaceResult response, File file, String mimeType, long length, int actualWidth, int actualHeight, int width, int height) {
ChatResponse<ResultImageFile> chatResponse = PodUploader.generateImageUploadResultForSendMessage(response, uniqueId, actualWidth, actualHeight, width, height, getPodSpaceImageUrl(response.getHashCode()));
String imageJson = gson.toJson(chatResponse);
listenerManager.callOnUploadImageFile(imageJson, chatResponse);
if (handler != null) {
handler.onFinish(imageJson, chatResponse);
}
showLog("RECEIVE_UPLOAD_IMAGE", imageJson);
listener.onWorkDone(response.getHashCode());
}
@Override
public void onFailure(String cause, Throwable t) {
String jsonError = captureError(cause, ChatConstant.ERROR_CODE_UPLOAD_FILE, uniqueId, t);
ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId);
if (handler != null) {
handler.onError(jsonError, error);
}
listener.onWorkDone(null);
}
@Override
public void onUploadStarted(String mimeType, File file, long length) {
showLog("UPLOADING_FILE");
}
@Override
public void onProgressUpdate(int progress, int totalBytesSent, int totalBytesToSend) {
if (handler != null) {
handler.onProgressUpdate(progress);
handler.onProgressUpdate(uniqueId, progress, totalBytesSent, totalBytesToSend);
}
}
});
initCancelUpload(uniqueId, subscription);
} catch (Exception e) {
String jsonError = captureError(ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId, e);
ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId);
listener.onWorkDone(null);
if (handler != null) {
handler.onError(jsonError, error);
}
}
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getTagList.
/**
* get user tags
*/
public String getTagList(GetTagListRequest request) {
String uniqueId = generateUniqueId();
if (cache) {
messageDatabaseHelper.getTagVos().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).filter(tags -> tags != null && tags.size() > 0).subscribe(tags -> {
ChatResponse<TagListResult> response = new ChatResponse<>();
response.setResult(new TagListResult(tags));
response.setUniqueId(uniqueId);
response.setCache(true);
listenerManager.callOnTagList(null, response);
});
}
if (chatReady) {
String message = TagManager.createTagListRequest(request, uniqueId);
sendAsyncMessage(message, AsyncAckType.Constants.WITHOUT_ACK, "GET_TAG_LIST");
} else {
onChatNotReady(uniqueId);
}
return uniqueId;
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleOutPutDeliveredMessageList.
private void handleOutPutDeliveredMessageList(ChatMessage chatMessage, Callback callback) {
try {
ChatResponse<ResultParticipant> chatResponse = new ChatResponse<>();
chatResponse.setUniqueId(chatMessage.getUniqueId());
ResultParticipant resultParticipant = new ResultParticipant();
List<Participant> participants = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Participant>>() {
}.getType());
resultParticipant.setParticipants(participants);
resultParticipant.setContentCount(chatMessage.getContentCount());
resultParticipant.setNextOffset(callback.getOffset() + participants.size());
resultParticipant.setContentCount(chatMessage.getContentCount());
resultParticipant.setHasNext(participants.size() + callback.getOffset() < chatMessage.getContentCount());
chatResponse.setResult(resultParticipant);
String content = gson.toJson(chatResponse);
if (sentryResponseLog) {
showLog("RECEIVE_DELIVERED_MESSAGE_LIST", content);
} else {
showLog("RECEIVE_DELIVERED_MESSAGE_LIST");
}
listenerManager.callOnDeliveredMessageList(content, chatResponse);
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(chatMessage.getUniqueId(), e);
}
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method replyFileMessage.
/**
* Reply the message in the current thread and send az message and receive at the
* <p>
* messageContent content of the reply message
* threadId id of the thread
* messageId of the message that we want to reply
* metaData meta data of the message
*/
public String replyFileMessage(RequestReplyFileMessage request, ProgressHandler.sendFileMessage handler) {
String uniqueId = generateUniqueId();
if (needReadStoragePermission(request.getActivity())) {
String jsonError = captureError(ChatConstant.ERROR_READ_EXTERNAL_STORAGE_PERMISSION, ChatConstant.ERROR_CODE_READ_EXTERNAL_STORAGE_PERMISSION, uniqueId);
ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_READ_EXTERNAL_STORAGE_PERMISSION, ChatConstant.ERROR_CODE_READ_EXTERNAL_STORAGE_PERMISSION, uniqueId);
if (handler != null) {
handler.onError(jsonError, error);
}
return uniqueId;
}
if (!chatReady) {
onChatNotReady(uniqueId);
return uniqueId;
}
if (getPodSpaceServer() == null) {
captureError("PodSpace server is null", 0, uniqueId);
return uniqueId;
}
long threadId = request.getThreadId();
String messageContent = request.getMessageContent();
String systemMetaData = request.getSystemMetaData();
Uri fileUri = request.getFileUri();
long messageId = request.getMessageId();
int messageType = request.getMessageType();
String methodName = ChatConstant.METHOD_REPLY_MSG;
try {
Subscription subscription = PodUploader.uploadToPodSpace(uniqueId, request.getFileUri(), request.getUserGroupHashCode(), context, getPodSpaceServer(), getToken(), TOKEN_ISSUER, request.getImageXc(), request.getImageYc(), request.getImageHc(), request.getImageWc(), new PodUploader.IPodUploadFileToPodSpace() {
@Override
public void onSuccess(UploadToPodSpaceResult response, File file, String mimeType, long length) {
removeFromUploadQueue(uniqueId);
ChatResponse<ResultFile> chatResponse = PodUploader.generateImageUploadResultForSendMessage(response, uniqueId);
String json = gson.toJson(chatResponse);
showLog("FILE_UPLOADED_TO_SERVER", json);
listenerManager.callOnUploadFile(json, chatResponse);
if (handler != null) {
handler.onFinishFile(json, chatResponse);
}
String jsonMeta = createFileMetadata(file, response.getHashCode(), 0, mimeType, length, response.getParentHash());
showLog("SEND_REPLY_FILE_MESSAGE", jsonMeta);
mainReplyMessage(messageContent, threadId, messageId, systemMetaData, messageType, jsonMeta, uniqueId, null);
}
@Override
public void onSuccess(UploadToPodSpaceResult response, File file, String mimeType, long length, int actualWidth, int actualHeight, int width, int height) {
removeFromUploadQueue(uniqueId);
ChatResponse<ResultImageFile> chatResponse = PodUploader.generateImageUploadResultForSendMessage(response, uniqueId, actualWidth, actualHeight, width, height, getPodSpaceImageUrl(response.getHashCode()));
String imageJson = gson.toJson(chatResponse);
listenerManager.callOnUploadImageFile(imageJson, chatResponse);
if (handler != null) {
handler.onFinishImage(imageJson, chatResponse);
}
showLog("RECEIVE_UPLOAD_IMAGE", imageJson);
String jsonMeta = createImageMetadata(file, response.getHashCode(), 0, height, width, mimeType, length, response.getParentHash(), false, null);
showLog("SEND_REPLY_FILE_MESSAGE", jsonMeta);
mainReplyMessage(messageContent, threadId, messageId, systemMetaData, messageType, jsonMeta, uniqueId, null);
}
@Override
public void onFailure(String cause, Throwable t) {
String jsonError = captureError(cause, ChatConstant.ERROR_CODE_UPLOAD_FILE, uniqueId, t);
ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId);
if (handler != null) {
handler.onError(jsonError, error);
}
}
@Override
public void onUploadStarted(String mimeType, File file, long length) {
addToUploadQueue(messageContent, fileUri, messageType, threadId, request.getUserGroupHashCode(), uniqueId, systemMetaData, messageId, mimeType, null, methodName, file, length);
showLog("UPLOAD_FILE_TO_SERVER");
}
@Override
public void onProgressUpdate(int progress, int totalBytesSent, int totalBytesToSend) {
if (handler != null)
handler.onProgressUpdate(uniqueId, progress, totalBytesSent, totalBytesToSend);
}
});
initCancelUpload(uniqueId, subscription);
} catch (Exception e) {
String jsonError = captureError(ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId, e);
ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId);
if (handler != null) {
handler.onError(jsonError, error);
}
}
return uniqueId;
}
Aggregations