use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method getThreadHistory.
public Observable<ChatResponse<ResultHistory>> getThreadHistory(@NonNull History history, long threadId) {
return rx.Observable.create(subscriber -> {
List<MessageVO> messageVOS = new ArrayList<>();
List<CacheMessageVO> cacheMessageVOS;
long fromTime = history.getFromTime();
long fromTimeNanos = history.getFromTimeNanos();
long toTime = history.getToTime();
long toTimeNanos = history.getToTimeNanos();
long messageId = history.getId();
long offset = history.getOffset();
long count = history.getCount();
int messageType = history.getMessageType();
String query = history.getQuery();
String order = history.getOrder();
offset = offset >= 0 ? offset : 0;
count = count > 0 ? count : 50;
if (Util.isNullOrEmpty(order)) {
order = "desc";
}
String rawQuery = "SELECT * FROM CacheMessageVO WHERE threadVoId =" + threadId;
rawQuery = addMessageIdIfExist(messageId, rawQuery);
rawQuery = addFromTimeIfExist(fromTime, fromTimeNanos, rawQuery);
rawQuery = addToTimeIfExist(toTime, toTimeNanos, rawQuery);
rawQuery = addQueryIfExist(query, rawQuery);
rawQuery = addMessageTypeIfExist(messageType, rawQuery);
long contentCount = messageDao.getHistoryContentCount(new SimpleSQLiteQuery(rawQuery.replaceFirst("SELECT \\* ", "SELECT COUNT(ID) ")));
rawQuery = addOrderAndLimitAndOffset(offset, count, order, rawQuery);
SupportSQLiteQuery sqLiteQuery = new SimpleSQLiteQuery(rawQuery);
cacheMessageVOS = messageDao.getRawHistory(sqLiteQuery);
prepareMessageVOs(messageVOS, cacheMessageVOS);
List<Sending> sendingList = getAllSendingQueueByThreadId(threadId);
List<Uploading> uploadingList = getAllUploadingQueueByThreadId(threadId);
List<Failed> failedList = getAllWaitQueueCacheByThreadId(threadId);
ChatResponse<ResultHistory> chatResponse = new ChatResponse<>();
chatResponse.setCache(true);
ResultHistory resultHistory = new ResultHistory();
resultHistory.setHistory(messageVOS);
resultHistory.setNextOffset(history.getOffset() + messageVOS.size());
resultHistory.setContentCount(contentCount);
if (messageVOS.size() + history.getOffset() < contentCount) {
resultHistory.setHasNext(true);
} else {
resultHistory.setHasNext(false);
}
resultHistory.setHistory(messageVOS);
resultHistory.setSending(sendingList);
resultHistory.setUploadingQueue(uploadingList);
resultHistory.setFailed(failedList);
chatResponse.setErrorCode(0);
chatResponse.setHasError(false);
chatResponse.setErrorMessage("");
chatResponse.setResult(resultHistory);
chatResponse.setCache(true);
chatResponse.setSubjectId(threadId);
subscriber.onNext(chatResponse);
});
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class MemoryDataSource method createHistoryResponse.
private MessageManager.HistoryResponse createHistoryResponse(List<MessageVO> messageVOS, long threadId) {
ChatResponse<ResultHistory> response = new ChatResponse<>();
ResultHistory result = new ResultHistory();
result.setHistory(messageVOS);
result.setContentCount(contactContentCount);
// TODO: 9/14/2020 fix here
result.setHasNext(messageVOS.size() < contactContentCount);
result.setNextOffset(messageVOS.size());
result.setFailed(getThreadFailedMessages(threadId));
result.setSending(getThreadSendingMessages(threadId));
result.setUploadingQueue(getThreadUploadingMessage(threadId));
response.setResult(result);
return new MessageManager.HistoryResponse(response, MEMORY);
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatActivity method downloadFile.
private void downloadFile() {
String url = "https://core.pod.ir/nzh/image?imageId=222808&hashCode=16c3cd2b93f-0.527719303638482";
// image
// long imageId = 404143;
long imageId = 68349;
long fileId = 68684;
// String imageHashCode = "17024463974-0.5588549950419339";
String imageHashCode = "16feadc7bf1-0.5248624596970302";
String fileHashCode = "17077360d4b-0.2366487166443898";
RequestGetImage requestGetImage = new RequestGetImage.Builder(imageId, imageHashCode, true).build();
RequestGetFile requestGetFile = new RequestGetFile.Builder(fileId, fileHashCode, true).build();
RequestGetPodSpaceFile rePod = new RequestGetPodSpaceFile.Builder("GAUPE1ZRK76VOXBS").build();
RequestGetPodSpaceImage rePodImage = new RequestGetPodSpaceImage.Builder("613Q7WCCEXZ1DGY5").setQuality(0.45f).build();
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_EXTERNAL_STORAGE);
return;
}
downloadingId = presenter.downloadFile(rePodImage, new ProgressHandler.IDownloadFile() {
@Override
public void onProgressUpdate(String uniqueId, long bytesDownloaded, long totalBytesToDownload) {
Log.e("DOWNLOAD", "IN ACTIVITY: " + "Downloaded: " + bytesDownloaded + " Left: " + totalBytesToDownload);
}
@Override
public void onProgressUpdate(String uniqueId, int progress) {
Log.e("DOWNLOAD", "IN ACTIVITY: " + "Progress: " + progress);
}
@Override
public void onError(String uniqueId, String error, String url) {
Log.e("DOWNLOAD", "IN ACTIVITY: ERROR :(((");
}
@Override
public void onLowFreeSpace(String uniqueId, String url) {
Log.e("DOWNLOAD", "Low Space...");
}
@Override
public void onFileReady(ChatResponse<ResultDownloadFile> response) {
Log.e("DOWNLOAD", "IN ACTIVITY: Finish File!!!!");
Log.e("DOWNLOAD", "File name: " + response.getResult().getFile().getName());
Log.e("DOWNLOAD", "Uri " + response.getResult().getUri());
Log.e("DOWNLOAD", "File Exist " + response.getResult().getFile().exists());
if (response.getResult().getFile().exists()) {
try {
Bitmap v = BitmapFactory.decodeFile(response.getResult().getFile().getAbsolutePath());
runOnUiThread(() -> {
// imageMap.setImageBitmap(v)
});
} catch (Exception e) {
e.printStackTrace();
Log.e("DOWNLOAD", "Not Image");
}
}
}
});
// downloadingId = presenter.downloadFile(requestGetImage, new ProgressHandler.IDownloadFile() {
//
//
// @Override
// public void onProgressUpdate(String uniqueId, int bytesDownloaded, int totalBytesToDownload) {
// Log.e("DOWNLOAD", "IN ACTIVITY: " + "Downloaded: " + bytesDownloaded + " Left: " + totalBytesToDownload);
//
// }
//
// @Override
// public void onProgressUpdate(String uniqueId, int progress) {
//
// }
//
// @Override
// public void onError(String uniqueId, String error, String url) {
// Log.e("DOWNLOAD", "IN ACTIVITY: ERROR :(((");
//
// }
//
// @Override
// public void onLowFreeSpace(String uniqueId, String url) {
// Log.e("DOWNLOAD", "Low Space...");
//
// }
//
// @Override
// public void onFileReady(ChatResponse<ResultDownloadFile> response) {
// Log.e("DOWNLOAD", "IN ACTIVITY: Finish File!!!!");
// Log.e("DOWNLOAD", "File name: " + response.getResult().getFile().getName());
// Log.e("DOWNLOAD", "Uri " + response.getResult().getUri());
// Log.e("DOWNLOAD", "File Exist " + response.getResult().getFile().exists());
//
//
// if (response.getResult().getFile().exists()) {
//
//
// try {
// Bitmap v = BitmapFactory.decodeFile(response.getResult().getFile().getAbsolutePath());
// runOnUiThread(() -> imageMap.setImageBitmap(v));
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// }
//
//
// }
//
// });
}
use of com.fanap.podchat.model.ChatResponse 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.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class MessagesCacheTest method sendReplyMessageAndCheckCache.
@Test
public void sendReplyMessageAndCheckCache() {
populateThreadsListFromServerOnly();
populateMessagesFromServer();
assert threads.size() > 0;
assert threadMessagesList.size() > 0;
Thread thread = threads.get(0);
MessageVO message = threadMessagesList.get(0);
ChatListener mTestListener = Mockito.mock(ChatListener.class);
chat.setListener(mTestListener);
String replyTXT = "Reply to " + message.getMessage();
RequestReplyMessage repRequest = new RequestReplyMessage.Builder(replyTXT, thread.getId(), message.getId(), TextMessageType.Constants.TEXT).build();
chat.replyMessage(repRequest, null);
Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onNewMessage(Mockito.any(), Mockito.any());
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).build();
chat.getHistory(requestGetHistory, null);
Mockito.verify(mTestListener, Mockito.after(2000).atLeastOnce()).onGetHistory(Mockito.any(), Mockito.argThat((ChatResponse<ResultHistory> response) -> response.isCache() && response.getResult().getHistory().stream().anyMatch(messageVO -> messageVO.getMessage().equals(replyTXT))));
}
Aggregations