Search in sources :

Example 1 with ChatMessageContent

use of com.fanap.podchat.mainmodel.ChatMessageContent in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method retrieveThreadInfoFromServer.

private void retrieveThreadInfoFromServer(long threadId, boolean isThreadInfoUpdate) {
    if (chatReady) {
        String uniqueId = generateUniqueId();
        ChatMessageContent chatMessageContent = new ChatMessageContent();
        chatMessageContent.setCount(1);
        chatMessageContent.setOffset(0);
        ArrayList<Integer> threadIds = new ArrayList<>();
        threadIds.add((int) threadId);
        chatMessageContent.setThreadIds(threadIds);
        JsonObject content = (JsonObject) gson.toJsonTree(chatMessageContent);
        AsyncMessage asyncMessage = new AsyncMessage();
        asyncMessage.setContent(content.toString());
        asyncMessage.setType(Constants.GET_THREADS);
        asyncMessage.setTokenIssuer("1");
        asyncMessage.setToken(getToken());
        asyncMessage.setUniqueId(uniqueId);
        asyncMessage.setTypeCode(typeCode != null ? typeCode : getTypeCode());
        JsonObject jsonObject = (JsonObject) gson.toJsonTree(asyncMessage);
        threadInfoCompletor.put(uniqueId, chatMessage -> {
            ArrayList<Thread> threads = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Thread>>() {
            }.getType());
            if (!Util.isNullOrEmpty(threads)) {
                if (isThreadInfoUpdate)
                    onThreadInfoUpdated(threads.get(0), chatMessage.getUniqueId(), true);
                else
                    handleThreadInfoUpdated(threads.get(0), chatMessage.getUniqueId());
                threadInfoCompletor.remove(uniqueId);
            }
        });
        sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_GET_THREAD_INFO");
    } else {
        showErrorLog("Couldn't complete thread info because chat is not ready");
    }
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) TypeToken(com.google.gson.reflect.TypeToken) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ChatMessageContent(com.fanap.podchat.mainmodel.ChatMessageContent) 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 2 with ChatMessageContent

use of com.fanap.podchat.mainmodel.ChatMessageContent in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method getContactMain.

private String getContactMain(int count, long offset, String username, boolean syncContact, String typeCode, boolean useCache, ChatHandler handler) {
    String uniqueId = generateUniqueId();
    int mCount = count > 0 ? count : 50;
    Runnable serverRequestTask = () -> {
        if (chatReady) {
            ChatMessageContent chatMessageContent = new ChatMessageContent();
            chatMessageContent.setOffset(offset);
            JsonObject jObj = (JsonObject) gson.toJsonTree(chatMessageContent);
            jObj.remove("lastMessageId");
            jObj.remove("firstMessageId");
            jObj.remove("count");
            jObj.addProperty("size", mCount);
            if (username != null)
                jObj.addProperty("username", username);
            AsyncMessage chatMessage = new AsyncMessage();
            chatMessage.setContent(jObj.toString());
            chatMessage.setType(Constants.GET_CONTACTS);
            chatMessage.setToken(getToken());
            chatMessage.setUniqueId(uniqueId);
            chatMessage.setTypeCode(Util.isNotNullOrEmpty(typeCode) ? typeCode : getTypeCode());
            chatMessage.setTokenIssuer("1");
            JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
            String asyncContent = jsonObject.toString();
            setCallBacks(null, null, null, !syncContact, Constants.GET_CONTACTS, offset, uniqueId);
            sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "GET_CONTACT_SEND");
            if (handler != null) {
                handler.onGetContact(uniqueId);
            }
        } else {
            captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
        }
    };
    if (cache && useCache) {
        dataSource.getContactData(count, offset, username).doOnCompleted(serverRequestTask::run).doOnError(exception -> {
            if (exception instanceof RoomIntegrityException) {
                disableCache();
            } else {
                captureError(exception.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, uniqueId);
            }
        }).onErrorResumeNext(Observable.empty()).subscribe(response -> {
            if (response != null && Util.isNotNullOrEmpty(response.getContactsList())) {
                showLog("SOURCE: " + response.getSource());
                publishContactResult(uniqueId, offset, new ArrayList<>(response.getContactsList()), (int) response.getContentCount());
            }
        });
    } else {
        serverRequestTask.run();
    }
    return uniqueId;
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) JsonObject(com.google.gson.JsonObject) ChatMessageContent(com.fanap.podchat.mainmodel.ChatMessageContent)

Example 3 with ChatMessageContent

use of com.fanap.podchat.mainmodel.ChatMessageContent in project pod-chat-android-sdk by FanapSoft.

the class ThreadManager method prepareThreadInfoFromServer.

public static String prepareThreadInfoFromServer(long threadId, String uniqueId, String typeCode, String mtypeCode, String token) {
    ChatMessageContent chatMessageContent = new ChatMessageContent();
    chatMessageContent.setCount(1);
    chatMessageContent.setOffset(0);
    ArrayList<Integer> threadIds = new ArrayList<>();
    threadIds.add((int) threadId);
    chatMessageContent.setThreadIds(threadIds);
    JsonObject content = (JsonObject) App.getGson().toJsonTree(chatMessageContent);
    AsyncMessage asyncMessage = new AsyncMessage();
    asyncMessage.setContent(content.toString());
    asyncMessage.setType(ChatMessageType.Constants.GET_THREADS);
    asyncMessage.setTokenIssuer("1");
    asyncMessage.setToken(token);
    asyncMessage.setUniqueId(uniqueId);
    asyncMessage.setTypeCode(typeCode != null ? typeCode : mtypeCode);
    JsonObject jsonObject = (JsonObject) App.getGson().toJsonTree(asyncMessage);
    return jsonObject.toString();
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ChatMessageContent(com.fanap.podchat.mainmodel.ChatMessageContent)

Example 4 with ChatMessageContent

use of com.fanap.podchat.mainmodel.ChatMessageContent in project pod-chat-android-sdk by FanapSoft.

the class ThreadManager method prepareGetThreadRequest.

public static String prepareGetThreadRequest(boolean isNew, int finalCount, long finalOffset, String threadName, ArrayList<Integer> threadIds, long creatorCoreUserId, long partnerCoreUserId, long partnerCoreContactId, String uniqueId, String typeCode, String mtypeCode, String token) {
    ChatMessageContent chatMessageContent = new ChatMessageContent();
    chatMessageContent.setNew(isNew);
    chatMessageContent.setCount(finalCount);
    chatMessageContent.setOffset(finalOffset);
    if (threadName != null) {
        chatMessageContent.setName(threadName);
    }
    JsonObject content;
    if (!Util.isNullOrEmpty(threadIds)) {
        chatMessageContent.setThreadIds(threadIds);
        content = (JsonObject) App.getGson().toJsonTree(chatMessageContent);
    } else {
        content = (JsonObject) App.getGson().toJsonTree(chatMessageContent);
        content.remove("threadIds");
    }
    if (creatorCoreUserId > 0) {
        content.addProperty("creatorCoreUserId", creatorCoreUserId);
    }
    if (partnerCoreUserId > 0) {
        content.addProperty("partnerCoreUserId", partnerCoreUserId);
    }
    if (partnerCoreContactId > 0) {
        content.addProperty("partnerCoreContactId", partnerCoreContactId);
    }
    if (!isNew)
        content.remove("new");
    content.remove("lastMessageId");
    content.remove("firstMessageId");
    AsyncMessage chatMessage = new AsyncMessage();
    chatMessage.setContent(content.toString());
    chatMessage.setType(ChatMessageType.Constants.GET_THREADS);
    chatMessage.setTokenIssuer("1");
    chatMessage.setToken(token);
    chatMessage.setUniqueId(uniqueId);
    chatMessage.setTypeCode(typeCode != null ? typeCode : mtypeCode);
    JsonObject jsonObject = (JsonObject) App.getGson().toJsonTree(chatMessage);
    jsonObject.remove("subjectId");
    return jsonObject.toString();
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject) ChatMessageContent(com.fanap.podchat.mainmodel.ChatMessageContent)

Aggregations

AsyncMessage (com.fanap.podchat.mainmodel.AsyncMessage)4 ChatMessageContent (com.fanap.podchat.mainmodel.ChatMessageContent)4 JsonObject (com.google.gson.JsonObject)4 ArrayList (java.util.ArrayList)2 HandlerThread (android.os.HandlerThread)1 PinThread (com.fanap.podchat.chat.pin.pin_thread.PinThread)1 RequestPinThread (com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)1 ResultPinThread (com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread)1 PublicThread (com.fanap.podchat.chat.thread.public_thread.PublicThread)1 RequestJoinPublicThread (com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread)1 ResultJoinPublicThread (com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread)1 Thread (com.fanap.podchat.mainmodel.Thread)1 ResultLeaveThread (com.fanap.podchat.model.ResultLeaveThread)1 ResultThread (com.fanap.podchat.model.ResultThread)1 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)1 RequestCreateThread (com.fanap.podchat.requestobject.RequestCreateThread)1 RequestLeaveThread (com.fanap.podchat.requestobject.RequestLeaveThread)1 RequestMuteThread (com.fanap.podchat.requestobject.RequestMuteThread)1 RequestThread (com.fanap.podchat.requestobject.RequestThread)1 TypeToken (com.google.gson.reflect.TypeToken)1