Search in sources :

Example 41 with ChatMessage

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

the class MessageManager method prepareSpamRequest.

public static String prepareSpamRequest(String uniqueId, RequestSpam request, String mtypeCode, String token) {
    JsonObject jsonObject;
    long threadId = request.getThreadId();
    String typeCode = request.getTypeCode();
    ChatMessage chatMessage = new ChatMessage();
    chatMessage.setType(ChatMessageType.Constants.SPAM_PV_THREAD);
    chatMessage.setTokenIssuer("1");
    chatMessage.setToken(CoreConfig.token);
    chatMessage.setUniqueId(uniqueId);
    chatMessage.setSubjectId(threadId);
    jsonObject = (JsonObject) App.getGson().toJsonTree(chatMessage);
    jsonObject.remove("contentCount");
    jsonObject.remove("systemMetadata");
    jsonObject.remove("metadata");
    jsonObject.remove("repliedTo");
    if (Util.isNullOrEmpty(typeCode)) {
        if (Util.isNullOrEmpty(mtypeCode)) {
            jsonObject.remove("typeCode");
        } else {
            jsonObject.addProperty("typeCode", CoreConfig.typeCode);
        }
    } else {
        jsonObject.addProperty("typeCode", request.getTypeCode());
    }
    return jsonObject.toString();
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) JsonObject(com.google.gson.JsonObject)

Example 42 with ChatMessage

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

the class MessageManager method prepareSpamRequest.

// for dericated method
public static String prepareSpamRequest(String uniqueId, String mtypeCode, long threadId, String token) {
    ChatMessage chatMessage = new ChatMessage();
    chatMessage.setType(ChatMessageType.Constants.SPAM_PV_THREAD);
    chatMessage.setTokenIssuer("1");
    chatMessage.setToken(token);
    chatMessage.setUniqueId(uniqueId);
    chatMessage.setSubjectId(threadId);
    JsonObject jsonObject = (JsonObject) App.getGson().toJsonTree(chatMessage);
    if (Util.isNullOrEmpty(mtypeCode)) {
        jsonObject.remove("typeCode");
    } else {
        jsonObject.remove("typeCode");
        jsonObject.addProperty("typeCode", mtypeCode);
    }
    String asyncContent = jsonObject.toString();
    return asyncContent;
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) JsonObject(com.google.gson.JsonObject)

Example 43 with ChatMessage

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

the class ThreadManager method prepareGetHIstoryWithUniqueIdsRequest.

public static String prepareGetHIstoryWithUniqueIdsRequest(long threadId, String uniqueId, String[] uniqueIds, String typeCode, String token) {
    RequestGetHistory request = new RequestGetHistory.Builder(threadId).offset(0).count(uniqueIds.length).uniqueIds(uniqueIds).build();
    String content = App.getGson().toJson(request);
    ChatMessage chatMessage = new ChatMessage();
    chatMessage.setContent(content);
    chatMessage.setType(ChatMessageType.Constants.GET_HISTORY);
    chatMessage.setToken(token);
    chatMessage.setTokenIssuer("1");
    chatMessage.setUniqueId(uniqueId);
    chatMessage.setSubjectId(threadId);
    JsonObject jsonObject = (JsonObject) App.getGson().toJsonTree(chatMessage);
    if (Util.isNullOrEmpty(typeCode)) {
        jsonObject.remove("typeCode");
    } else {
        jsonObject.remove("typeCode");
        jsonObject.addProperty("typeCode", typeCode);
    }
    String asyncContent = jsonObject.toString();
    return asyncContent;
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) JsonObject(com.google.gson.JsonObject)

Example 44 with ChatMessage

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

the class ThreadManager method createChangeThreadTypeRequest.

public static String createChangeThreadTypeRequest(ChangeThreadTypeRequest request, String uniqueId) throws PodChatException {
    JsonObject content = new JsonObject();
    content.addProperty("type", request.getType());
    if (request.getUniqname() != null)
        content.addProperty("uniqueName", request.getUniqname());
    AsyncMessage message = new ChatMessage();
    message.setType(ChatMessageType.Constants.CHANGE_THREAD_TYPE);
    message.setToken(CoreConfig.token);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setContent(content.toString());
    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) JsonObject(com.google.gson.JsonObject)

Example 45 with ChatMessage

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

the class ThreadManager method prepareCreateThread.

public static String prepareCreateThread(int threadType, Invitee[] invitee, String threadTitle, String description, String image, String metadata, String uniqueId, String typecode, String token) {
    List<Invitee> invitees = new ArrayList<Invitee>(Arrays.asList(invitee));
    ChatThread chatThread = new ChatThread();
    chatThread.setType(threadType);
    chatThread.setInvitees(invitees);
    chatThread.setTitle(threadTitle);
    JsonObject chatThreadObject = (JsonObject) App.getGson().toJsonTree(chatThread);
    if (Util.isNullOrEmpty(description)) {
        chatThreadObject.remove("description");
    } else {
        chatThreadObject.remove("description");
        chatThreadObject.addProperty("description", description);
    }
    if (Util.isNullOrEmpty(image)) {
        chatThreadObject.remove("image");
    } else {
        chatThreadObject.remove("image");
        chatThreadObject.addProperty("image", image);
    }
    if (Util.isNullOrEmpty(metadata)) {
        chatThreadObject.remove("metadata");
    } else {
        chatThreadObject.remove("metadata");
        chatThreadObject.addProperty("metadata", metadata);
    }
    String contentThreadChat = chatThreadObject.toString();
    ChatMessage chatMessage = getChatMessage(contentThreadChat, uniqueId, typecode, token);
    JsonObject jsonObject = (JsonObject) App.getGson().toJsonTree(chatMessage);
    if (Util.isNullOrEmpty(typecode)) {
        jsonObject.remove("typeCode");
    } else {
        jsonObject.remove("typeCode");
        jsonObject.addProperty("typeCode", typecode);
    }
    String asyncContent = jsonObject.toString();
    return asyncContent;
}
Also used : Invitee(com.fanap.podchat.mainmodel.Invitee) ChatThread(com.fanap.podchat.mainmodel.ChatThread) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Aggregations

ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)56 JsonObject (com.google.gson.JsonObject)33 AsyncMessage (com.fanap.podchat.mainmodel.AsyncMessage)20 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)9 PodChatException (com.fanap.podchat.util.PodChatException)9 JsonSyntaxException (com.google.gson.JsonSyntaxException)9 SentryException (io.sentry.core.protocol.SentryException)9 IOException (java.io.IOException)9 JSONException (org.json.JSONException)9 ArrayList (java.util.ArrayList)5 ChatResponse (com.fanap.podchat.model.ChatResponse)4 JsonArray (com.google.gson.JsonArray)4 NonNull (android.support.annotation.NonNull)3 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)3 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)3 MessageVO (com.fanap.podchat.mainmodel.MessageVO)3 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)3 JsonElement (com.google.gson.JsonElement)3 TypeToken (com.google.gson.reflect.TypeToken)3 SendingQueueCache (com.fanap.podchat.cachemodel.queue.SendingQueueCache)2