use of com.fanap.podchat.model.ResultNewMessage 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.model.ResultNewMessage 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.model.ResultNewMessage 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);
}
use of com.fanap.podchat.model.ResultNewMessage 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.model.ResultNewMessage 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);
}
Aggregations