Search in sources :

Example 16 with ChatResponse

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

the class MessageManager method preparepublishNewMessagesResponse.

public static ChatResponse<ResultNewMessage> preparepublishNewMessagesResponse(MessageVO messageVO, long threadId) {
    ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
    chatResponse.setUniqueId(messageVO.getUniqueId());
    chatResponse.setHasError(false);
    chatResponse.setErrorCode(0);
    chatResponse.setErrorMessage("");
    ResultNewMessage resultNewMessage = new ResultNewMessage();
    resultNewMessage.setMessageVO(messageVO);
    resultNewMessage.setThreadId(threadId);
    chatResponse.setResult(resultNewMessage);
    chatResponse.setSubjectId(threadId);
    return chatResponse;
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) ChatResponse(com.fanap.podchat.model.ChatResponse)

Example 17 with ChatResponse

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

the class MessageManager method prepareSeenMessageListResponse.

public static ChatResponse<ResultParticipant> prepareSeenMessageListResponse(ChatMessage chatMessage, long offset) {
    ChatResponse<ResultParticipant> chatResponse = new ChatResponse<>();
    chatResponse.setUniqueId(chatMessage.getUniqueId());
    ResultParticipant resultParticipant = new ResultParticipant();
    List<Participant> participants = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Participant>>() {
    }.getType());
    resultParticipant.setParticipants(participants);
    resultParticipant.setContentCount(chatMessage.getContentCount());
    resultParticipant.setNextOffset(offset + participants.size());
    resultParticipant.setContentCount(chatMessage.getContentCount());
    if (participants.size() + offset < chatMessage.getContentCount()) {
        resultParticipant.setHasNext(true);
    } else {
        resultParticipant.setHasNext(false);
    }
    chatResponse.setResult(resultParticipant);
    return chatResponse;
}
Also used : ResultParticipant(com.fanap.podchat.model.ResultParticipant) Participant(com.fanap.podchat.mainmodel.Participant) ResultParticipant(com.fanap.podchat.model.ResultParticipant) TypeToken(com.google.gson.reflect.TypeToken) ChatResponse(com.fanap.podchat.model.ChatResponse)

Example 18 with ChatResponse

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

the class PingManager method handleOnPingStatusSent.

public static ChatResponse<StatusPingResult> handleOnPingStatusSent(ChatMessage chatMessage) {
    StatusPingResult result = new StatusPingResult();
    ChatResponse<StatusPingResult> response = new ChatResponse<>();
    response.setResult(result);
    response.setCache(false);
    response.setHasError(false);
    response.setUniqueId(chatMessage.getUniqueId());
    return response;
}
Also used : StatusPingResult(com.fanap.podchat.chat.ping.result.StatusPingResult) ChatResponse(com.fanap.podchat.model.ChatResponse)

Example 19 with ChatResponse

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

the class UserRoles method handleOnGetUserRolesFromCache.

public static ChatResponse<ResultCurrentUserRoles> handleOnGetUserRolesFromCache(String uniqueId, RequestGetUserRoles request, CacheUserRoles cacheUserRole) {
    ArrayList<String> roles = new ArrayList<>(cacheUserRole.getRole());
    ResultCurrentUserRoles result = new ResultCurrentUserRoles();
    result.setRoles(roles);
    ChatResponse<ResultCurrentUserRoles> response = new ChatResponse<>();
    response.setResult(result);
    response.setUniqueId(uniqueId);
    response.setSubjectId(request.getThreadId());
    response.setCache(true);
    return response;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ArrayList(java.util.ArrayList) ResultCurrentUserRoles(com.fanap.podchat.chat.user.user_roles.model.ResultCurrentUserRoles)

Example 20 with ChatResponse

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

the class MessageDatabaseHelper method getThreadHistory.

public Observable<ChatResponse<ResultHistory>> getThreadHistory(@NonNull SearchSystemMetadataRequest request) {
    return rx.Observable.create(subscriber -> {
        List<MessageVO> messageVOS = new ArrayList<>();
        List<CacheMessageVO> cacheMessageVOS;
        long offset = request.getOffset();
        long count = request.getCount();
        String order = request.getOrder();
        offset = offset >= 0 ? offset : 0;
        count = count > 0 ? count : 50;
        if (Util.isNullOrEmpty(order)) {
            order = "desc";
        }
        String rawQuery = "SELECT * FROM CacheMessageVO WHERE threadVoId =" + request.getMessageThreadId();
        // rawQuery = rawQuery + " AND system_metadata_" + request.getMetadataCriteria().getField() + " >= " + request.getMetadataCriteria().getGte();
        long contentCount = messageDao.getHistoryContentCount(new SimpleSQLiteQuery(rawQuery.replaceFirst("SELECT \\* ", "SELECT COUNT(ID) ")));
        rawQuery = addOrderAndLimitAndOffset(offset, count, order, rawQuery);
        SupportSQLiteQuery sqLiteQuery = new SimpleSQLiteQuery(rawQuery);
        cacheMessageVOS = messageDao.getRawHistory(sqLiteQuery);
        prepareMessageVOs(messageVOS, cacheMessageVOS);
        List<Sending> sendingList = getAllSendingQueueByThreadId(request.getMessageThreadId());
        List<Uploading> uploadingList = getAllUploadingQueueByThreadId(request.getMessageThreadId());
        List<Failed> failedList = getAllWaitQueueCacheByThreadId(request.getMessageThreadId());
        ChatResponse<ResultHistory> chatResponse = new ChatResponse<>();
        chatResponse.setCache(true);
        ResultHistory resultHistory = new ResultHistory();
        resultHistory.setHistory(messageVOS);
        resultHistory.setNextOffset(request.getOffset() + messageVOS.size());
        resultHistory.setContentCount(contentCount);
        if (messageVOS.size() + request.getOffset() < contentCount) {
            resultHistory.setHasNext(true);
        } else {
            resultHistory.setHasNext(false);
        }
        resultHistory.setHistory(messageVOS);
        resultHistory.setSending(sendingList);
        resultHistory.setUploadingQueue(uploadingList);
        resultHistory.setFailed(failedList);
        chatResponse.setErrorCode(0);
        chatResponse.setHasError(false);
        chatResponse.setErrorMessage("");
        chatResponse.setResult(resultHistory);
        chatResponse.setCache(true);
        chatResponse.setSubjectId(request.getMessageThreadId());
        subscriber.onNext(chatResponse);
    });
}
Also used : Sending(com.fanap.podchat.cachemodel.queue.Sending) SupportSQLiteQuery(android.arch.persistence.db.SupportSQLiteQuery) Failed(com.fanap.podchat.cachemodel.queue.Failed) ArrayList(java.util.ArrayList) Uploading(com.fanap.podchat.cachemodel.queue.Uploading) ResultHistory(com.fanap.podchat.model.ResultHistory) SimpleSQLiteQuery(android.arch.persistence.db.SimpleSQLiteQuery) ChatResponse(com.fanap.podchat.model.ChatResponse) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) MessageVO(com.fanap.podchat.mainmodel.MessageVO) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO)

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