Search in sources :

Example 1 with RequestFileMessage

use of com.fanap.podchat.requestobject.RequestFileMessage 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");
// 
// 
// }
// });
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) RequestFileMessage(com.fanap.podchat.requestobject.RequestFileMessage)

Example 2 with RequestFileMessage

use of com.fanap.podchat.requestobject.RequestFileMessage in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method createThreadWithFile.

// 
// 1. Create thread.
// 2.1. Upload thread image and update thread info if RequestUploadImage is set.
// 2.2. Upload file to server with thread userGroupHash and send uploaded file as message by sendFileMessage.
// 
public ArrayList<String> createThreadWithFile(RequestCreateThreadWithFile request, @Nullable ProgressHandler.sendFileMessage progressHandler) {
    ArrayList<String> uniqueIds = new ArrayList<>();
    String requestUniqueId = generateUniqueId();
    uniqueIds.add(requestUniqueId);
    if (needReadStoragePermission(request.getFile().getActivity()))
        return uniqueIds;
    if (chatReady) {
        handlerSend.put(requestUniqueId, new ChatHandler() {

            @Override
            public void onThreadCreated(ResultThread thread) {
                super.onThreadCreated(thread);
                if (request.getUploadThreadImageRequest() != null)
                    new PodThreadManager().doThisAndGo(() -> updateThreadImage(thread, request.getUploadThreadImageRequest()));
                RequestFileMessage.Builder requestFileBuilder = new RequestFileMessage.Builder(request.getMessage() != null ? request.getMessage().getText() : null, request.getFile().getActivity(), thread.getThread().getId(), request.getFile().getFileUri(), request.getMessage() != null ? request.getMessage().getSystemMetadata() : null, request.getMessageType(), thread.getThread().getUserGroupHash());
                if (request.getFile() instanceof RequestUploadImage) {
                    requestFileBuilder.setImageHc(String.valueOf(((RequestUploadImage) request.getFile()).gethC()));
                    requestFileBuilder.setImageWc(String.valueOf(((RequestUploadImage) request.getFile()).getwC()));
                    requestFileBuilder.setImageXc(String.valueOf(((RequestUploadImage) request.getFile()).getxC()));
                    requestFileBuilder.setImageYc(String.valueOf(((RequestUploadImage) request.getFile()).getyC()));
                }
                RequestFileMessage requestFile = requestFileBuilder.build();
                sendFileMessage(requestFile, requestUniqueId, progressHandler);
            }
        });
        RequestCreateThread requestCreateThread = new RequestCreateThread.Builder(request.getType(), request.getInvitees()).title(request.getTitle()).withDescription(request.getDescription()).withImage(request.getImage()).withMetadata(request.getMessage() != null ? request.getMessage().getSystemMetadata() : null).build();
        createThread(requestCreateThread, requestUniqueId);
    // prepareCreateThreadWithFile(request, requestUniqueId, innerMessageUniqueId, forwardUniqueIds, "");
    } else {
        captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, requestUniqueId);
    }
    return uniqueIds;
}
Also used : PodThreadManager(com.fanap.podchat.util.PodThreadManager) RequestUploadImage(com.fanap.podchat.requestobject.RequestUploadImage) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestFileMessage(com.fanap.podchat.requestobject.RequestFileMessage)

Aggregations

RequestFileMessage (com.fanap.podchat.requestobject.RequestFileMessage)2 ChatResponse (com.fanap.podchat.model.ChatResponse)1 ErrorOutPut (com.fanap.podchat.model.ErrorOutPut)1 ResultThread (com.fanap.podchat.model.ResultThread)1 RequestCreateThread (com.fanap.podchat.requestobject.RequestCreateThread)1 RequestUploadImage (com.fanap.podchat.requestobject.RequestUploadImage)1 PodThreadManager (com.fanap.podchat.util.PodThreadManager)1 GsonBuilder (com.google.gson.GsonBuilder)1 ArrayList (java.util.ArrayList)1