use of com.fanap.podchat.cachemodel.CacheReplyInfoVO in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method saveHistory.
private void saveHistory(@NonNull List<CacheMessageVO> messageVOS, long threadId) {
worker(() -> {
for (CacheMessageVO cacheMessageVO : messageVOS) {
cacheMessageVO.setThreadVoId(threadId);
long time = cacheMessageVO.getTime();
long timeNanos = cacheMessageVO.getTimeNanos();
long pow = (long) Math.pow(10, 9);
long timestamp = ((time / 1000) * pow) + timeNanos;
cacheMessageVO.setTimeStamp(timestamp);
if (cacheMessageVO.getParticipant() != null) {
cacheMessageVO.setParticipantId(cacheMessageVO.getParticipant().getId());
messageDao.insertParticipant(cacheMessageVO.getParticipant());
}
if (cacheMessageVO.getConversation() != null) {
cacheMessageVO.setConversationId(cacheMessageVO.getConversation().getId());
}
if (cacheMessageVO.getForwardInfo() != null) {
cacheMessageVO.setForwardInfoId(cacheMessageVO.getForwardInfo().getId());
messageDao.insertForwardInfo(cacheMessageVO.getForwardInfo());
if (cacheMessageVO.getForwardInfo().getParticipant() != null) {
cacheMessageVO.getForwardInfo().setParticipantId(cacheMessageVO.getForwardInfo().getParticipant().getId());
messageDao.insertParticipant(cacheMessageVO.getForwardInfo().getParticipant());
}
}
if (cacheMessageVO.getReplyInfoVO() != null) {
CacheReplyInfoVO cacheReplyInfoVO = cacheMessageVO.getReplyInfoVO();
cacheMessageVO.setReplyInfoVOId(cacheReplyInfoVO.getRepliedToMessageId());
if (cacheReplyInfoVO.getParticipant() != null) {
CacheParticipant cacheReplyParticipant = cacheReplyInfoVO.getParticipant();
cacheReplyInfoVO.setParticipantId(cacheReplyParticipant.getId());
messageDao.insertParticipant(cacheReplyParticipant);
}
messageDao.insertReplyInfoVO(cacheReplyInfoVO);
}
}
messageDao.insertHistories(messageVOS);
});
}
use of com.fanap.podchat.cachemodel.CacheReplyInfoVO in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method getThreadRaw.
public void getThreadRaw(Integer count, Long offset, @Nullable ArrayList<Integer> threadIds, @Nullable String threadName, boolean isNew, OnWorkDone listener) throws RoomIntegrityException {
if (!canUseDatabase())
throw new RoomIntegrityException();
worker(() -> {
String sQuery;
final String ORDER = "order by pin desc,time desc";
sQuery = "select * from ThreadVo " + ORDER;
if (threadName != null && !isNew) {
sQuery = "select * from ThreadVo where title LIKE '%" + threadName + "%' " + ORDER;
}
if (threadIds != null && threadIds.size() > 0 && !isNew) {
StringBuilder stringBuilder = new StringBuilder();
for (int id : threadIds) {
stringBuilder.append(id).append(",");
}
String stringIds = stringBuilder.toString();
String lastString = stringIds.replaceAll(",$", "");
if (threadName != null) {
sQuery = "select * from ThreadVo where id IN " + "(" + lastString + ")" + "AND title LIKE '%" + threadName + "%' " + ORDER;
} else {
sQuery = "select * from ThreadVo where id IN " + "(" + lastString + ")" + " " + ORDER;
}
}
// only threads with unreadCount > 0 if isNew == true
if (isNew) {
sQuery = "select * from ThreadVo where unreadCount > 0 " + ORDER;
}
long contentCount = 0;
SimpleSQLiteQuery countQuery = new SimpleSQLiteQuery(sQuery.replaceFirst("select \\* ", "select count(id) "));
contentCount = messageDao.getThreadContentCount(countQuery);
sQuery += getPaging(count, offset);
SimpleSQLiteQuery query = new SimpleSQLiteQuery(sQuery);
List<ThreadVo> threadVos = messageDao.getThreadRaw(query);
List<Thread> threads = new ArrayList<>();
if (threadVos != null) {
for (ThreadVo threadVo : threadVos) {
if (threadVo.getId() == 0)
continue;
CacheParticipant cacheParticipant;
CacheReplyInfoVO cacheReplyInfoVO;
Participant participant = null;
ReplyInfoVO replyInfoVO = null;
@Nullable MessageVO lastMessageVO = null;
if (threadVo.getInviterId() > 0) {
threadVo.setInviter(messageDao.getInviter(threadVo.getInviterId()));
}
if (threadVo.getLastMessageVOId() > 0) {
threadVo.setLastMessageVO(messageDao.getLastMessageVO(threadVo.getLastMessageVOId()));
CacheMessageVO cacheLastMessageVO = threadVo.getLastMessageVO();
if (cacheLastMessageVO != null) {
if (cacheLastMessageVO.getParticipantId() != null) {
cacheParticipant = messageDao.getParticipant(cacheLastMessageVO.getParticipantId());
if (cacheParticipant != null) {
participant = cacheToParticipantMapper(cacheParticipant, null, null);
}
}
if (cacheLastMessageVO.getReplyInfoVOId() != null) {
cacheReplyInfoVO = messageDao.getReplyInfo(cacheLastMessageVO.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());
}
lastMessageVO = cacheMessageVoToMessageVoMapper(participant, replyInfoVO, null, cacheLastMessageVO);
}
}
// adding pinned message of thread if exist
addPinnedMessageOfThread(threadVo);
Thread thread = threadVoToThreadMapper(threadVo, lastMessageVO);
threads.add(thread);
}
}
listener.onWorkDone(threads);
listener.onWorkDone(contentCount, threads);
});
}
use of com.fanap.podchat.cachemodel.CacheReplyInfoVO in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method insertReplyInfo.
private CacheReplyInfoVO insertReplyInfo(CacheMessageVO cacheMessageVO, ThreadVo threadVo) {
CacheReplyInfoVO cacheReplyInfoVO;
cacheReplyInfoVO = threadVo.getLastMessageVO().getReplyInfoVO();
cacheMessageVO.setReplyInfoVOId(threadVo.getLastMessageVO().getReplyInfoVO().getRepliedToMessageId());
messageDao.insertLastMessageVO(cacheMessageVO);
if (cacheReplyInfoVO.getParticipant() != null) {
cacheReplyInfoVO.setParticipantId(cacheReplyInfoVO.getParticipant().getId());
messageDao.insertParticipant(cacheMessageVO.getReplyInfoVO().getParticipant());
}
messageDao.insertReplyInfoVO(cacheReplyInfoVO);
return cacheReplyInfoVO;
}
use of com.fanap.podchat.cachemodel.CacheReplyInfoVO in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method getThreadsByThreadName.
public List<Thread> getThreadsByThreadName(String threadName) {
List<Thread> threads;
List<ThreadVo> listThreadVo = messageDao.getThreadByName(50, 0, threadName);
if (listThreadVo != null) {
threads = new ArrayList<>();
for (ThreadVo threadVo : listThreadVo) {
CacheParticipant cacheParticipant;
CacheReplyInfoVO cacheReplyInfoVO;
Participant participant = null;
ReplyInfoVO replyInfoVO = null;
MessageVO lastMessageVO = null;
if (threadVo.getInviterId() > 0) {
threadVo.setInviter(messageDao.getInviter(threadVo.getInviterId()));
}
if (threadVo.getLastMessageVOId() > 0) {
threadVo.setLastMessageVO(messageDao.getLastMessageVO(threadVo.getLastMessageVOId()));
CacheMessageVO cacheLastMessageVO = threadVo.getLastMessageVO();
if (cacheLastMessageVO != null) {
if (cacheLastMessageVO.getParticipantId() != null) {
cacheParticipant = messageDao.getParticipant(cacheLastMessageVO.getParticipantId());
participant = cacheToParticipantMapper(cacheParticipant, null, null);
}
if (cacheLastMessageVO.getReplyInfoVOId() != null) {
cacheReplyInfoVO = messageDao.getReplyInfo(cacheLastMessageVO.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());
}
lastMessageVO = cacheMessageVoToMessageVoMapper(participant, replyInfoVO, null, cacheLastMessageVO);
}
}
// adding pinned message of thread if exist
addPinnedMessageOfThread(threadVo);
Thread thread = threadVoToThreadMapper(threadVo, lastMessageVO);
threads.add(thread);
}
} else {
return new ArrayList<>();
}
return threads;
}
use of com.fanap.podchat.cachemodel.CacheReplyInfoVO in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method updateThreadLastMessage.
private void updateThreadLastMessage(Thread thread, ThreadVo threadVo) {
CacheMessageVO cacheMessageVO = null;
CacheReplyInfoVO cacheReplyInfoVO;
CacheForwardInfo cacheForwardInfo;
if (thread.getLastMessageVO() != null)
cacheMessageVO = insertLastMessage(thread, threadVo);
if (cacheMessageVO == null)
return;
if (threadVo.getLastMessageVO().getParticipant() != null) {
insertParticipant(cacheMessageVO, threadVo);
}
if (threadVo.getLastMessageVO().getReplyInfoVO() != null) {
cacheReplyInfoVO = insertReplyInfo(cacheMessageVO, threadVo);
if (threadVo.getLastMessageVO().getReplyInfoVO().getParticipant() != null) {
insertReplyParticipant(cacheReplyInfoVO, threadVo);
}
}
if (threadVo.getLastMessageVO().getForwardInfo() != null) {
cacheForwardInfo = insertForwardInfo(cacheMessageVO, threadVo);
if (threadVo.getLastMessageVO().getForwardInfo().getParticipant() != null) {
insertForwardInfo(cacheForwardInfo, threadVo);
}
if (threadVo.getLastMessageVO().getForwardInfo().getConversation() != null) {
insertConversationSummary(cacheForwardInfo, threadVo);
}
}
}
Aggregations