Search in sources :

Example 6 with ResultThread

use of com.fanap.podchat.model.ResultThread 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)

Example 7 with ResultThread

use of com.fanap.podchat.model.ResultThread in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method reformatCreateThread.

private ChatResponse<ResultThread> reformatCreateThread(ChatMessage chatMessage) {
    ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
    chatResponse.setUniqueId(chatMessage.getUniqueId());
    ResultThread resultThread = new ResultThread();
    Thread thread = gson.fromJson(chatMessage.getContent(), Thread.class);
    resultThread.setThread(thread);
    chatResponse.setResult(resultThread);
    resultThread.setThread(thread);
    return chatResponse;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultThread(com.fanap.podchat.model.ResultThread) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) HandlerThread(android.os.HandlerThread) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)

Example 8 with ResultThread

use of com.fanap.podchat.model.ResultThread in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method onThreadInfoUpdated.

private void onThreadInfoUpdated(Thread thread, String uniqueId, boolean needCacheUpdate) {
    ResultThread resultThread = new ResultThread();
    resultThread.setThread(thread);
    ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
    chatResponse.setResult(resultThread);
    chatResponse.setUniqueId(uniqueId);
    chatResponse.setSubjectId(thread.getId());
    if (cache && needCacheUpdate) {
        dataSource.saveThreadResultFromServer(thread);
    }
    if (sentryResponseLog) {
        showLog("RECEIVE_UPDATE_THREAD_INFO", chatResponse.getJson());
    } else {
        showLog("RECEIVE_UPDATE_THREAD_INFO");
    }
    messageCallbacks.remove(uniqueId);
    listenerManager.callOnUpdateThreadInfo(chatResponse.getJson(), chatResponse);
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultThread(com.fanap.podchat.model.ResultThread)

Aggregations

ResultThread (com.fanap.podchat.model.ResultThread)8 ChatResponse (com.fanap.podchat.model.ChatResponse)6 RequestCreateThread (com.fanap.podchat.requestobject.RequestCreateThread)4 HandlerThread (android.os.HandlerThread)3 PinThread (com.fanap.podchat.chat.pin.pin_thread.PinThread)3 RequestPinThread (com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)3 ResultPinThread (com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread)3 PublicThread (com.fanap.podchat.chat.thread.public_thread.PublicThread)3 RequestJoinPublicThread (com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread)3 ResultJoinPublicThread (com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread)3 Thread (com.fanap.podchat.mainmodel.Thread)3 ResultLeaveThread (com.fanap.podchat.model.ResultLeaveThread)3 RequestLeaveThread (com.fanap.podchat.requestobject.RequestLeaveThread)3 RequestMuteThread (com.fanap.podchat.requestobject.RequestMuteThread)3 RequestThread (com.fanap.podchat.requestobject.RequestThread)3 ArrayList (java.util.ArrayList)2 ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)1 RequestThreadInnerMessage (com.fanap.podchat.mainmodel.RequestThreadInnerMessage)1 RequestFileMessage (com.fanap.podchat.requestobject.RequestFileMessage)1 RequestUploadImage (com.fanap.podchat.requestobject.RequestUploadImage)1