use of com.fanap.podchat.model.ResultImageFile in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method retryUpload.
/**
* It retry upload that they didn't send
*/
// public void retryUpload(RetryUpload retry, ProgressHandler.sendFileMessage handler) {
//
// Runnable retryTask = () -> {
// String uniqueId = retry.getUniqueId();
// Activity activity = retry.getActivity();
//
// UploadingQueueCache uploadingQ;
// if (cache) {
// uploadingQ = messageDatabaseHelper.getUploadingQ(uniqueId);
// } else {
// uploadingQ = uploadingQList.get(uniqueId);
// }
//
// if (uploadingQ != null) {
// long messageId = uploadingQ.getId();
// int messageType = uploadingQ.getMessageType();
// long threadId = uploadingQ.getThreadId();
// String message = uploadingQ.getMessage();
// String systemMetadata = uploadingQ.getSystemMetadata();
// MetaDataFile metaDataFile = gson.fromJson(systemMetadata, MetaDataFile.class);
// String link = metaDataFile.getFile().getLink();
// String mimeType = metaDataFile.getFile().getMimeType();
//
// LFileUpload lFileUpload = new LFileUpload();
// lFileUpload.setActivity(activity);
// lFileUpload.setDescription(message);
// lFileUpload.setFileUri(Uri.parse(link));
// lFileUpload.setHandler(handler);
// lFileUpload.setMessageType(messageType);
// lFileUpload.setThreadId(threadId);
// lFileUpload.setUniqueId(uniqueId);
// lFileUpload.setSystemMetaData(systemMetadata);
// lFileUpload.setHandler(handler);
// lFileUpload.setMimeType(mimeType);
//
// if (!Util.isNullOrEmpty(messageId)) {
// String methodName = ChatConstant.METHOD_REPLY_MSG;
// lFileUpload.setMethodName(methodName);
// }
//
// removeFromUploadQueue(uniqueId);
//
// if (FileUtils.isImage(mimeType) && !FileUtils.isGif(mimeType)) {
// uploadImageFileMessage(lFileUpload);
// } else {
// uploadFileMessage(lFileUpload);
// }
//
// }
// };
//
// new PodThreadManager()
// .doThisAndGo(retryTask);
//
// }
public void retryUpload(RetryUpload retry, ProgressHandler.sendFileMessage handler) {
Runnable retryTask = () -> {
String uniqueId = retry.getUniqueId();
Activity activity = retry.getActivity();
UploadingQueueCache uploadingQ;
if (cache) {
uploadingQ = dataSource.getUploadingQ(uniqueId);
// uploadingQ = messageDatabaseHelper.getUploadingQ(uniqueId);
} else {
uploadingQ = uploadingQList.get(uniqueId);
}
if (uploadingQ != null) {
long messageId = uploadingQ.getId();
int messageType = uploadingQ.getMessageType();
long threadId = uploadingQ.getThreadId();
String userGroupHash = uploadingQ.getUserGroupHash();
String methodName = !Util.isNullOrEmpty(messageId) ? ChatConstant.METHOD_REPLY_MSG : null;
String message = uploadingQ.getMessage();
String systemMetadata = uploadingQ.getSystemMetadata();
String metadata = uploadingQ.getMetadata();
MetaDataFile metaDataFile = gson.fromJson(metadata, MetaDataFile.class);
String link = null;
try {
link = metaDataFile.getFile().getLink();
} catch (Exception e) {
Log.e(TAG, "Couldn't retrieve link");
}
if (needReadStoragePermission(activity)) {
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;
}
removeFromUploadQueue(uniqueId);
try {
String finalLink = link;
Subscription subscription = PodUploader.uploadToPodSpace(uniqueId, Util.isNullOrEmpty(link) ? null : Uri.parse(link), userGroupHash, context, getPodSpaceServer(), getToken(), TOKEN_ISSUER, 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());
if (isReplyMessage(methodName)) {
showLog("SEND_REPLY_FILE_MESSAGE", jsonMeta);
mainReplyMessage(message, threadId, messageId, systemMetadata, messageType, jsonMeta, uniqueId, null);
} else {
sendTextMessageWithFile(message, threadId, jsonMeta, systemMetadata, uniqueId, typeCode, messageType);
}
}
@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);
if (isReplyMessage(methodName)) {
showLog("SEND_REPLY_FILE_MESSAGE", jsonMeta);
mainReplyMessage(message, threadId, messageId, systemMetadata, messageType, jsonMeta, uniqueId, null);
} else {
sendTextMessageWithFile(message, threadId, jsonMeta, systemMetadata, uniqueId, typeCode, messageType);
}
}
@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(message, Util.isNullOrEmpty(finalLink) ? null : Uri.parse(finalLink), messageType, threadId, userGroupHash, 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);
}
}
}
};
new PodThreadManager().doThisAndGo(retryTask);
}
use of com.fanap.podchat.model.ResultImageFile in project pod-chat-android-sdk by FanapSoft.
the class ChatActivity method createThreadWithFile.
private void createThreadWithFile() {
if (getUri() == null) {
Toast.makeText(this, "Pick a file", Toast.LENGTH_SHORT).show();
return;
}
RequestUploadImage requestUploadThreadImageImage = new RequestUploadImage.Builder(this, getUri()).setwC(140).sethC(140).build();
RequestUploadImage requestUploadImage = new RequestUploadImage.Builder(this, getUri()).setwC(120).sethC(120).setxC(1).setyC(1).build();
RequestUploadFile requestUploadFile = new RequestUploadFile.Builder(this, getUri()).build();
List<Invitee> invite = new ArrayList<>();
// f.kh sandbox
// invite.add(new Invitee("4893", InviteType.Constants.TO_BE_USER_CONTACT_ID));
// POURIA main
invite.add(new Invitee(1151568, InviteType.Constants.TO_BE_USER_CONTACT_ID));
// MASOUD
// invite.add(new Invitee(1511971, InviteType.Constants.TO_BE_USER_CONTACT_ID));
// ARVIN
invite.add(new Invitee(1512305, InviteType.Constants.TO_BE_USER_CONTACT_ID));
// MAHYAR
// invite.add(new Invitee(1196793, InviteType.Constants.TO_BE_USER_CONTACT_ID));
// RequestThreadInnerMessage innerMessage = new RequestThreadInnerMessage
// .Builder(TextMessageType.Constants.PICTURE)
// // .message("Create thread for File Message Test " + new Date().toString())
// // .forwardedMessageIds(listForwardIds)
// .build();
RequestCreateThreadWithFile request = new RequestCreateThreadWithFile.Builder(ThreadType.Constants.OWNER_GROUP, invite, requestUploadFile, TextMessageType.Constants.POD_SPACE_FILE).title("Test File PodSpace").setUploadThreadImageRequest(requestUploadThreadImageImage).build();
presenter.createThreadWithFile(request, new ProgressHandler.sendFileMessage() {
@Override
public void onProgressUpdate(String uniqueId, int progress, int totalBytesSent, int totalBytesToSend) {
Log.e("CTF", "Upload Progress: " + progress);
}
@Override
public void onFinishImage(String json, ChatResponse<ResultImageFile> chatResponse) {
Log.e("CTF", "Upload Finish (IMAGE): ");
}
@Override
public void onFinishFile(String json, ChatResponse<ResultFile> chatResponse) {
Log.e("CTF", "Upload Finish (FILE): ");
}
@Override
public void onError(String jsonError, ErrorOutPut error) {
Log.e("CTF", "Upload Error");
}
});
}
use of com.fanap.podchat.model.ResultImageFile in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method sendFileMessage.
/**
* This method first check the messageType of the file and then choose the right
* server and send that
* <p>
* description Its the description that you want to send with file in the thread
* fileUri Uri of the file that you want to send to thread
* threadId Id of the thread that you want to send file
* systemMetaData [optional]
* handler it is for send file message with progress
*/
// public String sendFileMessage(RequestFileMessage requestFileMessage, ProgressHandler.sendFileMessage handler) {
//
// long threadId = requestFileMessage.getThreadId();
// Activity activity = requestFileMessage.getActivity();
// Uri fileUri = requestFileMessage.getFileUri();
// String description = requestFileMessage.getDescription();
// int messageType = requestFileMessage.getMessageType();
// String systemMetadata = requestFileMessage.getSystemMetadata();
//
// return sendFileMessage(activity, description, threadId, fileUri, systemMetadata, messageType, handler);
// }
public String sendFileMessage(RequestFileMessage requestFileMessage, ProgressHandler.sendFileMessage handler) {
String uniqueId = generateUniqueId();
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 uniqueId;
}
if (!chatReady) {
onChatNotReady(uniqueId);
return uniqueId;
}
if (getPodSpaceServer() == null) {
captureError("PodSpace server is null", 0, uniqueId);
return uniqueId;
}
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_STARTED");
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);
}
}
return uniqueId;
}
use of com.fanap.podchat.model.ResultImageFile in project pod-chat-android-sdk by FanapSoft.
the class PodUploader method generateImageUploadResult.
private static ResultImageFile generateImageUploadResult(UploadToPodSpaceResult response) {
ResultImageFile result = new ResultImageFile();
result.setId(0);
result.setName(response.getName());
result.setHashCode(response.getHashCode());
// result.setDescription(response.getDescription());
result.setUrl(response.getParentHash());
return result;
}
use of com.fanap.podchat.model.ResultImageFile 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);
}
}
}
Aggregations