Search in sources :

Example 1 with AsyncMessage

use of com.fanap.podchat.mainmodel.AsyncMessage 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 AsyncMessage

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

the class ThreadManager method createMutaulGroupRequest.

public static String createMutaulGroupRequest(GetMutualGroupRequest request, String uniqueId) {
    JsonObject content = (JsonObject) App.getGson().toJsonTree(request);
    content.remove("useCache");
    AsyncMessage message = new ChatMessage();
    message.setType(ChatMessageType.Constants.MUTUAL_GROUPS);
    message.setToken(CoreConfig.token);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setContent(content.toString());
    message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
    message.setUniqueId(uniqueId);
    return App.getGson().toJson(message);
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject)

Example 3 with AsyncMessage

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

the class ThreadManager method createCloseThreadRequest.

public static String createCloseThreadRequest(CloseThreadRequest request, String uniqueId) throws PodChatException {
    validateThreadId(request, uniqueId);
    AsyncMessage message = new ChatMessage();
    message.setType(ChatMessageType.Constants.CLOSE_THREAD);
    message.setToken(CoreConfig.token);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
    message.setSubjectId(request.getThreadId());
    message.setUniqueId(uniqueId);
    return App.getGson().toJson(message);
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage)

Example 4 with AsyncMessage

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

the class ThreadManager method prepareCreateThread.

public static String prepareCreateThread(RequestCreateThread request, String uniqueId, String typecode, String token) {
    JsonObject chatMessageContent = (JsonObject) App.getGson().toJsonTree(request);
    if (request instanceof RequestCreatePublicThread) {
        String uniqueName = ((RequestCreatePublicThread) request).getUniqueName();
        chatMessageContent.addProperty("uniqueName", uniqueName);
    }
    AsyncMessage chatMessage = new AsyncMessage();
    chatMessage.setContent(chatMessageContent.toString());
    chatMessage.setType(ChatMessageType.Constants.INVITATION);
    chatMessage.setToken(token);
    chatMessage.setUniqueId(uniqueId);
    chatMessage.setTokenIssuer("1");
    chatMessage.setTypeCode(Util.isNullOrEmpty(request.getTypeCode()) ? typecode : request.getTypeCode());
    String asyncContent = App.getGson().toJson(chatMessage);
    return asyncContent;
}
Also used : RequestCreatePublicThread(com.fanap.podchat.chat.thread.public_thread.RequestCreatePublicThread) AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject)

Example 5 with AsyncMessage

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

the class PublicThread method checkIfNameIsAvailable.

public static String checkIfNameIsAvailable(RequestCheckIsNameAvailable request, String uniqueId) {
    AsyncMessage message = new AsyncMessage();
    message.setContent(request.getUniqueName());
    message.setToken(CoreConfig.token);
    message.setType(ChatMessageType.Constants.IS_NAME_AVAILABLE);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setUniqueId(uniqueId);
    message.setTypeCode(!Util.isNullOrEmpty(request.getTypeCode()) ? request.getTypeCode() : CoreConfig.typeCode);
    return App.getGson().toJson(message);
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage)

Aggregations

AsyncMessage (com.fanap.podchat.mainmodel.AsyncMessage)78 JsonObject (com.google.gson.JsonObject)53 ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)20 PodChatException (com.fanap.podchat.util.PodChatException)7 JsonElement (com.google.gson.JsonElement)6 JsonArray (com.google.gson.JsonArray)5 ChatMessageContent (com.fanap.podchat.mainmodel.ChatMessageContent)4 ArrayList (java.util.ArrayList)4 SendClientDTO (com.fanap.podchat.call.model.SendClientDTO)3 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)3 PodThreadManager (com.fanap.podchat.util.PodThreadManager)3 CreateCallVO (com.fanap.podchat.call.model.CreateCallVO)2 TurnCallParticipantVideoOffRequest (com.fanap.podchat.call.request_model.TurnCallParticipantVideoOffRequest)2 Invitee (com.fanap.podchat.mainmodel.Invitee)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 TypeToken (com.google.gson.reflect.TypeToken)2 SentryException (io.sentry.core.protocol.SentryException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 JSONException (org.json.JSONException)2