Search in sources :

Example 1 with ResultParticipant

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

the class ChatCore method loadAdminsFromCache.

private void loadAdminsFromCache(String uniqueId, int count, int offset, long threadId) {
    try {
        messageDatabaseHelper.getThreadAdmins(offset, count, threadId, (obj, listData) -> {
            List<Participant> participants = (List<Participant>) listData;
            long participantCount = (long) obj;
            if (participants != null) {
                ChatResponse<ResultParticipant> chatResponse = new ChatResponse<>();
                ResultParticipant resultParticipant = new ResultParticipant();
                resultParticipant.setThreadId(threadId);
                resultParticipant.setContentCount(participants.size());
                resultParticipant.setHasNext(participants.size() + offset < participantCount);
                resultParticipant.setParticipants(participants);
                chatResponse.setResult(resultParticipant);
                chatResponse.setCache(true);
                chatResponse.setUniqueId(uniqueId);
                chatResponse.setSubjectId(threadId);
                resultParticipant.setNextOffset(offset + participants.size());
                String jsonParticipant = gson.toJson(chatResponse);
                OutPutParticipant outPutParticipant = new OutPutParticipant();
                outPutParticipant.setResult(resultParticipant);
                listenerManager.callOnGetThreadAdmin(jsonParticipant, chatResponse);
                showLog("RECEIVE ADMINS FROM CACHE", jsonParticipant);
            }
        });
    } catch (RoomIntegrityException e) {
        disableCache();
    }
}
Also used : 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) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) ChatResponse(com.fanap.podchat.model.ChatResponse) 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) OutPutParticipant(com.fanap.podchat.model.OutPutParticipant)

Example 2 with ResultParticipant

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

the class ChatCore method loadParticipantsFromCache.

@SuppressWarnings("unchecked")
private void loadParticipantsFromCache(String uniqueId, int count, int offset, long threadId) {
    try {
        messageDatabaseHelper.getThreadParticipant(offset, count, threadId, (obj, listData) -> {
            if (listData != null) {
                List<Participant> participantsList = (List<Participant>) listData;
                long participantCount = (long) obj;
                ChatResponse<ResultParticipant> chatResponse = new ChatResponse<>();
                ResultParticipant resultParticipant = new ResultParticipant();
                resultParticipant.setContentCount(participantsList.size());
                resultParticipant.setHasNext(participantsList.size() + offset < participantCount);
                resultParticipant.setParticipants(participantsList);
                chatResponse.setResult(resultParticipant);
                chatResponse.setCache(true);
                chatResponse.setUniqueId(uniqueId);
                resultParticipant.setNextOffset(offset + participantsList.size());
                String jsonParticipant = gson.toJson(chatResponse);
                listenerManager.callOnGetThreadParticipant(jsonParticipant, chatResponse);
                showLog("PARTICIPANT FROM CACHE", jsonParticipant);
            }
        });
    } catch (RoomIntegrityException e) {
        disableCache();
    }
}
Also used : 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) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) ChatResponse(com.fanap.podchat.model.ChatResponse) 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)

Example 3 with ResultParticipant

use of com.fanap.podchat.model.ResultParticipant 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 4 with ResultParticipant

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

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

the class ChatCore method reformatThreadParticipantsForRemove.

private ChatResponse<ResultParticipant> reformatThreadParticipantsForRemove(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.deleteParticipant(chatMessage.getSubjectId(), cacheParticipants.get(0).getId());
        }
    }
    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)

Aggregations

ResultParticipant (com.fanap.podchat.model.ResultParticipant)7 Participant (com.fanap.podchat.mainmodel.Participant)6 ChatResponse (com.fanap.podchat.model.ChatResponse)6 RequestThreadParticipant (com.fanap.podchat.requestobject.RequestThreadParticipant)6 CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)5 OutPutParticipant (com.fanap.podchat.model.OutPutParticipant)5 ResultAddParticipant (com.fanap.podchat.model.ResultAddParticipant)5 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)5 ArrayList (java.util.ArrayList)4 PodChatException (com.fanap.podchat.util.PodChatException)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 SentryException (io.sentry.core.protocol.SentryException)3 IOException (java.io.IOException)3 JSONException (org.json.JSONException)3 RequestGetHashTagList (com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList)2 RequestGetMentionList (com.fanap.podchat.chat.mention.model.RequestGetMentionList)2 ResultBlockList (com.fanap.podchat.model.ResultBlockList)2 RequestBlockList (com.fanap.podchat.requestobject.RequestBlockList)2 RequestDeliveredMessageList (com.fanap.podchat.requestobject.RequestDeliveredMessageList)2 RequestSeenMessageList (com.fanap.podchat.requestobject.RequestSeenMessageList)2