use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class AssistantManager method createBlockAssistantsRequest.
public static String createBlockAssistantsRequest(BlockUnblockAssistantRequest request, String uniqueId) {
String content = App.getGson().toJson(request.getAssistantVos());
AsyncMessage message = new ChatMessage();
message.setType(ChatMessageType.Constants.BLOCK_ASSISTANT);
message.setToken(CoreConfig.token);
message.setTokenIssuer(CoreConfig.tokenIssuer);
message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
message.setContent(content);
message.setUniqueId(uniqueId);
return App.getGson().toJson(message);
}
use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class AssistantManager method createGetAssistantHistoryRequest.
public static String createGetAssistantHistoryRequest(GetAssistantHistoryRequest request, String uniqueId) {
JsonObject content = new JsonObject();
AsyncMessage message = new ChatMessage();
message.setType(ChatMessageType.Constants.GET_ASSISTANT_HISTORY);
message.setToken(CoreConfig.token);
message.setTokenIssuer(CoreConfig.tokenIssuer);
message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
message.setContent(App.getGson().toJson(content));
message.setUniqueId(uniqueId);
return App.getGson().toJson(message);
}
use of com.fanap.podchat.mainmodel.ChatMessage 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.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method deliveredMessageList.
/**
* The replacement method is getMessageDeliveredList.
*/
private String deliveredMessageList(RequestDeliveredMessageList requestParams) {
String uniqueId;
uniqueId = generateUniqueId();
try {
if (chatReady) {
if (Util.isNullOrEmpty(requestParams.getCount())) {
requestParams.setCount(50);
}
JsonObject object = (JsonObject) gson.toJsonTree(requestParams);
object.remove("typeCode");
ChatMessage chatMessage = new ChatMessage(uniqueId, Constants.DELIVERED_MESSAGE_LIST, object.toString(), getToken());
String asyncContent = chatMessage.getJson(requestParams.getTypeCode(), getTypeCode()).toString();
setCallBacks(null, null, null, true, Constants.DELIVERED_MESSAGE_LIST, requestParams.getOffset(), uniqueId);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_DELIVERED_MESSAGE_LIST");
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
} catch (Throwable e) {
onUnknownException(uniqueId, e);
}
return uniqueId;
}
use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method editMessage.
/**
* Message can be edit when you pass the message id and the edited
* content in order to edit your Message.
*/
public String editMessage(int messageId, String messageContent, String systemMetaData, ChatHandler handler) {
String uniqueId = generateUniqueId();
try {
if (chatReady) {
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(Constants.EDIT_MESSAGE);
chatMessage.setToken(getToken());
chatMessage.setUniqueId(uniqueId);
chatMessage.setSubjectId(messageId);
chatMessage.setContent(messageContent);
chatMessage.setSystemMetadata(systemMetaData);
chatMessage.setTokenIssuer("1");
// chatMessage.setMessageType(TextMessageType.Constants.TEXT);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
if (Util.isNullOrEmpty(getTypeCode())) {
jsonObject.remove("typeCode");
} else {
jsonObject.remove("typeCode");
jsonObject.addProperty("typeCode", getTypeCode());
}
jsonObject.remove("metadata");
jsonObject.remove("contentCount");
jsonObject.remove("repliedTo");
jsonObject.remove("time");
jsonObject.remove("messageType");
String asyncContent = jsonObject.toString();
setCallBacks(null, null, null, true, Constants.EDIT_MESSAGE, null, uniqueId);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_EDIT_MESSAGE");
stopTyping();
if (handler != null) {
handler.onEditMessage(uniqueId);
}
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
} catch (Throwable e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
return uniqueId;
}
Aggregations