Search in sources :

Example 21 with ChatMessage

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

the class ChatCore method unMuteThread.

/**
 * It Un mutes the thread so notification is on for that thread
 */
public String unMuteThread(RequestMuteThread request, ChatHandler handler) {
    String uniqueId;
    uniqueId = generateUniqueId();
    JsonObject jsonObject = null;
    try {
        if (chatReady) {
            long threadId = request.getThreadId();
            String typeCode = request.getTypeCode();
            ChatMessage chatMessage = new ChatMessage();
            chatMessage.setType(Constants.UN_MUTE_THREAD);
            chatMessage.setToken(getToken());
            chatMessage.setTokenIssuer("1");
            chatMessage.setSubjectId(threadId);
            chatMessage.setUniqueId(uniqueId);
            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", request.getTypeCode());
            }
            setCallBacks(null, null, null, true, Constants.UN_MUTE_THREAD, null, uniqueId);
            sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_UN_MUTE_THREAD");
            if (handler != null) {
                handler.onUnMuteThread(uniqueId);
            }
        } 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 : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) 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 22 with ChatMessage

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

the class ChatCore method getChatMessage.

@NonNull
private ChatMessage getChatMessage(MessageVO jsonMessage) {
    ChatMessage message = new ChatMessage();
    message.setType(Constants.DELIVERY);
    message.setContent(String.valueOf(jsonMessage.getId()));
    message.setTokenIssuer("1");
    message.setToken(getToken());
    message.setUniqueId(generateUniqueId());
    message.setTime(1000);
    return message;
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) NonNull(android.support.annotation.NonNull)

Example 23 with ChatMessage

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

the class ChatCore method publishNewMessages.

private void publishNewMessages(List<MessageVO> newMessages, long threadId, String uniqueId) {
    for (MessageVO messageVO : newMessages) {
        try {
            // gson.toJson(chatResponse);
            ChatResponse<ResultNewMessage> chatResponse = MessageManager.preparepublishNewMessagesResponse(messageVO, threadId);
            String json = gson.toJson(chatResponse);
            listenerManager.callOnNewMessage(json, chatResponse);
            long ownerId = 0;
            if (messageVO.getParticipant() != null) {
                ownerId = messageVO.getParticipant().getId();
            }
            showLog("RECEIVED_NEW_MESSAGE", json);
            if (ownerId > 0 && ownerId != getUserId()) {
                ChatMessage message = getChatMessage(messageVO);
                String asyncContent = gson.toJson(message);
                async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
                setThreadCallbacks(threadId, uniqueId);
                showLog("SEND_DELIVERY_MESSAGE", asyncContent);
            }
        } catch (Exception e) {
            showErrorLog(e.getMessage());
            onUnknownException(uniqueId, e);
        }
    }
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO) 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 24 with ChatMessage

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

the class ContactManager method prepareGetBlockListRequest.

public static String prepareGetBlockListRequest(Long count, Long offset, String uniqueId, String typecode, String token) {
    JsonObject content = new JsonObject();
    if (offset != null) {
        content.addProperty("offset", offset);
    }
    if (count != null) {
        content.addProperty("count", count);
    } else {
        content.addProperty("count", 50);
    }
    ChatMessage chatMessage = new ChatMessage();
    chatMessage.setContent(content.toString());
    chatMessage.setType(ChatMessageType.Constants.GET_BLOCKED);
    chatMessage.setTokenIssuer("1");
    chatMessage.setToken(token);
    chatMessage.setUniqueId(uniqueId);
    JsonObject jsonObject = (JsonObject) App.getGson().toJsonTree(chatMessage);
    if (Util.isNullOrEmpty(typecode)) {
        jsonObject.remove("typeCode");
    } else {
        jsonObject.remove("typeCode");
        jsonObject.addProperty("typeCode", typecode);
    }
    return jsonObject.toString();
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) JsonObject(com.google.gson.JsonObject)

Example 25 with ChatMessage

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

the class AssistantManager method createGetBlockedAssistantsRequest.

public static String createGetBlockedAssistantsRequest(GetBlockedAssistantsRequest request, String uniqueId) {
    JsonObject content = new JsonObject();
    content.addProperty("contactType", request.getTypeCode());
    if ((Long) request.getOffset() != null) {
        content.addProperty("offset", request.getOffset());
    }
    if ((Long) request.getCount() != null) {
        content.addProperty("count", request.getCount());
    } else {
        content.addProperty("count", 50);
    }
    AsyncMessage message = new ChatMessage();
    message.setType(ChatMessageType.Constants.GET_BLOCKED_ASSISTANTS);
    message.setToken(CoreConfig.token);
    message.setTokenIssuer(CoreConfig.tokenIssuer);
    message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
    message.setContent(App.getGson().toJson(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)

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