use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class BotManager method handleOnBotCommandDefined.
public static ChatResponse<DefineBotCommandResult> handleOnBotCommandDefined(ChatMessage chatMessage) {
ChatResponse<DefineBotCommandResult> response = new ChatResponse<>();
DefineBotCommandResult result = App.getGson().fromJson(chatMessage.getContent(), DefineBotCommandResult.class);
response.setResult(result);
response.setUniqueId(chatMessage.getUniqueId());
return response;
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class BotManager method handleOnUserBots.
public static ChatResponse<GetUserBotsResult> handleOnUserBots(ChatMessage chatMessage) {
ChatResponse<GetUserBotsResult> response = new ChatResponse<>();
GetUserBotsResult result = new GetUserBotsResult(App.getGson().fromJson(chatMessage.getContent(), new TypeToken<List<BotVo>>() {
}.getType()));
response.setResult(result);
response.setUniqueId(chatMessage.getUniqueId());
response.setSubjectId(chatMessage.getSubjectId());
return response;
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method sendFileMessage.
private void sendFileMessage(RequestFileMessage requestFileMessage, String uniqueId, ProgressHandler.sendFileMessage handler) {
if (needReadStoragePermission(requestFileMessage.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;
}
if (!chatReady) {
onChatNotReady(uniqueId);
return;
}
if (getPodSpaceServer() == null) {
captureError("File server is null", 0, uniqueId);
return;
}
try {
Subscription subscription = PodUploader.uploadToPodSpace(uniqueId, requestFileMessage.getFileUri(), requestFileMessage.getUserGroupHash(), context, getPodSpaceServer(), getToken(), TOKEN_ISSUER, requestFileMessage.getImageXc(), requestFileMessage.getImageYc(), requestFileMessage.getImageHc(), requestFileMessage.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());
sendTextMessageWithFile(requestFileMessage.getDescription(), requestFileMessage.getThreadId(), jsonMeta, requestFileMessage.getSystemMetadata(), uniqueId, typeCode, requestFileMessage.getMessageType());
}
@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);
sendTextMessageWithFile(requestFileMessage.getDescription(), requestFileMessage.getThreadId(), jsonMeta, requestFileMessage.getSystemMetadata(), uniqueId, typeCode, requestFileMessage.getMessageType());
}
@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(requestFileMessage.getDescription(), requestFileMessage.getFileUri(), requestFileMessage.getMessageType(), requestFileMessage.getThreadId(), requestFileMessage.getUserGroupHash(), uniqueId, requestFileMessage.getSystemMetadata(), mimeType, file, length);
showLog("UPLOAD_FILE_TO_SERVER");
showLog(requestFileMessage.toString());
}
@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);
}
}
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method uploadImageProgress.
public String uploadImageProgress(RequestUploadImage request, @Nullable ProgressHandler.onProgress 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("File server is null", 0, uniqueId);
return uniqueId;
}
try {
Subscription subscription = PodUploader.uploadPublicToPodSpace(uniqueId, request.getFileUri(), context, getPodSpaceServer(), getToken(), TOKEN_ISSUER, String.valueOf(request.getxC()), String.valueOf(request.getyC()), String.valueOf(request.gethC()), String.valueOf(request.getwC()), request.isPublic(), 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);
}
@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) {
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);
if (handler != null) {
handler.onError(jsonError, error);
}
}
return uniqueId;
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleNewMessage.
/**
* When the new message arrived we send the deliver message to the sender user.
*/
private void handleNewMessage(ChatMessage chatMessage) {
try {
MessageVO messageVO = gson.fromJson(chatMessage.getContent(), MessageVO.class);
if (cache) {
dataSource.saveMessageResultFromServer(messageVO, chatMessage.getSubjectId());
}
ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
chatResponse.setUniqueId(chatMessage.getUniqueId());
chatResponse.setHasError(false);
chatResponse.setErrorCode(0);
chatResponse.setErrorMessage("");
ResultNewMessage resultNewMessage = new ResultNewMessage();
resultNewMessage.setMessageVO(messageVO);
resultNewMessage.setThreadId(chatMessage.getSubjectId());
chatResponse.setResult(resultNewMessage);
chatResponse.setSubjectId(chatMessage.getSubjectId());
String json = gson.toJson(chatResponse);
long ownerId = 0;
if (messageVO != null) {
ownerId = messageVO.getParticipant().getId();
}
if (sentryResponseLog) {
showLog("RECEIVED_NEW_MESSAGE", json);
} else {
showLog("RECEIVED_NEW_MESSAGE");
}
if (ownerId != getUserId()) {
if (messageVO != null) {
ChatMessage message = getChatMessage(messageVO);
String asyncContent = gson.toJson(message);
async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
setThreadCallbacks(chatMessage.getSubjectId(), chatMessage.getUniqueId());
showLog("SEND_DELIVERY_MESSAGE", asyncContent);
}
}
if (messageVO != null) {
handleOnNewMessageAdded(messageVO.getConversation(), chatMessage.getUniqueId());
}
listenerManager.callOnNewMessage(json, chatResponse);
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(chatMessage.getUniqueId(), e);
}
}
Aggregations