Search in sources :

Example 21 with AsyncMessage

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

the class CallAsyncRequestsManager method createTurnOffVideoMessage.

public static String createTurnOffVideoMessage(long callId, String uniqueId) {
    ArrayList<Long> ids = new ArrayList<>();
    ids.add(CoreConfig.userId);
    TurnCallParticipantVideoOffRequest request = new TurnCallParticipantVideoOffRequest.Builder(callId, ids).build();
    AsyncMessage message = new AsyncMessage();
    message.setType(ChatMessageType.Constants.TURN_OFF_VIDEO_CALL);
    message.setToken(CoreConfig.token);
    message.setSubjectId(request.getCallId());
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setUniqueId(uniqueId);
    message.setTypeCode(Util.isNullOrEmpty(request.getTypeCode()) ? request.getTypeCode() : CoreConfig.typeCode);
    JsonObject a = (JsonObject) App.getGson().toJsonTree(message);
    return a.toString();
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) TurnCallParticipantVideoOffRequest(com.fanap.podchat.call.request_model.TurnCallParticipantVideoOffRequest) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Example 22 with AsyncMessage

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

the class CallAsyncRequestsManager method createEndShareScreenMessage.

public static String createEndShareScreenMessage(EndShareScreenRequest request, String uniqueId) {
    AsyncMessage message = new AsyncMessage();
    message.setType(ChatMessageType.Constants.END_SHARE_SCREEN);
    message.setToken(CoreConfig.token);
    message.setSubjectId(request.getCallId());
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setUniqueId(uniqueId);
    message.setTypeCode(Util.isNullOrEmpty(request.getTypeCode()) ? request.getTypeCode() : CoreConfig.typeCode);
    JsonObject jsonObject = (JsonObject) App.getGson().toJsonTree(message);
    return jsonObject.toString();
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject)

Example 23 with AsyncMessage

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

the class ChatCore method getThreadAdminsMain.

private String getThreadAdminsMain(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) {
            loadAdminsFromCache(uniqueId, mCount, offset, threadId);
        }
    });
    podThreadManager.addTask(() -> {
        if (chatReady) {
            JsonObject content = new JsonObject();
            content.addProperty("count", mCount);
            content.addProperty("offset", offset);
            content.addProperty("admin", true);
            AsyncMessage chatMessage = new AsyncMessage();
            chatMessage.setContent(content.toString());
            chatMessage.setType(Constants.THREAD_PARTICIPANTS);
            chatMessage.setTokenIssuer(String.valueOf(TOKEN_ISSUER));
            chatMessage.setToken(getToken());
            chatMessage.setUniqueId(uniqueId);
            chatMessage.setSubjectId(threadId);
            chatMessage.setTypeCode(typeCode != null ? typeCode : getTypeCode());
            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_ADMINS");
            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 24 with AsyncMessage

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

the class ChatCore method updateThreadInfo.

private String updateThreadInfo(long threadId, ThreadInfoVO threadInfoVO, String userGroupHash, RequestUploadImage requestUploadThreadPicture, ChatHandler handler) {
    String uniqueId = generateUniqueId();
    try {
        if (Util.isNullOrEmpty(userGroupHash)) {
            captureError(ChatConstant.ERROR_INVALID_USER_GROUP_HASH, ChatConstant.ERROR_CODE_INVALID_USER_GROUP_HASH, uniqueId);
            return uniqueId;
        }
        if (chatReady) {
            JsonObject threadMetadataObject;
            if (Util.isNullOrEmpty(threadInfoVO.getMetadata())) {
                threadMetadataObject = new JsonObject();
            } else {
                threadMetadataObject = parser.parse(threadInfoVO.getMetadata()).getAsJsonObject();
            }
            JsonObject contentObject = new JsonObject();
            contentObject.addProperty("name", threadInfoVO.getTitle());
            contentObject.addProperty("description", threadInfoVO.getDescription());
            Runnable updateThreadTask = () -> {
                String content = contentObject.toString();
                AsyncMessage chatMessage = new AsyncMessage();
                chatMessage.setContent(content);
                chatMessage.setTokenIssuer("1");
                chatMessage.setToken(getToken());
                chatMessage.setSubjectId(threadId);
                chatMessage.setUniqueId(uniqueId);
                chatMessage.setType(Constants.UPDATE_THREAD_INFO);
                JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
                jsonObject.remove("contentCount");
                jsonObject.remove("systemMetadata");
                // jsonObject.remove("metadata");
                jsonObject.remove("repliedTo");
                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.UPDATE_THREAD_INFO, null, uniqueId);
                sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_UPDATE_THREAD_INFO");
                if (handler != null) {
                    handler.onUpdateThreadInfo(uniqueId);
                }
            };
            uploadImageToThread(requestUploadThreadPicture, userGroupHash, uniqueId, null, hashCode -> {
                if (hashCode != null) {
                    String imageHashCode = (String) hashCode;
                    String imageLink = getPodSpaceImageUrl(imageHashCode);
                    threadMetadataObject.addProperty("fileHash", imageHashCode);
                    contentObject.addProperty("metadata", threadMetadataObject.toString());
                    contentObject.addProperty("image", imageLink);
                    updateThreadTask.run();
                }
            });
        } else {
            captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
        }
    } catch (Exception e) {
        showErrorLog(e.getMessage());
        onUnknownException(uniqueId, e);
    }
    return uniqueId;
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject) JSONException(org.json.JSONException) SentryException(io.sentry.core.protocol.SentryException) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) PodChatException(com.fanap.podchat.util.PodChatException) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException)

Example 25 with AsyncMessage

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

the class ChatCore method signalMessage.

private void signalMessage(RequestSignalMsg requestSignalMsg, String logMessage, String uniqueId) {
    int signalType = requestSignalMsg.getSignalType();
    long threadId = requestSignalMsg.getThreadId();
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("type", String.valueOf(signalType));
    AsyncMessage chatMessage = new AsyncMessage();
    chatMessage.setContent(jsonObject.toString());
    chatMessage.setType(Constants.SYSTEM_MESSAGE);
    chatMessage.setToken(getToken());
    chatMessage.setTokenIssuer(String.valueOf(TOKEN_ISSUER));
    chatMessage.setUniqueId(uniqueId);
    chatMessage.setSubjectId(threadId);
    sendAsyncMessage(gson.toJson(chatMessage), AsyncAckType.Constants.WITHOUT_ACK, logMessage);
}
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