use of com.fanap.podchat.mainmodel.MessageVO in project pod-chat-android-sdk by FanapSoft.
the class AssistantCacheTest method populateMessagesFromServer.
public void populateMessagesFromServer() {
populateThreadsListFromServerOnly();
assert threads.size() > 0;
Thread thread = threads.get(0);
chatListeners = new ChatListener() {
@Override
public void onGetHistory(String content, ChatResponse<ResultHistory> history) {
if (!history.isCache()) {
print("Received Message List Server: " + content);
threadMessagesList.addAll(history.getResult().getHistory().stream().filter(messageVO -> messageVO.getMessage() != null).collect(Collectors.toList()));
chat.removeListener(chatListeners);
resumeProcess();
}
}
};
chat.addListener(chatListeners);
RequestGetHistory requestGetHistory = new RequestGetHistory.Builder(thread.getId()).withNoCache().build();
chat.getHistory(requestGetHistory, null);
pauseProcess();
}
use of com.fanap.podchat.mainmodel.MessageVO in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method publishNewMessages.
private void publishNewMessages(List<MessageVO> newMessages, long threadId, String uniqueId) {
for (MessageVO messageVO : newMessages) {
try {
// gson.toJson(chatResponse);
ChatResponse<ResultNewMessage> chatResponse = MessageManager.preparepublishNewMessagesResponse(messageVO, threadId);
String json = gson.toJson(chatResponse);
listenerManager.callOnNewMessage(json, chatResponse);
long ownerId = 0;
if (messageVO.getParticipant() != null) {
ownerId = messageVO.getParticipant().getId();
}
showLog("RECEIVED_NEW_MESSAGE", json);
if (ownerId > 0 && ownerId != getUserId()) {
ChatMessage message = getChatMessage(messageVO);
String asyncContent = gson.toJson(message);
async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
setThreadCallbacks(threadId, uniqueId);
showLog("SEND_DELIVERY_MESSAGE", asyncContent);
}
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
}
}
use of com.fanap.podchat.mainmodel.MessageVO in project pod-chat-android-sdk by FanapSoft.
the class HashTagManager method getMentionListResponse.
public static ChatResponse<ResultHistory> getMentionListResponse(ChatMessage chatMessage) {
List<MessageVO> messageVOS = getMessageVOSFromChatMessage(chatMessage);
ResultHistory resultHistory = new ResultHistory();
resultHistory.setContentCount(chatMessage.getContentCount());
resultHistory.setHistory(messageVOS);
ChatResponse<ResultHistory> finalResponse = new ChatResponse<>();
finalResponse.setResult(resultHistory);
finalResponse.setUniqueId(chatMessage.getUniqueId());
finalResponse.setSubjectId(chatMessage.getSubjectId());
return finalResponse;
}
use of com.fanap.podchat.mainmodel.MessageVO in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleNewMessage.
/**
* When the new message arrived we send the deliver message to the sender user.
*/
private void handleNewMessage(ChatMessage chatMessage) {
try {
MessageVO messageVO = gson.fromJson(chatMessage.getContent(), MessageVO.class);
if (cache) {
dataSource.saveMessageResultFromServer(messageVO, chatMessage.getSubjectId());
}
ChatResponse<ResultNewMessage> chatResponse = new ChatResponse<>();
chatResponse.setUniqueId(chatMessage.getUniqueId());
chatResponse.setHasError(false);
chatResponse.setErrorCode(0);
chatResponse.setErrorMessage("");
ResultNewMessage resultNewMessage = new ResultNewMessage();
resultNewMessage.setMessageVO(messageVO);
resultNewMessage.setThreadId(chatMessage.getSubjectId());
chatResponse.setResult(resultNewMessage);
chatResponse.setSubjectId(chatMessage.getSubjectId());
String json = gson.toJson(chatResponse);
long ownerId = 0;
if (messageVO != null) {
ownerId = messageVO.getParticipant().getId();
}
if (sentryResponseLog) {
showLog("RECEIVED_NEW_MESSAGE", json);
} else {
showLog("RECEIVED_NEW_MESSAGE");
}
if (ownerId != getUserId()) {
if (messageVO != null) {
ChatMessage message = getChatMessage(messageVO);
String asyncContent = gson.toJson(message);
async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
setThreadCallbacks(chatMessage.getSubjectId(), chatMessage.getUniqueId());
showLog("SEND_DELIVERY_MESSAGE", asyncContent);
}
}
if (messageVO != null) {
handleOnNewMessageAdded(messageVO.getConversation(), chatMessage.getUniqueId());
}
listenerManager.callOnNewMessage(json, chatResponse);
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(chatMessage.getUniqueId(), e);
}
}
use of com.fanap.podchat.mainmodel.MessageVO in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method findEditedMessages.
private List<MessageVO> findEditedMessages(List<MessageVO> oldMessages, List<MessageVO> newMessages, String uniqueId, long threadId) {
Set<MessageVO> editedMessages = new HashSet<>();
for (MessageVO newMessage : newMessages) {
for (MessageVO oldMessage : oldMessages) {
if (oldMessage.isEdited(newMessage)) {
editedMessages.add(newMessage);
// gson.toJson(chatResponse);
ChatResponse<ResultNewMessage> chatResponse = MessageManager.prepareNewMessageResponse(newMessage, threadId, uniqueId);
showLog("RECEIVE_EDIT_MESSAGE", chatResponse.toString());
listenerManager.callOnEditedMessage(chatResponse.toString(), chatResponse);
messageCallbacks.remove(newMessage.getUniqueId());
}
}
}
return new ArrayList<>(editedMessages);
}
Aggregations