use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method retrieveAndUpdateThreadOnLastMessageDeleted.
public void retrieveAndUpdateThreadOnLastMessageDeleted(Thread thread, ThreadManager.ILastMessageChanged callback) {
worker(() -> {
long threadId = thread.getId();
ArrayList<Integer> tIds = new ArrayList<>();
tIds.add((int) threadId);
try {
getThreadRaw(1, (long) 0, tIds, null, false, threads -> {
List<Thread> threadList = (List<Thread>) threads;
if (!Util.isNullOrEmpty(threadList) && threadList.get(0).getId() > 0) {
Thread threadFromCache = threadList.get(0);
threadFromCache.setLastMessage(thread.getLastMessage());
threadFromCache.setLastMessageVO(thread.getLastMessageVO());
threadFromCache.setTime(thread.getTime());
threadFromCache.setUnreadCount(thread.getUnreadCount());
callback.onThreadExistInCache(threadFromCache);
saveNewThread(threadFromCache);
} else {
callback.threadNotFoundInCache();
}
});
} catch (RoomIntegrityException e) {
e.printStackTrace();
callback.threadNotFoundInCache();
}
});
}
use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method prepareTagList.
private List<TagVo> prepareTagList() {
List<CacheTagVo> tags = messageDao.getCacheTagVos();
List<TagVo> tagVos = new ArrayList<>();
for (CacheTagVo item : tags) {
TagVo tag = CacheTagVoToTagVoMapper(item);
long allUnreadCount = 0;
List<CacheTagParticipantVO> cacheTagParticipants = messageDao.getCacheTagParticipantVosByTagId(item.getTagId());
List<TagParticipantVO> tagParticipants = new ArrayList<>();
for (CacheTagParticipantVO cacheTagParticipantVO : cacheTagParticipants) {
TagParticipantVO cache = cacheTagParticipantVOToTagParticipantVOMapper(cacheTagParticipantVO);
if (messageDao.getThreadById(cacheTagParticipantVO.getThreadId()) != null) {
Thread thread = threadVoToThreadMapper(messageDao.getThreadById(cacheTagParticipantVO.getThreadId()), null);
cache.setConversationVO(thread);
// TODO it should be save in db. can save it when save tags on db
if (thread.getUnreadCount() > 0)
allUnreadCount = allUnreadCount + thread.getUnreadCount();
}
tagParticipants.add(cache);
}
tag.setTagParticipants(tagParticipants);
tag.setAllUnreadCount(allUnreadCount);
tagVos.add(tag);
}
return tagVos;
}
use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method retrieveAndUpdateThreadOnThreadInfoUpdated.
public void retrieveAndUpdateThreadOnThreadInfoUpdated(Thread thread, ThreadManager.ILastMessageChanged callback) {
worker(() -> {
long threadId = thread.getId();
ArrayList<Integer> tIds = new ArrayList<>();
tIds.add((int) threadId);
try {
getThreadRaw(1, (long) 0, tIds, null, false, threads -> {
List<Thread> threadList = (List<Thread>) threads;
if (!Util.isNullOrEmpty(threadList) && threadList.get(0).getId() > 0) {
Thread threadFromCache = threadList.get(0);
if (!Util.isNullOrEmpty(thread.getTitle()))
threadFromCache.setTitle(thread.getTitle());
if (!Util.isNullOrEmpty(thread.getImage()))
threadFromCache.setImage(thread.getImage());
if (!Util.isNullOrEmpty(thread.getDescription()))
threadFromCache.setDescription(thread.getDescription());
if (!Util.isNullOrEmpty(thread.getMetadata()))
threadFromCache.setMetadata(thread.getMetadata());
threadFromCache.setTime(thread.getTime());
threadFromCache.setUserGroupHash(thread.getUserGroupHash());
callback.onThreadExistInCache(threadFromCache);
saveNewThread(threadFromCache);
} else {
callback.threadNotFoundInCache();
}
});
} catch (RoomIntegrityException e) {
e.printStackTrace();
callback.threadNotFoundInCache();
}
});
}
use of com.fanap.podchat.mainmodel.Thread 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.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method getThreads.
public List<Thread> getThreads(long count, long offset) {
List<Thread> threads;
if (messageDao.getThreads(count, offset) != null) {
List<ThreadVo> threadVos = messageDao.getThreads(count, offset);
threads = new ArrayList<>();
CacheParticipant cacheParticipant;
CacheReplyInfoVO cacheReplyInfoVO;
Participant participant = null;
ReplyInfoVO replyInfoVO = null;
for (ThreadVo threadVo : threadVos) {
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);
}
// sort threads by last message time
Collections.sort(new ArrayList<>(threads), (o1, o2) -> Long.compare(o1.getLastMessageVO().getTime(), o2.getLastMessageVO().getTime()));
return threads;
} else {
threads = new ArrayList<>();
}
return threads;
}
Aggregations