Search in sources :

Example 11 with CacheParticipant

use of com.fanap.podchat.cachemodel.CacheParticipant in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method insertPinnedMessage.

private void insertPinnedMessage(Thread thread) {
    PinMessageVO pinMessageVO = thread.getPinMessageVO();
    pinMessageVO.setThreadId(thread.getId());
    try {
        Participant participant = pinMessageVO.getParticipant();
        if (participant != null) {
            String participantJson = App.getGson().toJson(participant);
            CacheParticipant cacheParticipant = App.getGson().fromJson(participantJson, CacheParticipant.class);
            messageDao.insertParticipant(cacheParticipant);
            pinMessageVO.setParticipantId(cacheParticipant.getId());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    messageDao.insertPinnedMessage(pinMessageVO);
}
Also used : 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) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 12 with CacheParticipant

use of com.fanap.podchat.cachemodel.CacheParticipant 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)

Example 13 with CacheParticipant

use of com.fanap.podchat.cachemodel.CacheParticipant in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method handleAddParticipant.

private void handleAddParticipant(ChatMessage chatMessage, String messageUniqueId) {
    Thread thread = gson.fromJson(chatMessage.getContent(), Thread.class);
    if (cache) {
        ThreadVo threadVo = gson.fromJson(chatMessage.getContent(), ThreadVo.class);
        List<CacheParticipant> cacheParticipants = threadVo.getParticipants();
        if (!Util.isNullOrEmpty(cacheParticipants))
            messageDatabaseHelper.saveParticipants(cacheParticipants, thread.getId(), getExpireAmount());
    }
    ChatResponse<ResultAddParticipant> chatResponse = ParticipantsManager.prepareAddParticipantResponse(chatMessage, thread);
    String jsonAddParticipant = gson.toJson(chatResponse);
    if (sentryResponseLog) {
        showLog("RECEIVE_ADD_PARTICIPANT", jsonAddParticipant);
    } else {
        showLog("RECEIVE_ADD_PARTICIPANT");
    }
    messageCallbacks.remove(messageUniqueId);
    listenerManager.callOnThreadAddParticipant(jsonAddParticipant, chatResponse);
}
Also used : ThreadVo(com.fanap.podchat.cachemodel.ThreadVo) ResultAddParticipant(com.fanap.podchat.model.ResultAddParticipant) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) 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 14 with CacheParticipant

use of com.fanap.podchat.cachemodel.CacheParticipant in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method insertParticipant.

private void insertParticipant(CacheMessageVO cacheMessageVO, ThreadVo threadVo) {
    cacheMessageVO.setParticipantId(threadVo.getLastMessageVO().getParticipant().getId());
    messageDao.insertLastMessageVO(cacheMessageVO);
    CacheParticipant cacheParticipantLastMessageVO = threadVo.getLastMessageVO().getParticipant();
    cacheParticipantLastMessageVO.setThreadId(threadVo.getId());
    messageDao.insertParticipant(threadVo.getLastMessageVO().getParticipant());
}
Also used : CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant)

Example 15 with CacheParticipant

use of com.fanap.podchat.cachemodel.CacheParticipant in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method savePinMessage.

public void savePinMessage(ChatResponse<ResultPinMessage> response, long subjectId) {
    worker(() -> {
        ResultPinMessage result = response.getResult();
        PinMessageVO pinMessageVO = new PinMessageVO();
        pinMessageVO.setThreadId(subjectId);
        pinMessageVO.setMessageId(result.getMessageId());
        pinMessageVO.setNotifyAll(result.isNotifyAll());
        pinMessageVO.setText(result.getText());
        pinMessageVO.setTime(result.getTime());
        if (result.getParticipant() != null) {
            Participant participant = result.getParticipant();
            String participantJson = App.getGson().toJson(participant);
            CacheParticipant cacheParticipant = App.getGson().fromJson(participantJson, CacheParticipant.class);
            messageDao.insertParticipant(cacheParticipant);
            pinMessageVO.setParticipantId(cacheParticipant.getId());
        }
        messageDao.insertPinnedMessage(pinMessageVO);
    });
}
Also used : 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) ResultPinMessage(com.fanap.podchat.chat.pin.pin_message.model.ResultPinMessage) PinMessageVO(com.fanap.podchat.mainmodel.PinMessageVO) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant)

Aggregations

CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)19 Participant (com.fanap.podchat.mainmodel.Participant)14 CacheThreadParticipant (com.fanap.podchat.cachemodel.CacheThreadParticipant)13 CacheCallParticipant (com.fanap.podchat.call.persist.CacheCallParticipant)12 PinMessageVO (com.fanap.podchat.mainmodel.PinMessageVO)9 ArrayList (java.util.ArrayList)9 CacheMessageVO (com.fanap.podchat.cachemodel.CacheMessageVO)7 CacheReplyInfoVO (com.fanap.podchat.cachemodel.CacheReplyInfoVO)6 GapMessageVO (com.fanap.podchat.cachemodel.GapMessageVO)6 ThreadVo (com.fanap.podchat.cachemodel.ThreadVo)6 MessageVO (com.fanap.podchat.mainmodel.MessageVO)6 Thread (com.fanap.podchat.mainmodel.Thread)6 ReplyInfoVO (com.fanap.podchat.model.ReplyInfoVO)5 ChatProfileVO (com.fanap.podchat.chat.user.profile.ChatProfileVO)4 IOException (java.io.IOException)4 ResultAddParticipant (com.fanap.podchat.model.ResultAddParticipant)3 CacheParticipantRoles (com.fanap.podchat.cachemodel.CacheParticipantRoles)2 ChatResponse (com.fanap.podchat.model.ChatResponse)2 OutPutParticipant (com.fanap.podchat.model.OutPutParticipant)2 ResultParticipant (com.fanap.podchat.model.ResultParticipant)2