Search in sources :

Example 51 with AsyncMessage

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

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

Example 53 with AsyncMessage

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

the class PublicThread method joinPublicThread.

public static String joinPublicThread(RequestJoinPublicThread request, String uniqueId) {
    AsyncMessage message = new AsyncMessage();
    message.setContent(request.getUniqueName());
    message.setToken(CoreConfig.token);
    message.setType(ChatMessageType.Constants.JOIN_THREAD);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setUniqueId(uniqueId);
    message.setTypeCode(!Util.isNullOrEmpty(request.getTypeCode()) ? request.getTypeCode() : CoreConfig.typeCode);
    JsonObject tmp = (JsonObject) App.getGson().toJsonTree(message);
    tmp.remove("subjectId");
    return tmp.toString();
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject)

Example 54 with AsyncMessage

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

the class PingManager method createStatusPingRequest.

public static String createStatusPingRequest(StatusPingRequest request, String uniqueId) throws PodChatException {
    validateUpdateStatusRequest(request, uniqueId);
    // Map<String, Long> contentMap = new HashMap<>();
    JsonObject contentObj = new JsonObject();
    long locationId = request.isInChat() ? IN_CHAT_ID : request.isInThread() ? IN_THREAD_ID : request.isInContactsList() ? IN_CONTACTS_LIST_ID : IMPOSSIBLE_STATE_ID;
    // contentMap.put(LOCATION, locationId);
    contentObj.addProperty(LOCATION, locationId);
    if (request.isInThread())
        contentObj.addProperty(LOCATION_ID, request.getThreadId());
    AsyncMessage message = new AsyncMessage();
    message.setContent(contentObj.toString());
    message.setToken(CoreConfig.token);
    message.setType(ChatMessageType.Constants.LOCATION_PING);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setUniqueId(uniqueId);
    message.setTypeCode(!Util.isNullOrEmpty(request.getTypeCode()) ? request.getTypeCode() : CoreConfig.typeCode);
    JsonObject requestObj = (JsonObject) App.getGson().toJsonTree(message);
    requestObj.remove("subjectId");
    return requestObj.toString();
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject)

Example 55 with AsyncMessage

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

the class TagManager method createRemoveTagParticipantRequest.

public static String createRemoveTagParticipantRequest(RemoveTagParticipantRequest request, String uniqueId) {
    JsonArray participants = new JsonArray();
    for (Long p : request.getThreadIds()) {
        participants.add(p);
    }
    String content = "[{\"threadId\": 8688 }," + "{\"threadId\": 8730 }," + "{\"threadId\": 8729 }]";
    // String content = App.getGson().toJson(participants);
    AsyncMessage message = new ChatMessage();
    message.setType(ChatMessageType.Constants.REMOVE_TAG_PARTICIPANT);
    message.setToken(CoreConfig.token);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
    message.setContent(content);
    message.setSubjectId(request.getTagId());
    message.setUniqueId(uniqueId);
    return App.getGson().toJson(message);
}
Also used : JsonArray(com.google.gson.JsonArray) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) 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