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);
}
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;
}
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);
}
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());
}
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);
});
}
Aggregations