use of com.fanap.podchat.mainmodel.Participant in project pod-chat-android-sdk by FanapSoft.
the class MessageManager method prepareSeenMessageListResponse.
public static ChatResponse<ResultParticipant> prepareSeenMessageListResponse(ChatMessage chatMessage, long offset) {
ChatResponse<ResultParticipant> chatResponse = new ChatResponse<>();
chatResponse.setUniqueId(chatMessage.getUniqueId());
ResultParticipant resultParticipant = new ResultParticipant();
List<Participant> participants = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Participant>>() {
}.getType());
resultParticipant.setParticipants(participants);
resultParticipant.setContentCount(chatMessage.getContentCount());
resultParticipant.setNextOffset(offset + participants.size());
resultParticipant.setContentCount(chatMessage.getContentCount());
if (participants.size() + offset < chatMessage.getContentCount()) {
resultParticipant.setHasNext(true);
} else {
resultParticipant.setHasNext(false);
}
chatResponse.setResult(resultParticipant);
return chatResponse;
}
use of com.fanap.podchat.mainmodel.Participant 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.mainmodel.Participant in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method insertCacheAssistantVo.
private void insertCacheAssistantVo(AssistantVo assistantVo) {
CacheAssistantVo cacheFile = new CacheAssistantVo();
cacheFile.setRoles(assistantVo.getRoles());
cacheFile.setBlock(assistantVo.getBlock());
if (assistantVo.getParticipantVO() != null) {
Participant participant = assistantVo.getParticipantVO();
CacheParticipant pInCache = messageDao.getParticipant(participant.getId());
CacheParticipant cacheParticipant;
if (pInCache != null) {
cacheParticipant = new CacheParticipant(participant, pInCache.getThreadId());
} else {
cacheParticipant = new CacheParticipant(participant, 0);
}
cacheFile.setParticipantVOId(cacheParticipant.getId());
cacheFile.setInviteeId(cacheParticipant.getId());
messageDao.insertParticipant(cacheParticipant);
if (participant.getChatProfileVO() != null) {
participant.getChatProfileVO().setId(participant.getId());
messageDao.insertChatProfile(participant.getChatProfileVO());
}
}
cacheFile.setContactType(assistantVo.getContactType());
messageDao.insertCacheAssistantVo(cacheFile);
}
use of com.fanap.podchat.mainmodel.Participant 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.Participant in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method addPinnedMessageOfThread.
private void addPinnedMessageOfThread(ThreadVo threadVo) {
worker(() -> {
PinMessageVO pinnedMessage = messageDao.getThreadPinnedMessage(threadVo.getId());
if (pinnedMessage != null) {
// get cached participant
if (pinnedMessage.getParticipantId() > 0) {
CacheParticipant cacheParticipant = messageDao.getParticipant(pinnedMessage.getParticipantId());
if (cacheParticipant != null) {
// convert cached participant to participant
Participant participant = cacheToParticipantMapper(cacheParticipant, false, null);
pinnedMessage.setParticipant(participant);
}
}
threadVo.setPinMessageVO(pinnedMessage);
}
});
}
Aggregations