Search in sources :

Example 36 with AsyncMessage

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

the class ChatCore method getThreadParticipantsMain.

private String getThreadParticipantsMain(int count, int offset, long threadId, String typeCode, boolean useCache, ChatHandler handler) {
    String uniqueId = generateUniqueId();
    final int mCount = count != 0 ? count : 50;
    PodThreadManager podThreadManager = new PodThreadManager();
    podThreadManager.addTask(() -> {
        if (cache && useCache) {
            loadParticipantsFromCache(uniqueId, mCount, offset, threadId);
        }
    });
    podThreadManager.addTask(() -> {
        if (chatReady) {
            JsonObject content = new JsonObject();
            content.addProperty("count", mCount);
            content.addProperty("offset", offset);
            AsyncMessage chatMessage = new AsyncMessage();
            chatMessage.setContent(content.toString());
            chatMessage.setType(Constants.THREAD_PARTICIPANTS);
            chatMessage.setTokenIssuer("1");
            chatMessage.setToken(getToken());
            chatMessage.setUniqueId(uniqueId);
            chatMessage.setSubjectId(threadId);
            chatMessage.setTypeCode(Util.isNullOrEmpty(typeCode) ? getTypeCode() : typeCode);
            JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
            String asyncContent = jsonObject.toString();
            setCallBacks(null, null, null, true, Constants.THREAD_PARTICIPANTS, (long) offset, uniqueId);
            sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_GET_THREAD_PARTICIPANT");
            if (handler != null) {
                handler.onGetThreadParticipant(uniqueId);
            }
        } else {
            captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
        }
    });
    podThreadManager.runTasksSynced();
    return uniqueId;
}
Also used : PodThreadManager(com.fanap.podchat.util.PodThreadManager) AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject)

Example 37 with AsyncMessage

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

the class ChatCore method pingAfterSetToken.

private void pingAfterSetToken() {
    AsyncMessage chatMessage = new AsyncMessage();
    chatMessage.setType(Constants.PING);
    chatMessage.setTokenIssuer("1");
    chatMessage.setToken(getToken());
    checkToken = true;
    String asyncContent = gson.toJson(chatMessage);
    async.sendMessage(asyncContent, AsyncAckType.Constants.WITH_ACK);
    showLog("**SEND_CHAT PING FOR CHECK TOKEN AUTHENTICATION", asyncContent);
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage)

Example 38 with AsyncMessage

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

the class ChatCore method ping.

/**
 * Ping for staying chat alive
 */
private void ping() {
    if (chatReady && async.getPeerId() != null) {
        AsyncMessage chatMessage = new AsyncMessage();
        chatMessage.setType(Constants.PING);
        chatMessage.setTokenIssuer("1");
        chatMessage.setToken(getToken());
        String asyncContent = gson.toJson(chatMessage);
        sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITH_ACK, "CHAT PING");
    }
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage)

Example 39 with AsyncMessage

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

the class BotManager method createCreateBotRequest.

public static String createCreateBotRequest(CreateBotRequest request, String uniqueId) throws PodChatException {
    validateBotName(request.getBotName());
    JsonObject content = new JsonObject();
    content.addProperty("botName", request.getBotName());
    AsyncMessage message = new AsyncMessage();
    message.setContent(request.getBotName());
    message.setToken(CoreConfig.token);
    message.setType(ChatMessageType.Constants.CREATE_BOT);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setUniqueId(uniqueId);
    message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
    return App.getGson().toJson(message);
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject)

Example 40 with AsyncMessage

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

the class BotManager method createStartBotRequest.

public static String createStartBotRequest(StartAndStopBotRequest request, String uniqueId) throws PodChatException {
    validateThreadId(request.getThreadId());
    validateBotName(request.getBotName());
    JsonObject content = new JsonObject();
    content.addProperty("botName", request.getBotName());
    AsyncMessage message = new AsyncMessage();
    message.setContent(content.toString());
    message.setToken(CoreConfig.token);
    message.setType(ChatMessageType.Constants.START_BOT);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setUniqueId(uniqueId);
    message.setSubjectId(request.getThreadId());
    message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
    return App.getGson().toJson(message);
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject)

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