Search in sources :

Example 1 with ResultThread

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

the class ChatCore method createThreadWithMessage.

/**
 * Create the thread with message is just for  p to p.( Thread Type is int NORMAL = 0)
 *
 * @return The first UniqueId is for create thread and the rest of them are for new message or forward messages
 * Its have three kind of Unique Ids. One of them is for message. One of them for Create Thread
 * and the others for Forward Message or Messages.
 * <p>
 * int messageType  Type of the Thread (You can have Thread Type from ThreadType.class)
 * String ownerSsoId  [Optional]
 * List<Invitee> invitees  you can add your invite list here
 * String title  [Optional] title of the group thread
 * <p>
 * RequestThreadInnerMessage message{  object of the inner message
 * <p>
 * -------------  String text  text of the message
 * -------------  int messageType  messageType of the message  [Optional]
 * -------------  String metadata  [Optional]
 * -------------  String systemMetadata  [Optional]
 * -------------  List<Long> forwardedMessageIds  [Optional]
 * }
 */
public ArrayList<String> createThreadWithMessage(RequestCreateThread threadRequest) {
    List<String> forwardUniqueIds;
    JsonObject innerMessageObj;
    JsonObject jsonObject;
    String threadUniqueId = generateUniqueId();
    ArrayList<String> uniqueIds = new ArrayList<>();
    uniqueIds.add(threadUniqueId);
    try {
        if (chatReady) {
            RequestThreadInnerMessage innerMessage = threadRequest.getMessage();
            innerMessageObj = (JsonObject) gson.toJsonTree(innerMessage);
            if (Util.isNullOrEmpty(threadRequest.getMessage().getType())) {
                innerMessageObj.remove("type");
            }
            if (Util.isNullOrEmpty(threadRequest.getMessage().getText())) {
                innerMessageObj.remove("message");
            } else {
                String newMsgUniqueId = generateUniqueId();
                innerMessageObj.addProperty("uniqueId", newMsgUniqueId);
                uniqueIds.add(newMsgUniqueId);
                setCallBacks(true, true, true, true, Constants.MESSAGE, null, newMsgUniqueId);
            }
            if (!Util.isNullOrEmptyNumber(threadRequest.getMessage().getForwardedMessageIds())) {
                /**
                 * Its generated new unique id for each forward message
                 */
                List<Long> messageIds = threadRequest.getMessage().getForwardedMessageIds();
                forwardUniqueIds = new ArrayList<>();
                for (long ids : messageIds) {
                    String frwMsgUniqueId = generateUniqueId();
                    forwardUniqueIds.add(frwMsgUniqueId);
                    uniqueIds.add(frwMsgUniqueId);
                    setCallBacks(true, true, true, true, Constants.MESSAGE, null, frwMsgUniqueId);
                }
                JsonElement element = gson.toJsonTree(forwardUniqueIds, new TypeToken<List<Long>>() {
                }.getType());
                JsonArray jsonArray = element.getAsJsonArray();
                innerMessageObj.add("forwardedUniqueIds", jsonArray);
            } else {
                innerMessageObj.remove("forwardedUniqueIds");
                innerMessageObj.remove("forwardedMessageIds");
            }
            JsonObject jsonObjectCreateThread = (JsonObject) gson.toJsonTree(threadRequest);
            jsonObjectCreateThread.remove("count");
            jsonObjectCreateThread.remove("offset");
            jsonObjectCreateThread.add("message", innerMessageObj);
            ChatMessage chatMessage = new ChatMessage();
            chatMessage.setContent(jsonObjectCreateThread.toString());
            chatMessage.setType(Constants.INVITATION);
            chatMessage.setUniqueId(threadUniqueId);
            chatMessage.setToken(getToken());
            chatMessage.setTokenIssuer("1");
            jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
            jsonObject.remove("repliedTo");
            jsonObject.remove("subjectId");
            jsonObject.remove("systemMetadata");
            jsonObject.remove("contentCount");
            String typeCode = threadRequest.getTypeCode();
            if (Util.isNullOrEmpty(typeCode)) {
                if (Util.isNullOrEmpty(getTypeCode())) {
                    jsonObject.remove("typeCode");
                } else {
                    jsonObject.addProperty("typeCode", getTypeCode());
                }
            } else {
                jsonObject.addProperty("typeCode", typeCode);
            }
            setCallBacks(null, null, null, true, Constants.INVITATION, null, threadUniqueId);
            if (threadRequest.getUploadThreadImageRequest() != null) {
                handlerSend.put(threadUniqueId, new ChatHandler() {

                    @Override
                    public void onThreadCreated(ResultThread thread) {
                        super.onThreadCreated(thread);
                        updateThreadImage(thread, threadRequest.getUploadThreadImageRequest());
                    }
                });
            }
            sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_CREATE_THREAD_WITH_MESSAGE");
        } else {
            captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, threadUniqueId);
        }
    } catch (Throwable e) {
        showErrorLog(e.getMessage());
        onUnknownException(uniqueIds.get(0), e);
    }
    return uniqueIds;
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) RequestThreadInnerMessage(com.fanap.podchat.mainmodel.RequestThreadInnerMessage) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) ResultThread(com.fanap.podchat.model.ResultThread)

Example 2 with ResultThread

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

the class ChatCore method handleRemoveFromThread.

private void handleRemoveFromThread(ChatMessage chatMessage) {
    ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
    ResultThread resultThread = new ResultThread();
    Thread thread = new Thread();
    thread.setId(chatMessage.getSubjectId());
    resultThread.setThread(thread);
    String content = gson.toJson(chatResponse);
    if (cache) {
        messageDatabaseHelper.deleteThread(chatMessage.getSubjectId());
    }
    if (sentryResponseLog) {
        showLog("RECEIVED_REMOVED_FROM_THREAD", content);
    } else {
        showLog("RECEIVED_REMOVED_FROM_THREAD");
    }
    listenerManager.callOnRemovedFromThread(content, 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 3 with ResultThread

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

the class ChatCore method onThreadLastMessageUpdated.

private void onThreadLastMessageUpdated(Thread thread, String uniqueId) {
    ResultThread resultThread = new ResultThread();
    resultThread.setThread(thread);
    ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
    chatResponse.setResult(resultThread);
    chatResponse.setUniqueId(uniqueId);
    chatResponse.setSubjectId(thread.getId());
    if (sentryResponseLog) {
        showLog("THREAD_INFO_UPDATED", chatResponse.getJson());
    } else {
        showLog("THREAD_INFO_UPDATED");
    }
    if (cache) {
        dataSource.saveThreadResultFromCache(thread);
    }
    listenerManager.callOnThreadInfoUpdated(chatResponse.getJson(), chatResponse);
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultThread(com.fanap.podchat.model.ResultThread)

Example 4 with ResultThread

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

the class ChatCore method handleThreadInfoUpdated.

private void handleThreadInfoUpdated(Thread thread, String uniqueId) {
    ResultThread resultThread = new ResultThread();
    resultThread.setThread(thread);
    ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
    chatResponse.setResult(resultThread);
    chatResponse.setUniqueId(uniqueId);
    listenerManager.callOnThreadInfoUpdated(chatResponse.getJson(), chatResponse);
    if (sentryResponseLog) {
        showLog("THREAD_INFO_UPDATED", chatResponse.getJson());
    } else {
        showLog("THREAD_INFO_UPDATED");
    }
    if (cache) {
        // messageDatabaseHelper.saveNewThread(resultThread.getThread());
        dataSource.saveThreadResultFromServer(thread);
    }
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultThread(com.fanap.podchat.model.ResultThread)

Example 5 with ResultThread

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

the class ChatCore method handleThreadInfoUpdated.

private void handleThreadInfoUpdated(ChatMessage chatMessage) {
    ResultThread resultThread = new ResultThread();
    Thread thread = gson.fromJson(chatMessage.getContent(), Thread.class);
    resultThread.setThread(thread);
    ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
    chatResponse.setResult(resultThread);
    chatResponse.setUniqueId(chatMessage.getUniqueId());
    if (sentryResponseLog) {
        showLog("THREAD_INFO_UPDATED", chatMessage.getContent());
    } else {
        showLog("THREAD_INFO_UPDATED");
    }
    if (cache) {
        dataSource.saveThreadResultFromServer(resultThread.getThread());
    }
    listenerManager.callOnThreadInfoUpdated(chatMessage.getContent(), 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)

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