use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method createThreadWithMessage.
private void createThreadWithMessage(RequestCreateThreadWithFile request, String requestUniqueId, String innerMessageUniqueId, List<String> forwardUniqueIds) {
RequestCreateThreadWithMessage rctm = new RequestCreateThreadWithMessage.Builder(request.getType(), request.getInvitees(), request.getMessageType()).message(request.getMessage()).build();
JsonObject asyncRequestObject = null;
JsonObject innerMessageObj = null;
try {
if (chatReady) {
innerMessageObj = (JsonObject) gson.toJsonTree(request.getMessage());
if (Util.isNullOrEmpty(request.getMessage().getType())) {
innerMessageObj.remove("type");
}
if (Util.isNullOrEmpty(request.getMessage().getText())) {
innerMessageObj.remove("message");
} else {
innerMessageObj.addProperty("uniqueId", innerMessageUniqueId);
setCallBacks(true, true, true, true, Constants.MESSAGE, null, innerMessageUniqueId);
}
if (!Util.isNullOrEmpty(forwardUniqueIds)) {
JsonElement forwardMessageUniqueIdsJsonElement = gson.toJsonTree(forwardUniqueIds, new TypeToken<List<Long>>() {
}.getType());
JsonArray jsonArray = forwardMessageUniqueIdsJsonElement.getAsJsonArray();
innerMessageObj.add("forwardedUniqueIds", jsonArray);
} else {
innerMessageObj.remove("forwardedUniqueIds");
innerMessageObj.remove("forwardedMessageIds");
}
JsonObject jsonObjectCreateThread = (JsonObject) gson.toJsonTree(rctm);
jsonObjectCreateThread.remove("count");
jsonObjectCreateThread.remove("offset");
jsonObjectCreateThread.add("message", innerMessageObj);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setContent(jsonObjectCreateThread.toString());
chatMessage.setType(Constants.INVITATION);
chatMessage.setUniqueId(requestUniqueId);
chatMessage.setToken(getToken());
chatMessage.setTokenIssuer("1");
asyncRequestObject = (JsonObject) gson.toJsonTree(chatMessage);
asyncRequestObject.remove("repliedTo");
asyncRequestObject.remove("subjectId");
asyncRequestObject.remove("systemMetadata");
asyncRequestObject.remove("contentCount");
String typeCode = request.getTypeCode();
if (Util.isNullOrEmpty(typeCode)) {
if (Util.isNullOrEmpty(getTypeCode())) {
asyncRequestObject.remove("typeCode");
} else {
asyncRequestObject.addProperty("typeCode", getTypeCode());
}
} else {
asyncRequestObject.addProperty("typeCode", typeCode);
}
setCallBacks(null, null, null, true, Constants.INVITATION, null, requestUniqueId);
handlerSend.put(requestUniqueId, new ChatHandler() {
});
sendAsyncMessage(asyncRequestObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_CREATE_THREAD_WITH_FILE");
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, requestUniqueId);
}
} catch (Exception e) {
captureError(ChatConstant.ERROR_UNKNOWN_EXCEPTION, ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, requestUniqueId, e);
}
}
use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getNotSeenDuration.
public String getNotSeenDuration(RequestGetLastSeens requestGetLastSeens) {
String uniqueId = generateUniqueId();
ArrayList<Integer> userIdsList = requestGetLastSeens.getUserIds();
JsonObject jObj = new JsonObject();
JsonElement jsonElement = gson.toJsonTree(userIdsList);
jObj.add("userIds", jsonElement);
if (chatReady) {
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(Constants.GET_NOT_SEEN_DURATION);
chatMessage.setContent(jObj.toString());
chatMessage.setToken(getToken());
chatMessage.setTokenIssuer("1");
chatMessage.setUniqueId(uniqueId);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
jsonObject.remove("systemMetadata");
jsonObject.remove("metadata");
jsonObject.remove("repliedTo");
jsonObject.remove("contentCount");
jsonObject.remove("time");
jsonObject.remove("subjectId");
if (Util.isNullOrEmpty(getTypeCode())) {
jsonObject.remove("typeCode");
} else {
jsonObject.remove("typeCode");
jsonObject.addProperty("typeCode", getTypeCode());
}
String asyncContent = jsonObject.toString();
setCallBacks(null, null, null, true, Constants.GET_NOT_SEEN_DURATION, null, uniqueId);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_GET_NOT_SEEN_DURATION");
}
return uniqueId;
}
use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method muteThread.
/**
* It Mutes the thread so notification is set to off for that thread
*/
public String muteThread(long threadId, ChatHandler handler) {
String uniqueId;
uniqueId = generateUniqueId();
JsonObject jsonObject;
try {
if (chatReady) {
// long threadId = request.getThreadId();
// String typeCode = request.getTypeCode();
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(Constants.MUTE_THREAD);
chatMessage.setToken(getToken());
chatMessage.setTokenIssuer("1");
chatMessage.setSubjectId(threadId);
chatMessage.setUniqueId(uniqueId);
jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
jsonObject.remove("contentCount");
jsonObject.remove("systemMetadata");
jsonObject.remove("metadata");
jsonObject.remove("repliedTo");
if (Util.isNullOrEmpty(typeCode)) {
if (Util.isNullOrEmpty(getTypeCode())) {
jsonObject.remove("typeCode");
} else {
jsonObject.addProperty("typeCode", getTypeCode());
}
} else {
jsonObject.addProperty("typeCode", typeCode);
}
setCallBacks(null, null, null, true, Constants.MUTE_THREAD, null, uniqueId);
sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_MUTE_THREAD");
if (handler != null) {
handler.onMuteThread(uniqueId);
}
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
return uniqueId;
}
use of com.fanap.podchat.mainmodel.ChatMessage 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.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method sendTextMessageWithFile.
private void sendTextMessageWithFile(String description, long threadId, String metaData, String systemMetadata, String uniqueId, String typeCode, Integer messageType) {
/* Add to sending Queue*/
SendingQueueCache sendingQueue = new SendingQueueCache();
if (systemMetadata != null)
sendingQueue.setSystemMetadata(systemMetadata);
else
sendingQueue.setSystemMetadata("");
if (messageType != null)
sendingQueue.setMessageType(messageType);
else
sendingQueue.setMessageType(0);
sendingQueue.setThreadId(threadId);
sendingQueue.setUniqueId(uniqueId);
sendingQueue.setMessage(description);
sendingQueue.setMetadata(metaData);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setContent(description);
chatMessage.setType(Constants.MESSAGE);
chatMessage.setTokenIssuer("1");
chatMessage.setToken(getToken());
chatMessage.setMetadata(metaData);
chatMessage.setSystemMetadata(systemMetadata);
chatMessage.setMessageType(messageType);
chatMessage.setUniqueId(uniqueId);
chatMessage.setSubjectId(threadId);
chatMessage.setTypeCode(typeCode != null ? typeCode : getTypeCode());
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
if (Util.isNullOrEmpty(systemMetadata)) {
jsonObject.remove("systemMetadata");
}
if (chatMessage.getRepliedTo() == 0)
jsonObject.remove("repliedTo");
if (chatMessage.getTime() == 0)
jsonObject.remove("time");
jsonObject.remove("contentCount");
String asyncContent = jsonObject.toString();
sendingQueue.setAsyncContent(asyncContent);
insertToSendQueue(uniqueId, sendingQueue);
if (chatReady) {
setThreadCallbacks(threadId, uniqueId);
moveFromSendingQueueToWaitQueue(uniqueId, sendingQueue);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_TXT_MSG_WITH_FILE");
stopTyping();
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
}
Aggregations