Search in sources :

Example 1 with ResultThreadsSummary

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

the class ChatCore method getAllThreads.

private void getAllThreads() {
    if (cache) {
        String uniqueId = generateUniqueId();
        JsonObject content = new JsonObject();
        content.addProperty("summary", true);
        ChatMessage chatMessage = new ChatMessage();
        chatMessage.setContent(content.toString());
        chatMessage.setToken(getToken());
        chatMessage.setType(Constants.GET_THREADS);
        chatMessage.setTypeCode(getTypeCode());
        chatMessage.setUniqueId(uniqueId);
        ChatHandler handler = new ChatHandler() {

            @Override
            public void onGetThread(String data) {
                super.onGetThread(data);
                ArrayList<ResultThreadsSummary> result = gson.fromJson(data, new TypeToken<ArrayList<ResultThreadsSummary>>() {
                }.getType());
                ArrayList<Long> serverResultThreadIds = new ArrayList<>();
                for (ResultThreadsSummary rts : result) {
                    serverResultThreadIds.add((long) rts.getId());
                }
                messageDatabaseHelper.getThreadIdsList(t -> {
                    try {
                        if (t == null)
                            return;
                        List<Long> threadsIdsInCache = (List<Long>) t;
                        if (threadsIdsInCache.size() > 0) {
                            threadsIdsInCache.removeAll(serverResultThreadIds);
                            if (serverResultThreadIds.size() > 0) {
                                messageDatabaseHelper.deleteThreads(new ArrayList<>(threadsIdsInCache));
                                showLog("THREADS CACHE UPDATED", "");
                            }
                        }
                    } catch (Exception e) {
                        showErrorLog(e.getMessage());
                        onUnknownException(uniqueId, e);
                    }
                });
            }
        };
        // callback
        handlerSend.put(uniqueId, handler);
        JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
        jsonObject.remove("contentCount");
        jsonObject.remove("repliedTo");
        jsonObject.remove("subjectId");
        jsonObject.remove("time");
        sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "UPDATING_THREADS_CACHE");
    }
}
Also used : ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) ResultThreadsSummary(com.fanap.podchat.model.ResultThreadsSummary) ArrayList(java.util.ArrayList) 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) TypeToken(com.google.gson.reflect.TypeToken) ResultBlockList(com.fanap.podchat.model.ResultBlockList) RequestGetMentionList(com.fanap.podchat.chat.mention.model.RequestGetMentionList) RequestDeliveredMessageList(com.fanap.podchat.requestobject.RequestDeliveredMessageList) ArrayList(java.util.ArrayList) RequestBlockList(com.fanap.podchat.requestobject.RequestBlockList) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) RequestSeenMessageList(com.fanap.podchat.requestobject.RequestSeenMessageList) List(java.util.List)

Aggregations

RequestGetHashTagList (com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList)1 RequestGetMentionList (com.fanap.podchat.chat.mention.model.RequestGetMentionList)1 ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)1 ResultBlockList (com.fanap.podchat.model.ResultBlockList)1 ResultThreadsSummary (com.fanap.podchat.model.ResultThreadsSummary)1 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)1 RequestBlockList (com.fanap.podchat.requestobject.RequestBlockList)1 RequestDeliveredMessageList (com.fanap.podchat.requestobject.RequestDeliveredMessageList)1 RequestSeenMessageList (com.fanap.podchat.requestobject.RequestSeenMessageList)1 PodChatException (com.fanap.podchat.util.PodChatException)1 JsonObject (com.google.gson.JsonObject)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 TypeToken (com.google.gson.reflect.TypeToken)1 SentryException (io.sentry.core.protocol.SentryException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JSONException (org.json.JSONException)1