use of com.fanap.podchat.mainmodel.Participant in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method prepareMessageVOs.
private void prepareMessageVOs(List<MessageVO> messageVOS, List<CacheMessageVO> cacheMessageVOS) {
for (CacheMessageVO cacheMessageVO : cacheMessageVOS) {
Participant participant = null;
ReplyInfoVO replyInfoVO = null;
ForwardInfo forwardInfo = null;
ConversationSummery conversationSummery = null;
if (cacheMessageVO.getForwardInfoId() != null) {
cacheMessageVO.setForwardInfo(messageDao.getForwardInfo(cacheMessageVO.getForwardInfoId()));
}
if (cacheMessageVO.getParticipantId() != null) {
CacheParticipant cacheParticipant = messageDao.getParticipant(cacheMessageVO.getParticipantId());
if (cacheParticipant != null) {
ChatProfileVO profileVO = messageDao.getChatProfileVOById(cacheParticipant.getId());
cacheParticipant.setChatProfileVO(profileVO);
participant = cacheToParticipantMapper(cacheParticipant, null, null);
} else {
if (cacheMessageVO.getConversationId() > 0)
messageDao.deleteParticipant(cacheMessageVO.getConversationId(), cacheMessageVO.getParticipantId());
}
}
ThreadVo thread = messageDao.getThreadById(cacheMessageVO.getConversationId());
cacheMessageVO.setConversation(thread);
if (cacheMessageVO.getReplyInfoVOId() != null) {
CacheReplyInfoVO cacheReplyInfoVO = messageDao.getReplyInfo(cacheMessageVO.getReplyInfoVOId());
if (cacheReplyInfoVO != null) {
replyInfoVO = new ReplyInfoVO(cacheReplyInfoVO.getRepliedToMessageId(), cacheReplyInfoVO.getMessageType(), cacheReplyInfoVO.isDeleted(), cacheReplyInfoVO.getRepliedToMessage(), cacheReplyInfoVO.getSystemMetadata(), cacheReplyInfoVO.getMetadata(), cacheReplyInfoVO.getMessage(), cacheReplyInfoVO.getRepliedToMessageTime(), cacheReplyInfoVO.getRepliedToMessageNanos());
if (cacheReplyInfoVO.getParticipantId() > 0) {
CacheParticipant cacheParticipant = messageDao.getParticipant(cacheReplyInfoVO.getParticipantId());
if (cacheParticipant != null) {
Participant replyParticipant = cacheToParticipantMapper(cacheParticipant, false, null);
replyInfoVO.setParticipant(replyParticipant);
}
}
}
}
if (cacheMessageVO.getForwardInfo() != null) {
CacheForwardInfo cacheForwardInfo = messageDao.getForwardInfo(cacheMessageVO.getForwardInfoId());
if (cacheForwardInfo != null) {
if (cacheForwardInfo.getParticipantId() != null) {
CacheParticipant cacheParticipant = messageDao.getParticipant(cacheForwardInfo.getParticipantId());
if (cacheParticipant != null) {
participant = cacheToParticipantMapper(cacheParticipant, null, null);
}
}
if (Util.isNullOrEmpty(cacheForwardInfo.getConversationId())) {
// todo check it again
conversationSummery = messageDao.getConversationSummery(cacheForwardInfo.getConversationId());
}
forwardInfo = new ForwardInfo(participant, conversationSummery);
}
}
Thread msgThread = threadVoToThreadMapper(cacheMessageVO.getConversation(), null);
MessageVO messageVO = cacheMessageVoToMessageVoMapper(participant, replyInfoVO, forwardInfo, cacheMessageVO);
messageVO.setConversation(msgThread);
messageVOS.add(messageVO);
}
}
use of com.fanap.podchat.mainmodel.Participant in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method saveCallsHistory.
public void saveCallsHistory(ArrayList<CallVO> callsList) {
worker(() -> {
ArrayList<CacheCall> cacheCalls = new ArrayList<>();
for (CallVO call : callsList) {
CacheCall cacheCall = new CacheCall().fromCall(call);
cacheCalls.add(cacheCall);
if (cacheCall.isGroup()) {
for (Participant participant : cacheCall.getCallParticipants()) {
saveCallParticipant(participant, call.getId());
}
}
if (cacheCall.getPartnerParticipantVO() != null) {
saveCallParticipant(cacheCall.getPartnerParticipantVO(), call.getId());
}
if (call.getConversationVO() != null) {
saveNewThread(call.getConversationVO());
}
}
messageDao.insertCacheCalls(cacheCalls);
});
}
use of com.fanap.podchat.mainmodel.Participant in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method updateCashAssistantHistory.
public void updateCashAssistantHistory(OnWorkDone listener, List<AssistantHistoryVo> response) {
worker(() -> {
List<CacheAssistantHistoryVo> cashAssitantHistory = new ArrayList<>();
for (AssistantHistoryVo assistantVo : response) {
CacheAssistantHistoryVo cashAsisstantHistory = new CacheAssistantHistoryVo();
if (assistantVo.getParticipantVO() != null) {
Participant participant = assistantVo.getParticipantVO();
String participantJson = App.getGson().toJson(participant);
CacheParticipant cacheParticipant = App.getGson().fromJson(participantJson, CacheParticipant.class);
messageDao.insertParticipant(cacheParticipant);
cashAsisstantHistory.setParticipantVOId(assistantVo.getParticipantVO().getId());
}
cashAsisstantHistory.setActionTime(assistantVo.getActionTime());
cashAsisstantHistory.setActionType(assistantVo.getActionType());
cashAsisstantHistory.setActionName(assistantVo.getActionName());
cashAssitantHistory.add(cashAsisstantHistory);
}
messageDao.insertCacheAssistantHistoryVo(cashAssitantHistory);
listener.onWorkDone(true);
});
}
use of com.fanap.podchat.mainmodel.Participant in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method getCallHistory.
public void getCallHistory(GetCallHistoryRequest request, FunctionalListener callback) throws RoomIntegrityException {
if (!canUseDatabase())
throw new RoomIntegrityException();
worker(() -> {
request.setCount(request.getCount() > 0 ? request.getCount() : 50);
List<CacheCall> cacheCalls = new ArrayList<>();
long contentCount = 0;
if (request.getCreatorCoreUserId() > 0) {
cacheCalls = messageDao.getCachedCallByUserId(request.getCount(), request.getOffset(), request.getCreatorCoreUserId(), request.getType());
contentCount = messageDao.getCountOfCachedCallByUserId(request.getCreatorCoreUserId(), request.getType());
} else if (!Util.isNullOrEmpty(request.getCallIds())) {
if (request.getCallIds().size() > 1) {
String ids = "";
for (Long callId : request.getCallIds()) {
ids = ids.concat("" + callId + ", ");
}
ids = ids.substring(0, ids.lastIndexOf(","));
cacheCalls = messageDao.getCachedCallByIds(request.getCount(), request.getOffset(), ids);
contentCount = messageDao.getCountOfCachedCallByIds(ids);
} else {
CacheCall cacheCall = messageDao.getCachedCallById(request.getCallIds().get(0));
contentCount = 1;
cacheCalls.add(cacheCall);
}
} else if (request.getThreadId() != null && request.getThreadId() > 0) {
cacheCalls = messageDao.getCachedCallByTypeAndThreadId(request.getCount(), request.getOffset(), request.getType(), request.getThreadId());
contentCount = messageDao.getCountOfCachedCallByTypeAndThreadId(request.getType(), request.getThreadId());
} else {
cacheCalls = messageDao.getCachedCallByType(request.getCount(), request.getOffset(), request.getType());
contentCount = messageDao.getCountOfCachedCallByType(request.getType());
}
ArrayList<CallVO> callVOList = new ArrayList<>();
for (CacheCall cacheCall : cacheCalls) {
@Nullable CacheCallParticipant callPartnerParticipant = messageDao.getCachedCallParticipant(cacheCall.getPartnerParticipantId());
if (callPartnerParticipant != null) {
Participant partnerParticipant = callPartnerParticipant.toParticipant();
ChatProfileVO chatProfileVO = messageDao.getChatProfileVOById(partnerParticipant.getId());
partnerParticipant.setChatProfileVO(chatProfileVO);
cacheCall.setPartnerParticipantVO(partnerParticipant);
}
if (cacheCall.isGroup()) {
List<CacheCallParticipant> cacheCallParticipants = messageDao.getCachedCallParticipants(cacheCall.getId());
if (!Util.isNullOrEmpty(cacheCallParticipants)) {
List<Participant> callParticipantsList = new ArrayList<>();
for (CacheCallParticipant cacheCll : cacheCallParticipants) {
Participant callParticipant = cacheCll.toParticipant();
ChatProfileVO profileVO = messageDao.getChatProfileVOById(callParticipant.getId());
callParticipant.setChatProfileVO(profileVO);
callParticipantsList.add(callParticipant);
}
cacheCall.setCallParticipants(callParticipantsList);
}
}
CallVO call = cacheCall.toCallVo();
if (cacheCall.getThreadId() > 0) {
ThreadVo threadVo = messageDao.getThreadById(cacheCall.getThreadId());
Thread thread;
if (threadVo != null) {
thread = threadVoToThreadMapper(threadVo, null);
} else {
thread = new Thread();
thread.setId(cacheCall.getThreadId());
}
call.setConversationVO(thread);
}
callVOList.add(call);
}
callback.onWorkDone(contentCount, callVOList);
});
}
use of com.fanap.podchat.mainmodel.Participant in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method getThreadAdmins.
public void getThreadAdmins(long offset, long count, long threadId, FunctionalListener listener) throws RoomIntegrityException {
if (!canUseDatabase())
throw new RoomIntegrityException();
worker(() -> {
List<Participant> participants = new ArrayList<>();
List<CacheThreadParticipant> listCtp = messageDao.getAllThreadParticipants(offset, count, threadId);
long participantCount = messageDao.getParticipantCount(threadId);
if (listCtp == null) {
listener.onWorkDone(participantCount, participants);
} else {
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
Calendar c = Calendar.getInstance();
c.setTime(new Date());
Date nowDate = c.getTime();
for (CacheThreadParticipant threadParticipant : listCtp) {
try {
Date expireDate = format.parse(threadParticipant.getExpireDate());
long participantId = threadParticipant.getParticipantId();
if (expireDate != null) {
if (expireDate.compareTo(nowDate) < 0) {
messageDao.deleteCacheThreadParticipant(participantId);
} else {
CacheParticipant cParticipant = messageDao.getParticipant(participantId);
ChatProfileVO chatProfileVO = messageDao.getChatProfileVOById(cParticipant.getId());
if (chatProfileVO != null) {
cParticipant.setChatProfileVO(chatProfileVO);
}
List<String> roles = new ArrayList<>();
CacheParticipantRoles cachedRoles = messageDao.getParticipantRoles(participantId, threadId);
if (cachedRoles != null) {
if (cachedRoles.getRoles().size() > 0)
roles = cachedRoles.getRoles();
}
if (roles.size() > 0) {
Participant participant = cacheToParticipantMapper(cParticipant, true, roles);
participants.add(participant);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
listener.onWorkDone(participantCount, participants);
});
}
Aggregations