Search in sources :

Example 6 with AsyncMessage

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

the class MessageManager method prepareMainHistoryResponse.

public static String prepareMainHistoryResponse(History history, long threadId, String uniqueId, String typecode, String token) {
    // long offsets = history.getOffset();
    long fromTime = history.getFromTime();
    long fromTimeNanos = history.getFromTimeNanos();
    long toTime = history.getToTime();
    long toTimeNanos = history.getToTimeNanos();
    String query = history.getQuery();
    JsonObject content = (JsonObject) App.getGson().toJsonTree(history);
    if (history.getLastMessageId() == 0) {
        content.remove("lastMessageId");
    }
    if (history.getFirstMessageId() == 0) {
        content.remove("firstMessageId");
    }
    if (history.getId() <= 0) {
        content.remove("id");
    }
    if (Util.isNullOrEmpty(query)) {
        content.remove("query");
    }
    if (Util.isNullOrEmpty(fromTime)) {
        content.remove("fromTime");
    }
    if (Util.isNullOrEmpty(fromTimeNanos)) {
        content.remove("fromTimeNanos");
    }
    if (Util.isNullOrEmpty(toTime)) {
        content.remove("toTime");
    }
    if (Util.isNullOrEmpty(toTimeNanos)) {
        content.remove("toTimeNanos");
    }
    if (history.getUniqueIds() == null) {
        content.remove("uniqueIds");
    }
    if (history.getMessageType() == 0) {
        content.remove("messageType");
    }
    AsyncMessage chatMessage = new AsyncMessage();
    chatMessage.setContent(content.toString());
    chatMessage.setType(ChatMessageType.Constants.GET_HISTORY);
    chatMessage.setToken(token);
    chatMessage.setTokenIssuer("1");
    chatMessage.setUniqueId(uniqueId);
    chatMessage.setSubjectId(threadId);
    chatMessage.setTypeCode(typecode);
    return App.getGson().toJsonTree(chatMessage).toString();
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) JsonObject(com.google.gson.JsonObject)

Example 7 with AsyncMessage

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

the class MessageManager method getAllUnreadMessgesCount.

public static String getAllUnreadMessgesCount(RequestGetUnreadMessagesCount request, String uniqueId) {
    JsonObject content = new JsonObject();
    content.addProperty("mute", request.withMuteThreads());
    AsyncMessage message = new AsyncMessage();
    message.setContent(content.toString());
    message.setToken(CoreConfig.token);
    message.setType(ChatMessageType.Constants.ALL_UNREAD_MESSAGE_COUNT);
    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 8 with AsyncMessage

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

the class TagManager method createTagListRequest.

public static String createTagListRequest(GetTagListRequest request, String uniqueId) {
    AsyncMessage message = new ChatMessage();
    message.setType(ChatMessageType.Constants.GET_TAG_LIST);
    message.setToken(CoreConfig.token);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    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)

Example 9 with AsyncMessage

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

the class TagManager method createAddTagRequest.

public static String createAddTagRequest(CreateTagRequest request, String uniqueId) {
    JsonObject contentObject = new JsonObject();
    if (request.getName() != null)
        contentObject.addProperty("name", request.getName());
    String content = App.getGson().toJson(contentObject);
    AsyncMessage message = new ChatMessage();
    message.setType(ChatMessageType.Constants.CREATE_TAG);
    message.setToken(CoreConfig.token);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
    message.setContent(content);
    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 10 with AsyncMessage

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

the class TagManager method createAddTagParticipantRequest.

public static String createAddTagParticipantRequest(AddTagParticipantRequest request, String uniqueId) {
    JsonArray participants = new JsonArray();
    for (Long p : request.getThreadIds()) {
        participants.add(p);
    }
    String content = App.getGson().toJson(participants);
    AsyncMessage message = new ChatMessage();
    message.setType(ChatMessageType.Constants.ADD_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