use of com.fanap.podchat.mainmodel.Participant 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;
}
use of com.fanap.podchat.mainmodel.Participant in project pod-chat-android-sdk by FanapSoft.
the class MessageDatabaseHelper method getThreadsByThreadIds.
@NonNull
public List<Thread> getThreadsByThreadIds(@NonNull ArrayList<Integer> threadIds) {
List<Thread> threads = new ArrayList<>();
for (int id : threadIds) {
if (messageDao.getThreadById(id) != null) {
ThreadVo threadVo = messageDao.getThreadById(id);
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);
}
}
return threads;
}
use of com.fanap.podchat.mainmodel.Participant 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.mainmodel.Participant in project pod-chat-android-sdk by FanapSoft.
the class CallAsyncRequestsManager method handleStartedRecordCallResponse.
public static ChatResponse<Participant> handleStartedRecordCallResponse(ChatMessage chatMessage) {
ChatResponse<Participant> response = new ChatResponse<>();
Participant result = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<Participant>() {
}.getType());
response.setResult(result);
response.setUniqueId(chatMessage.getUniqueId());
response.setCache(false);
return response;
}
use of com.fanap.podchat.mainmodel.Participant 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;
}
Aggregations