use of com.fanap.podchat.model.ErrorOutPut 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.ErrorOutPut in project pod-chat-android-sdk by FanapSoft.
the class ChatActivity method sendFileMessage.
private void sendFileMessage(String[] fileUnique) {
RequestFileMessage request = new RequestFileMessage.Builder(ChatActivity.this, TEST_THREAD_ID, getUri(), // constructor
TextMessageType.Constants.POD_SPACE_PICTURE).description("test file message").setUserGroupHash(TEST_THREAD_HASH).build();
fileUnique[0] = presenter.sendFileMessage(request, new ProgressHandler.sendFileMessage() {
@Override
public void onProgressUpdate(String uniqueId, int progress, int totalBytesSent, int totalBytesToSend) {
Log.e("SFM", "Sending files message: " + progress + " * " + totalBytesSent + " * " + totalBytesToSend);
}
@Override
public void onFinishImage(String json, ChatResponse<ResultImageFile> chatResponse) {
Log.e("SFM", "onFinishImage");
}
@Override
public void onFinishFile(String json, ChatResponse<ResultFile> chatResponse) {
Log.e("SFM", "onFinishFile");
}
@Override
public void onError(String jsonError, ErrorOutPut error) {
Log.e("SFM", "onError");
}
});
// fileUnique[0] = presenter.sendFileMessage(
// ChatActivity.this,
// ChatActivity.this,
// "test file message",
// TEST_THREAD_ID,
// getUri(),
// getMetaData(),
// TextMessageType.Constants.PICTURE,
// new ProgressHandler.sendFileMessage() {
// @Override
// public void onProgressUpdate(String uniqueId, int progress, int totalBytesSent, int totalBytesToSend) {
//
// Log.e("SFM", "Sending files message: " + progress + " * " + totalBytesSent + " * " + totalBytesToSend);
// }
//
// @Override
// public void onFinishImage(String json, ChatResponse<ResultImageFile> chatResponse) {
//
// Log.e("SFM", "onFinishImage");
//
// }
//
// @Override
// public void onFinishFile(String json, ChatResponse<ResultFile> chatResponse) {
//
// Log.e("SFM", "onFinishFile");
//
// }
//
// @Override
// public void onError(String jsonError, ErrorOutPut error) {
//
// Log.e("SFM", "onError");
//
//
// }
// });
}
use of com.fanap.podchat.model.ErrorOutPut 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.ErrorOutPut in project pod-chat-android-sdk by FanapSoft.
the class ThreadCacheTest method sendMessage.
public void sendMessage() {
populateThreadsFromServer();
Collections.shuffle(threadsInServer);
Thread thread = threadsInServer.get(0);
System.out.println("Thread : " + thread.getTitle());
Assert.assertNotNull(thread);
chatListeners = new ChatListener() {
@Override
public void onNewMessage(String content, ChatResponse<ResultNewMessage> response) {
resumeProcess();
chat.removeListener(chatListeners);
}
@Override
public void onError(String content, ErrorOutPut error) {
resumeProcess();
System.out.println("Error: " + content);
Assert.assertEquals(0, 1);
chat.removeListener(chatListeners);
}
};
chat.addListener(chatListeners);
RequestMessage request = new RequestMessage.Builder("Android Test " + new Date(), thread.getId()).messageType(TextMessageType.Constants.TEXT).build();
chat.sendTextMessage(request, null);
}
use of com.fanap.podchat.model.ErrorOutPut in project pod-chat-android-sdk by FanapSoft.
the class ChatTest method getThreadFullHistory.
private void getThreadFullHistory(Thread thread) {
long startTime = System.currentTimeMillis();
AtomicBoolean hasNext = new AtomicBoolean(true);
int count = 25;
AtomicLong offset = new AtomicLong(0);
AtomicLong threadMessagesCount = new AtomicLong(-1);
AtomicLong threadReceivedHistory = new AtomicLong(0);
ChatListener historyListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
threadMessagesCount.set(history.getResult().getContentCount());
long received = threadReceivedHistory.get();
threadReceivedHistory.set(received + history.getResult().getHistory().size());
hasNext.set(history.getResult().isHasNext());
if (hasNext.get()) {
offset.set(offset.get() + history.getResult().getHistory().size());
}
resumeProcess();
}
@Override
public void onError(String content, ErrorOutPut error) {
Assert.fail(content);
}
};
chat.addListener(historyListeners);
while (hasNext.get()) {
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).offset(offset.get()).withNoCache().count(count).order("desc").build();
String uniqueId = presenter.getHistory(requestGetHistory, null);
pauseProcess();
}
long endTime = System.currentTimeMillis();
System.out.println(">>> >>> >>>");
System.out.println(">>> >>> >>>");
System.out.println(">>> >>> >>>");
System.out.println("RUNNING TEST ON THREAD:");
System.out.println(thread.getTitle());
System.out.println(thread.getId());
System.out.println("RECEIVED TOTAL " + threadReceivedHistory + " MESSAGES OF HISTORY IN");
System.out.println(endTime - startTime + " MILLISECONDS");
System.out.println(">>> >>> >>>");
System.out.println(">>> >>> >>>");
System.out.println(">>> >>> >>>");
Assert.assertEquals(threadMessagesCount.get(), threadReceivedHistory.get());
}
Aggregations