Search in sources :

Example 1 with Participant

use of com.fanap.podchat.mainmodel.Participant 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 Participant

use of com.fanap.podchat.mainmodel.Participant 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 Participant

use of com.fanap.podchat.mainmodel.Participant 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 Participant

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

the class CallPresenter method onNewMessage.

@Override
public void onNewMessage(String content, ChatResponse<ResultNewMessage> chatResponse) {
    if (CallRecordTracer.isRecordedFileMessage(chatResponse.getUniqueId())) {
        try {
            view.showMessage("تماس در مسیر زیر ذخیره شد: \n " + chatResponse.getResult().getMessageVO().getMetadata());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return;
    }
    // This is reject message from contact
    if (!callUniqueIds.contains(chatResponse.getUniqueId())) {
        if (Util.isNotNullOrEmpty(chatResponse.getResult().getMessageVO().getMessage())) {
            if (chatResponse.getResult().getMessageVO().getCallHistoryVO() == null) {
                String message = chatResponse.getResult().getMessageVO().getMessage();
                Participant participant = chatResponse.getResult().getMessageVO().getParticipant();
                view.updateStatus(participant.getName() + " گفت: " + message);
                view.showMessage(" ✉ " + participant.getName() + " : " + message);
            }
        }
    } else {
        callUniqueIds.remove(chatResponse.getUniqueId());
    }
}
Also used : ResultAddParticipant(com.fanap.podchat.model.ResultAddParticipant) ResultParticipant(com.fanap.podchat.model.ResultParticipant) Participant(com.fanap.podchat.mainmodel.Participant)

Example 5 with Participant

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

the class CallPresenter method onCallClientErrors.

@Override
public void onCallClientErrors(ChatResponse<CallClientErrorsResult> response) {
    CallErrorVO error = response.getResult().getCallErrorVO();
    Participant cp = error.getParticipant();
    if (error.getCode() == ChatConstant.ERROR_CODE_CAMERA_NOT_AVAILABLE) {
        view.showMessage("دوربین " + cp.getName() + " قابل استفاده نیست!");
    }
    if (error.getCode() == ChatConstant.ERROR_CODE_MICROPHONE_NOT_AVAILABLE) {
        view.showMessage("میکروفن " + cp.getName() + " قابل استفاده نیست!");
    }
}
Also used : ResultAddParticipant(com.fanap.podchat.model.ResultAddParticipant) ResultParticipant(com.fanap.podchat.model.ResultParticipant) Participant(com.fanap.podchat.mainmodel.Participant) CallErrorVO(com.fanap.podchat.call.model.CallErrorVO)

Aggregations

Participant (com.fanap.podchat.mainmodel.Participant)29 CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)22 CacheCallParticipant (com.fanap.podchat.call.persist.CacheCallParticipant)18 CacheThreadParticipant (com.fanap.podchat.cachemodel.CacheThreadParticipant)17 ArrayList (java.util.ArrayList)15 PinMessageVO (com.fanap.podchat.mainmodel.PinMessageVO)8 ChatResponse (com.fanap.podchat.model.ChatResponse)7 ResultParticipant (com.fanap.podchat.model.ResultParticipant)7 ThreadVo (com.fanap.podchat.cachemodel.ThreadVo)6 ChatProfileVO (com.fanap.podchat.chat.user.profile.ChatProfileVO)6 Thread (com.fanap.podchat.mainmodel.Thread)6 ResultAddParticipant (com.fanap.podchat.model.ResultAddParticipant)6 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)5 CacheReplyInfoVO (com.fanap.podchat.cachemodel.CacheReplyInfoVO)5 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)5 MessageVO (com.fanap.podchat.mainmodel.MessageVO)5 OutPutParticipant (com.fanap.podchat.model.OutPutParticipant)5 ReplyInfoVO (com.fanap.podchat.model.ReplyInfoVO)5 IOException (java.io.IOException)5 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)4