use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method retrieveThreadInfoFromServer.
private void retrieveThreadInfoFromServer(long threadId, boolean isThreadInfoUpdate) {
if (chatReady) {
String uniqueId = generateUniqueId();
ChatMessageContent chatMessageContent = new ChatMessageContent();
chatMessageContent.setCount(1);
chatMessageContent.setOffset(0);
ArrayList<Integer> threadIds = new ArrayList<>();
threadIds.add((int) threadId);
chatMessageContent.setThreadIds(threadIds);
JsonObject content = (JsonObject) gson.toJsonTree(chatMessageContent);
AsyncMessage asyncMessage = new AsyncMessage();
asyncMessage.setContent(content.toString());
asyncMessage.setType(Constants.GET_THREADS);
asyncMessage.setTokenIssuer("1");
asyncMessage.setToken(getToken());
asyncMessage.setUniqueId(uniqueId);
asyncMessage.setTypeCode(typeCode != null ? typeCode : getTypeCode());
JsonObject jsonObject = (JsonObject) gson.toJsonTree(asyncMessage);
threadInfoCompletor.put(uniqueId, chatMessage -> {
ArrayList<Thread> threads = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Thread>>() {
}.getType());
if (!Util.isNullOrEmpty(threads)) {
if (isThreadInfoUpdate)
onThreadInfoUpdated(threads.get(0), chatMessage.getUniqueId(), true);
else
handleThreadInfoUpdated(threads.get(0), chatMessage.getUniqueId());
threadInfoCompletor.remove(uniqueId);
}
});
sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_GET_THREAD_INFO");
} else {
showErrorLog("Couldn't complete thread info because chat is not ready");
}
}
use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method publishMutualThreadsList.
private String publishMutualThreadsList(String uniqueId, Long finalOffset, ThreadManager.ThreadResponse cacheThreadResponse) {
ChatResponse<ResultThreads> chatResponse = new ChatResponse<>();
List<Thread> threadList = cacheThreadResponse.getThreadList();
chatResponse.setCache(true);
long contentCount = cacheThreadResponse.getContentCount();
ResultThreads resultThreads = new ResultThreads();
resultThreads.setThreads(threadList);
resultThreads.setContentCount(contentCount);
chatResponse.setCache(true);
if (threadList.size() + finalOffset < contentCount) {
resultThreads.setHasNext(true);
} else {
resultThreads.setHasNext(false);
}
resultThreads.setNextOffset(finalOffset + threadList.size());
chatResponse.setResult(resultThreads);
chatResponse.setUniqueId(uniqueId);
String result = gson.toJson(chatResponse);
listenerManager.callOnGetMutualGroup(result, chatResponse);
return result;
}
use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method reformatGetThreadsResponseForMutual.
/**
* Reformat the get thread response
*/
private ChatResponse<ResultThreads> reformatGetThreadsResponseForMutual(ChatMessage chatMessage, long userId) {
ChatResponse<ResultThreads> outPutThreads = new ChatResponse<>();
ArrayList<Thread> threads = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Thread>>() {
}.getType());
if (cache) {
// get threads summary shouldn't update cache
if (!handlerSend.containsKey(chatMessage.getUniqueId())) {
// messageDatabaseHelper.saveThreads(threads);
dataSource.saveThreadResultFromServer(threads);
dataSource.saveMutualThreadResultFromServer(threads, userId);
}
}
ResultThreads resultThreads = new ResultThreads();
resultThreads.setThreads(threads);
resultThreads.setContentCount(chatMessage.getContentCount());
outPutThreads.setErrorCode(0);
outPutThreads.setErrorMessage("");
outPutThreads.setHasError(false);
outPutThreads.setUniqueId(chatMessage.getUniqueId());
outPutThreads.setResult(resultThreads);
return outPutThreads;
}
use of com.fanap.podchat.mainmodel.Thread in project pod-chat-android-sdk by FanapSoft.
the class ThreadManager method handleChangeThreadType.
public static ChatResponse<Thread> handleChangeThreadType(ChatMessage chatMessage) {
ChatResponse<Thread> response = new ChatResponse<>();
Thread thread = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<Thread>() {
}.getType());
response.setResult(thread);
response.setUniqueId(chatMessage.getUniqueId());
response.setCache(false);
return response;
}
use of com.fanap.podchat.mainmodel.Thread 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);
});
}
Aggregations