Search in sources :

Example 11 with ChatResponse

use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method reformatThreadParticipants.

private ChatResponse<ResultParticipant> reformatThreadParticipants(Callback callback, ChatMessage chatMessage) {
    ArrayList<Participant> participants = new ArrayList<>();
    if (!Util.isNullOrEmpty(chatMessage.getContent())) {
        try {
            participants = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Participant>>() {
            }.getType());
        } catch (Exception e) {
            showErrorLog(e.getMessage());
            onUnknownException(chatMessage.getUniqueId(), e);
        }
    }
    if (cache) {
        List<CacheParticipant> cacheParticipants = new ArrayList<>();
        if (!Util.isNullOrEmpty(chatMessage.getContent())) {
            try {
                cacheParticipants = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<CacheParticipant>>() {
                }.getType());
            } catch (JsonSyntaxException e) {
                showErrorLog(e.getMessage());
                onUnknownException(chatMessage.getUniqueId(), e);
            }
        }
        if (!cacheParticipants.isEmpty())
            messageDatabaseHelper.saveParticipants(cacheParticipants, chatMessage.getSubjectId(), getExpireAmount());
    }
    ChatResponse<ResultParticipant> outPutParticipant = new ChatResponse<>();
    outPutParticipant.setErrorCode(0);
    outPutParticipant.setErrorMessage("");
    outPutParticipant.setHasError(false);
    outPutParticipant.setUniqueId(chatMessage.getUniqueId());
    outPutParticipant.setSubjectId(chatMessage.getSubjectId());
    ResultParticipant resultParticipant = new ResultParticipant();
    resultParticipant.setContentCount(chatMessage.getContentCount());
    resultParticipant.setThreadId(chatMessage.getSubjectId());
    if (callback != null) {
        resultParticipant.setHasNext(participants.size() + callback.getOffset() < chatMessage.getContentCount());
        resultParticipant.setNextOffset(callback.getOffset() + participants.size());
    }
    resultParticipant.setParticipants(participants);
    outPutParticipant.setResult(resultParticipant);
    return outPutParticipant;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) ResultAddParticipant(com.fanap.podchat.model.ResultAddParticipant) ResultParticipant(com.fanap.podchat.model.ResultParticipant) Participant(com.fanap.podchat.mainmodel.Participant) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) RequestThreadParticipant(com.fanap.podchat.requestobject.RequestThreadParticipant) OutPutParticipant(com.fanap.podchat.model.OutPutParticipant) ResultParticipant(com.fanap.podchat.model.ResultParticipant) ChatResponse(com.fanap.podchat.model.ChatResponse) ArrayList(java.util.ArrayList) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) 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 12 with ChatResponse

use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method reformatNotSeenDuration.

private ChatResponse<ResultNotSeenDuration> reformatNotSeenDuration(ChatMessage chatMessage, Callback callback) {
    ChatResponse<ResultNotSeenDuration> response = new ChatResponse<>();
    Map<String, Long> idNotSeenPairs = new HashMap<>();
    JsonParser parser = new JsonParser();
    JsonObject jsonObject;
    try {
        jsonObject = parser.parse(chatMessage.getContent()).getAsJsonObject();
    } catch (Exception e) {
        captureError(e.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, chatMessage.getUniqueId(), e);
        return null;
    }
    for (String key : jsonObject.keySet()) {
        idNotSeenPairs.put(key, jsonObject.get(key).getAsLong());
    }
    ResultNotSeenDuration resultNotSeenDuration = new ResultNotSeenDuration();
    resultNotSeenDuration.setIdNotSeenPair(idNotSeenPairs);
    response.setResult(resultNotSeenDuration);
    return response;
}
Also used : ResultNotSeenDuration(com.fanap.podchat.model.ResultNotSeenDuration) HashMap(java.util.HashMap) ChatResponse(com.fanap.podchat.model.ChatResponse) 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) JsonParser(com.google.gson.JsonParser)

Example 13 with ChatResponse

use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.

the class ThreadManager method handleChangeThreadType.

public static ChatResponse<Thread> handleChangeThreadType(ChatMessage chatMessage) {
    ChatResponse<Thread> response = new ChatResponse<>();
    Thread thread = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<Thread>() {
    }.getType());
    response.setResult(thread);
    response.setUniqueId(chatMessage.getUniqueId());
    response.setCache(false);
    return response;
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) ChatResponse(com.fanap.podchat.model.ChatResponse) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestCreatePublicThread(com.fanap.podchat.chat.thread.public_thread.RequestCreatePublicThread) ChatThread(com.fanap.podchat.mainmodel.ChatThread)

Example 14 with ChatResponse

use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.

the class Mention method getMentionListResponse.

public static ChatResponse<ResultHistory> getMentionListResponse(ChatMessage chatMessage) {
    List<MessageVO> messageVOS = getMessageVOSFromChatMessage(chatMessage);
    ResultHistory resultHistory = new ResultHistory();
    resultHistory.setContentCount(chatMessage.getContentCount());
    resultHistory.setHistory(messageVOS);
    ChatResponse<ResultHistory> finalResponse = new ChatResponse<>();
    finalResponse.setResult(resultHistory);
    finalResponse.setUniqueId(chatMessage.getUniqueId());
    finalResponse.setSubjectId(chatMessage.getSubjectId());
    return finalResponse;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) MessageVO(com.fanap.podchat.mainmodel.MessageVO) ResultHistory(com.fanap.podchat.model.ResultHistory)

Example 15 with ChatResponse

use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.

the class MessageManager method prepareNewMessageResponse.

public static ChatResponse<ResultNewMessage> prepareNewMessageResponse(MessageVO newMessage, long threadId, String uniqueId) {
    ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
    ResultNewMessage editMessage = new ResultNewMessage();
    editMessage.setMessageVO(newMessage);
    editMessage.setThreadId(threadId);
    chatResponse.setResult(editMessage);
    chatResponse.setUniqueId(uniqueId);
    chatResponse.setSubjectId(threadId);
    return chatResponse;
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) ChatResponse(com.fanap.podchat.model.ChatResponse)

Aggregations

ChatResponse (com.fanap.podchat.model.ChatResponse)162 ChatListener (com.fanap.podchat.chat.ChatListener)38 Test (org.junit.Test)38 ArrayList (java.util.ArrayList)35 Thread (com.fanap.podchat.mainmodel.Thread)29 JsonSyntaxException (com.google.gson.JsonSyntaxException)29 ResultHistory (com.fanap.podchat.model.ResultHistory)28 LargeTest (android.support.test.filters.LargeTest)27 RequestThread (com.fanap.podchat.requestobject.RequestThread)27 PodChatException (com.fanap.podchat.util.PodChatException)26 MessageVO (com.fanap.podchat.mainmodel.MessageVO)25 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)23 IOException (java.io.IOException)23 JSONException (org.json.JSONException)22 ResultThreads (com.fanap.podchat.model.ResultThreads)21 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)21 SentryException (io.sentry.core.protocol.SentryException)21 FlakyTest (android.support.test.filters.FlakyTest)19 MediumTest (android.support.test.filters.MediumTest)19 Activity (android.app.Activity)17