Search in sources :

Example 1 with Thread

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

the class ChatCore method retrieveThreadInfoFromServer.

private void retrieveThreadInfoFromServer(long threadId, boolean isThreadInfoUpdate) {
    if (chatReady) {
        String uniqueId = generateUniqueId();
        ChatMessageContent chatMessageContent = new ChatMessageContent();
        chatMessageContent.setCount(1);
        chatMessageContent.setOffset(0);
        ArrayList<Integer> threadIds = new ArrayList<>();
        threadIds.add((int) threadId);
        chatMessageContent.setThreadIds(threadIds);
        JsonObject content = (JsonObject) gson.toJsonTree(chatMessageContent);
        AsyncMessage asyncMessage = new AsyncMessage();
        asyncMessage.setContent(content.toString());
        asyncMessage.setType(Constants.GET_THREADS);
        asyncMessage.setTokenIssuer("1");
        asyncMessage.setToken(getToken());
        asyncMessage.setUniqueId(uniqueId);
        asyncMessage.setTypeCode(typeCode != null ? typeCode : getTypeCode());
        JsonObject jsonObject = (JsonObject) gson.toJsonTree(asyncMessage);
        threadInfoCompletor.put(uniqueId, chatMessage -> {
            ArrayList<Thread> threads = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Thread>>() {
            }.getType());
            if (!Util.isNullOrEmpty(threads)) {
                if (isThreadInfoUpdate)
                    onThreadInfoUpdated(threads.get(0), chatMessage.getUniqueId(), true);
                else
                    handleThreadInfoUpdated(threads.get(0), chatMessage.getUniqueId());
                threadInfoCompletor.remove(uniqueId);
            }
        });
        sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_GET_THREAD_INFO");
    } else {
        showErrorLog("Couldn't complete thread info because chat is not ready");
    }
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) TypeToken(com.google.gson.reflect.TypeToken) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ChatMessageContent(com.fanap.podchat.mainmodel.ChatMessageContent) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) HandlerThread(android.os.HandlerThread) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)

Example 2 with Thread

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

the class ChatCore method publishMutualThreadsList.

private String publishMutualThreadsList(String uniqueId, Long finalOffset, ThreadManager.ThreadResponse cacheThreadResponse) {
    ChatResponse<ResultThreads> chatResponse = new ChatResponse<>();
    List<Thread> threadList = cacheThreadResponse.getThreadList();
    chatResponse.setCache(true);
    long contentCount = cacheThreadResponse.getContentCount();
    ResultThreads resultThreads = new ResultThreads();
    resultThreads.setThreads(threadList);
    resultThreads.setContentCount(contentCount);
    chatResponse.setCache(true);
    if (threadList.size() + finalOffset < contentCount) {
        resultThreads.setHasNext(true);
    } else {
        resultThreads.setHasNext(false);
    }
    resultThreads.setNextOffset(finalOffset + threadList.size());
    chatResponse.setResult(resultThreads);
    chatResponse.setUniqueId(uniqueId);
    String result = gson.toJson(chatResponse);
    listenerManager.callOnGetMutualGroup(result, chatResponse);
    return result;
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) ChatResponse(com.fanap.podchat.model.ChatResponse) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) HandlerThread(android.os.HandlerThread) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)

Example 3 with Thread

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

the class ChatCore method reformatGetThreadsResponseForMutual.

/**
 * Reformat the get thread response
 */
private ChatResponse<ResultThreads> reformatGetThreadsResponseForMutual(ChatMessage chatMessage, long userId) {
    ChatResponse<ResultThreads> outPutThreads = new ChatResponse<>();
    ArrayList<Thread> threads = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Thread>>() {
    }.getType());
    if (cache) {
        // get threads summary shouldn't update cache
        if (!handlerSend.containsKey(chatMessage.getUniqueId())) {
            // messageDatabaseHelper.saveThreads(threads);
            dataSource.saveThreadResultFromServer(threads);
            dataSource.saveMutualThreadResultFromServer(threads, userId);
        }
    }
    ResultThreads resultThreads = new ResultThreads();
    resultThreads.setThreads(threads);
    resultThreads.setContentCount(chatMessage.getContentCount());
    outPutThreads.setErrorCode(0);
    outPutThreads.setErrorMessage("");
    outPutThreads.setHasError(false);
    outPutThreads.setUniqueId(chatMessage.getUniqueId());
    outPutThreads.setResult(resultThreads);
    return outPutThreads;
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) ResultThreads(com.fanap.podchat.model.ResultThreads) ChatResponse(com.fanap.podchat.model.ChatResponse) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) HandlerThread(android.os.HandlerThread) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)

Example 4 with Thread

use of com.fanap.podchat.mainmodel.Thread 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 5 with Thread

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

the class MessageDatabaseHelper method getThreadRaw.

public void getThreadRaw(Integer count, Long offset, @Nullable ArrayList<Integer> threadIds, @Nullable String threadName, boolean isNew, OnWorkDone listener) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    worker(() -> {
        String sQuery;
        final String ORDER = "order by pin desc,time desc";
        sQuery = "select * from ThreadVo " + ORDER;
        if (threadName != null && !isNew) {
            sQuery = "select * from ThreadVo where title LIKE '%" + threadName + "%' " + ORDER;
        }
        if (threadIds != null && threadIds.size() > 0 && !isNew) {
            StringBuilder stringBuilder = new StringBuilder();
            for (int id : threadIds) {
                stringBuilder.append(id).append(",");
            }
            String stringIds = stringBuilder.toString();
            String lastString = stringIds.replaceAll(",$", "");
            if (threadName != null) {
                sQuery = "select * from ThreadVo where id IN " + "(" + lastString + ")" + "AND title LIKE  '%" + threadName + "%' " + ORDER;
            } else {
                sQuery = "select * from ThreadVo where id IN " + "(" + lastString + ")" + " " + ORDER;
            }
        }
        // only threads with unreadCount > 0 if isNew == true
        if (isNew) {
            sQuery = "select * from ThreadVo where unreadCount > 0 " + ORDER;
        }
        long contentCount = 0;
        SimpleSQLiteQuery countQuery = new SimpleSQLiteQuery(sQuery.replaceFirst("select \\* ", "select count(id) "));
        contentCount = messageDao.getThreadContentCount(countQuery);
        sQuery += getPaging(count, offset);
        SimpleSQLiteQuery query = new SimpleSQLiteQuery(sQuery);
        List<ThreadVo> threadVos = messageDao.getThreadRaw(query);
        List<Thread> threads = new ArrayList<>();
        if (threadVos != null) {
            for (ThreadVo threadVo : threadVos) {
                if (threadVo.getId() == 0)
                    continue;
                CacheParticipant cacheParticipant;
                CacheReplyInfoVO cacheReplyInfoVO;
                Participant participant = null;
                ReplyInfoVO replyInfoVO = null;
                @Nullable MessageVO lastMessageVO = null;
                if (threadVo.getInviterId() > 0) {
                    threadVo.setInviter(messageDao.getInviter(threadVo.getInviterId()));
                }
                if (threadVo.getLastMessageVOId() > 0) {
                    threadVo.setLastMessageVO(messageDao.getLastMessageVO(threadVo.getLastMessageVOId()));
                    CacheMessageVO cacheLastMessageVO = threadVo.getLastMessageVO();
                    if (cacheLastMessageVO != null) {
                        if (cacheLastMessageVO.getParticipantId() != null) {
                            cacheParticipant = messageDao.getParticipant(cacheLastMessageVO.getParticipantId());
                            if (cacheParticipant != null) {
                                participant = cacheToParticipantMapper(cacheParticipant, null, null);
                            }
                        }
                        if (cacheLastMessageVO.getReplyInfoVOId() != null) {
                            cacheReplyInfoVO = messageDao.getReplyInfo(cacheLastMessageVO.getReplyInfoVOId());
                            if (cacheReplyInfoVO != null)
                                replyInfoVO = new ReplyInfoVO(cacheReplyInfoVO.getRepliedToMessageId(), cacheReplyInfoVO.getMessageType(), cacheReplyInfoVO.isDeleted(), cacheReplyInfoVO.getRepliedToMessage(), cacheReplyInfoVO.getSystemMetadata(), cacheReplyInfoVO.getMetadata(), cacheReplyInfoVO.getMessage(), cacheReplyInfoVO.getRepliedToMessageTime(), cacheReplyInfoVO.getRepliedToMessageNanos());
                        }
                        lastMessageVO = cacheMessageVoToMessageVoMapper(participant, replyInfoVO, null, cacheLastMessageVO);
                    }
                }
                // adding pinned message of thread if exist
                addPinnedMessageOfThread(threadVo);
                Thread thread = threadVoToThreadMapper(threadVo, lastMessageVO);
                threads.add(thread);
            }
        }
        listener.onWorkDone(threads);
        listener.onWorkDone(contentCount, threads);
    });
}
Also used : ArrayList(java.util.ArrayList) Thread(com.fanap.podchat.mainmodel.Thread) ThreadVo(com.fanap.podchat.cachemodel.ThreadVo) CacheThreadParticipant(com.fanap.podchat.cachemodel.CacheThreadParticipant) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) Participant(com.fanap.podchat.mainmodel.Participant) CacheCallParticipant(com.fanap.podchat.call.persist.CacheCallParticipant) SimpleSQLiteQuery(android.arch.persistence.db.SimpleSQLiteQuery) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) CacheReplyInfoVO(com.fanap.podchat.cachemodel.CacheReplyInfoVO) ReplyInfoVO(com.fanap.podchat.model.ReplyInfoVO) CacheReplyInfoVO(com.fanap.podchat.cachemodel.CacheReplyInfoVO) 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) Nullable(android.support.annotation.Nullable)

Aggregations

Thread (com.fanap.podchat.mainmodel.Thread)95 RequestThread (com.fanap.podchat.requestobject.RequestThread)79 Test (org.junit.Test)55 ChatListener (com.fanap.podchat.chat.ChatListener)53 ArrayList (java.util.ArrayList)42 ResultHistory (com.fanap.podchat.model.ResultHistory)36 LargeTest (android.support.test.filters.LargeTest)35 RequestMessage (com.fanap.podchat.requestobject.RequestMessage)33 Date (java.util.Date)30 ChatResponse (com.fanap.podchat.model.ChatResponse)22 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)22 MessageVO (com.fanap.podchat.mainmodel.MessageVO)20 SearchSystemMetadataRequest (com.fanap.podchat.chat.messge.SearchSystemMetadataRequest)16 NosqlSearchMetadataCriteria (com.fanap.podchat.mainmodel.NosqlSearchMetadataCriteria)16 ResultNewMessage (com.fanap.podchat.model.ResultNewMessage)16 ResultThreads (com.fanap.podchat.model.ResultThreads)16 FlakyTest (android.support.test.filters.FlakyTest)14 MediumTest (android.support.test.filters.MediumTest)14 Activity (android.app.Activity)10 Context (android.content.Context)10