use of com.fanap.podchat.mainmodel.MessageVO in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method findAndUpdateGaps.
private void findAndUpdateGaps(List<MessageVO> newMessagesFromServer, long threadId) {
Runnable jobFindAndInsertGap = () -> {
if (newMessagesFromServer.size() == 0)
return;
MessageVO lastMessage = newMessagesFromServer.get(newMessagesFromServer.size() - 1);
if (lastMessage.getPreviousId() == 0)
return;
List<CacheMessageVO> messages = messageDatabaseHelper.getMessageById(lastMessage.getPreviousId());
if (Util.isNullOrEmpty(messages)) {
GapMessageVO gapMessageVO = new GapMessageVO();
gapMessageVO.setId(lastMessage.getId());
gapMessageVO.setPreviousId(lastMessage.getPreviousId());
gapMessageVO.setThreadId(threadId);
gapMessageVO.setTime(lastMessage.getTime());
gapMessageVO.setUniqueId(lastMessage.getUniqueId());
messageDatabaseHelper.insertGap(gapMessageVO);
lastMessage.setHasGap(true);
dataSource.updateMessage(lastMessage, threadId);
// messageDatabaseHelper.updateMessage(lastMessage, threadId);
}
};
Runnable jobUpdateGaps = () -> {
List<GapMessageVO> gaps = messageDatabaseHelper.getAllGaps(threadId);
if (!Util.isNullOrEmpty(gaps)) {
Map<Long, Long> msgIdAndPreviousId = new HashMap<>();
for (GapMessageVO gapMessage : gaps) {
msgIdAndPreviousId.put(gapMessage.getPreviousId(), gapMessage.getId());
}
for (MessageVO newMessage : newMessagesFromServer) {
if (msgIdAndPreviousId.containsKey(newMessage.getId())) {
// delete gap that produced by this message
messageDatabaseHelper.deleteGapForMessageId(msgIdAndPreviousId.get(newMessage.getId()));
// set message gap field to false
messageDatabaseHelper.updateMessageGapState(msgIdAndPreviousId.get(newMessage.getId()), false);
}
}
}
};
PodThreadManager podThreadManager = new PodThreadManager();
podThreadManager.addTask(jobFindAndInsertGap);
podThreadManager.addTask(jobUpdateGaps);
podThreadManager.runTasksSynced();
}
use of com.fanap.podchat.mainmodel.MessageVO in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleEditMessage.
private void handleEditMessage(ChatMessage chatMessage, String messageUniqueId) {
if (sentryResponseLog) {
showLog("RECEIVE_EDIT_MESSAGE", gson.toJson(chatMessage));
} else {
showLog("RECEIVE_EDIT_MESSAGE");
}
ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
ResultNewMessage newMessage = new ResultNewMessage();
MessageVO messageVO = gson.fromJson(chatMessage.getContent(), MessageVO.class);
if (messageVO.getMessage().startsWith("#")) {
Log.e(TAG, "hashtag: " + "hello");
String hashtag = messageVO.getMessage().substring(0, messageVO.getMessage().indexOf(' '));
Log.e(TAG, "hashtag: " + hashtag);
}
if (cache) {
dataSource.updateMessageResultFromServer(messageVO, chatMessage.getSubjectId());
}
newMessage.setMessageVO(messageVO);
newMessage.setThreadId(chatMessage.getSubjectId());
chatResponse.setResult(newMessage);
chatResponse.setUniqueId(chatMessage.getUniqueId());
chatResponse.setSubjectId(chatMessage.getSubjectId());
String content = gson.toJson(chatResponse);
messageCallbacks.remove(messageUniqueId);
listenerManager.callOnEditedMessage(content, chatResponse);
}
use of com.fanap.podchat.mainmodel.MessageVO in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleForwardMessage.
private void handleForwardMessage(ChatMessage chatMessage) {
MessageVO messageVO = gson.fromJson(chatMessage.getContent(), MessageVO.class);
ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
ResultNewMessage resultMessage = new ResultNewMessage();
resultMessage.setThreadId(chatMessage.getSubjectId());
resultMessage.setMessageVO(messageVO);
chatResponse.setResult(resultMessage);
String json = gson.toJson(chatResponse);
long ownerId = 0;
if (messageVO != null) {
ownerId = messageVO.getParticipant().getId();
}
if (sentryResponseLog) {
showLog("RECEIVED_FORWARD_MESSAGE", json);
} else {
showLog("RECEIVED_FORWARD_MESSAGE");
}
if (ownerId != getUserId()) {
ChatMessage message = null;
if (messageVO != null) {
message = getChatMessage(messageVO);
}
String asyncContent = gson.toJson(message);
showLog("SEND_DELIVERY_MESSAGE", asyncContent);
async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
}
if (cache) {
dataSource.saveMessageResultFromServer(messageVO, chatMessage.getSubjectId());
}
listenerManager.callOnNewMessage(json, chatResponse);
}
use of com.fanap.podchat.mainmodel.MessageVO in project pod-chat-android-sdk by FanapSoft.
the class MessageManager method getFailedFromWaiting.
public static List<Failed> getFailedFromWaiting(List<WaitQueueCache> listCaches) {
List<Failed> listQueues = new ArrayList<>();
for (WaitQueueCache queueCache : listCaches) {
Failed failed = new Failed();
MessageVO messageVO = new MessageVO();
messageVO.setId(queueCache.getId());
messageVO.setMessage(queueCache.getMessage());
messageVO.setMessageType(queueCache.getMessageType());
messageVO.setMetadata(queueCache.getMetadata());
messageVO.setSystemMetadata(queueCache.getSystemMetadata());
failed.setMessageVo(messageVO);
failed.setThreadId(queueCache.getThreadId());
failed.setUniqueId(queueCache.getUniqueId());
listQueues.add(failed);
}
return listQueues;
}
use of com.fanap.podchat.mainmodel.MessageVO in project pod-chat-android-sdk by FanapSoft.
the class MessageManager method getUploadingFromUploadCache.
public static List<Uploading> getUploadingFromUploadCache(List<UploadingQueueCache> uploadingQueueCaches) {
List<Uploading> uploadingQueues = new ArrayList<>();
for (UploadingQueueCache queueCache : uploadingQueueCaches) {
Uploading uploadingQueue = new Uploading();
MessageVO messageVO = new MessageVO();
messageVO.setId(queueCache.getId());
messageVO.setMessage(queueCache.getMessage());
messageVO.setMessageType(queueCache.getMessageType());
messageVO.setMetadata(queueCache.getMetadata());
messageVO.setSystemMetadata(queueCache.getSystemMetadata());
uploadingQueue.setMessageVo(messageVO);
uploadingQueue.setThreadId(queueCache.getThreadId());
uploadingQueue.setUniqueId(queueCache.getUniqueId());
uploadingQueues.add(uploadingQueue);
}
return uploadingQueues;
}
Aggregations