use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method seenMessageList.
// Get the list of the participants that saw the specific message
/*
* The replacement method is getMessageSeenList.
* */
private String seenMessageList(RequestSeenMessageList requestParams) {
String uniqueId;
uniqueId = generateUniqueId();
if (chatReady) {
try {
if (Util.isNullOrEmpty(requestParams.getCount())) {
requestParams.setCount(50);
}
JsonObject object = (JsonObject) gson.toJsonTree(requestParams);
object.remove("typeCode");
ChatMessage chatMessage = new ChatMessage(uniqueId, Constants.SEEN_MESSAGE_LIST, object.toString(), getToken());
String asyncContent = chatMessage.getJson(requestParams.getTypeCode(), getTypeCode()).toString();
setCallBacks(null, null, null, true, Constants.SEEN_MESSAGE_LIST, requestParams.getOffset(), uniqueId);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_SEEN_MESSAGE_LIST");
} catch (Throwable e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
return uniqueId;
}
use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method mainReplyMessage.
private String mainReplyMessage(String messageContent, long threadId, long messageId, String systemMetaData, Integer messageType, String metaData, String iUniqueId, ChatHandler handler) {
String uniqueId = iUniqueId;
if (iUniqueId == null)
uniqueId = generateUniqueId();
/* Add to sending Queue*/
SendingQueueCache sendingQueue = new SendingQueueCache();
sendingQueue.setSystemMetadata(systemMetaData);
sendingQueue.setMessageType(messageType);
sendingQueue.setThreadId(threadId);
sendingQueue.setUniqueId(uniqueId);
sendingQueue.setMessage(messageContent);
sendingQueue.setMetadata(metaData);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setUniqueId(uniqueId);
chatMessage.setRepliedTo(messageId);
chatMessage.setSubjectId(threadId);
chatMessage.setTokenIssuer("1");
chatMessage.setToken(getToken());
chatMessage.setContent(messageContent);
chatMessage.setMetadata(metaData);
chatMessage.setSystemMetadata(systemMetaData);
chatMessage.setType(Constants.MESSAGE);
chatMessage.setTypeCode(getTypeCode());
chatMessage.setMessageType(messageType);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
if (Util.isNullOrEmpty(systemMetaData)) {
jsonObject.remove("systemMetaData");
}
if (Util.isNullOrEmpty(metaData)) {
jsonObject.remove("metadata");
}
jsonObject.remove("time");
String asyncContent = jsonObject.toString();
sendingQueue.setAsyncContent(asyncContent);
insertToSendQueue(uniqueId, sendingQueue);
if (log)
Log.i(TAG, "Message with this" + "uniqueId" + uniqueId + "has been added to Message Queue");
if (chatReady) {
moveFromSendingQueueToWaitQueue(uniqueId, sendingQueue);
setThreadCallbacks(threadId, uniqueId);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_REPLY_MESSAGE");
stopTyping();
if (handler != null) {
handler.onReplyMessage(uniqueId);
}
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
return uniqueId;
}
use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method createThreadWithMessage.
/**
* Create the thread with message is just for p to p.( Thread Type is int NORMAL = 0)
*
* @return The first UniqueId is for create thread and the rest of them are for new message or forward messages
* Its have three kind of Unique Ids. One of them is for message. One of them for Create Thread
* and the others for Forward Message or Messages.
* <p>
* int messageType Type of the Thread (You can have Thread Type from ThreadType.class)
* String ownerSsoId [Optional]
* List<Invitee> invitees you can add your invite list here
* String title [Optional] title of the group thread
* <p>
* RequestThreadInnerMessage message{ object of the inner message
* <p>
* ------------- String text text of the message
* ------------- int messageType messageType of the message [Optional]
* ------------- String metadata [Optional]
* ------------- String systemMetadata [Optional]
* ------------- List<Long> forwardedMessageIds [Optional]
* }
*/
public ArrayList<String> createThreadWithMessage(RequestCreateThread threadRequest) {
List<String> forwardUniqueIds;
JsonObject innerMessageObj;
JsonObject jsonObject;
String threadUniqueId = generateUniqueId();
ArrayList<String> uniqueIds = new ArrayList<>();
uniqueIds.add(threadUniqueId);
try {
if (chatReady) {
RequestThreadInnerMessage innerMessage = threadRequest.getMessage();
innerMessageObj = (JsonObject) gson.toJsonTree(innerMessage);
if (Util.isNullOrEmpty(threadRequest.getMessage().getType())) {
innerMessageObj.remove("type");
}
if (Util.isNullOrEmpty(threadRequest.getMessage().getText())) {
innerMessageObj.remove("message");
} else {
String newMsgUniqueId = generateUniqueId();
innerMessageObj.addProperty("uniqueId", newMsgUniqueId);
uniqueIds.add(newMsgUniqueId);
setCallBacks(true, true, true, true, Constants.MESSAGE, null, newMsgUniqueId);
}
if (!Util.isNullOrEmptyNumber(threadRequest.getMessage().getForwardedMessageIds())) {
/**
* Its generated new unique id for each forward message
*/
List<Long> messageIds = threadRequest.getMessage().getForwardedMessageIds();
forwardUniqueIds = new ArrayList<>();
for (long ids : messageIds) {
String frwMsgUniqueId = generateUniqueId();
forwardUniqueIds.add(frwMsgUniqueId);
uniqueIds.add(frwMsgUniqueId);
setCallBacks(true, true, true, true, Constants.MESSAGE, null, frwMsgUniqueId);
}
JsonElement element = gson.toJsonTree(forwardUniqueIds, new TypeToken<List<Long>>() {
}.getType());
JsonArray jsonArray = element.getAsJsonArray();
innerMessageObj.add("forwardedUniqueIds", jsonArray);
} else {
innerMessageObj.remove("forwardedUniqueIds");
innerMessageObj.remove("forwardedMessageIds");
}
JsonObject jsonObjectCreateThread = (JsonObject) gson.toJsonTree(threadRequest);
jsonObjectCreateThread.remove("count");
jsonObjectCreateThread.remove("offset");
jsonObjectCreateThread.add("message", innerMessageObj);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setContent(jsonObjectCreateThread.toString());
chatMessage.setType(Constants.INVITATION);
chatMessage.setUniqueId(threadUniqueId);
chatMessage.setToken(getToken());
chatMessage.setTokenIssuer("1");
jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
jsonObject.remove("repliedTo");
jsonObject.remove("subjectId");
jsonObject.remove("systemMetadata");
jsonObject.remove("contentCount");
String typeCode = threadRequest.getTypeCode();
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.INVITATION, null, threadUniqueId);
if (threadRequest.getUploadThreadImageRequest() != null) {
handlerSend.put(threadUniqueId, new ChatHandler() {
@Override
public void onThreadCreated(ResultThread thread) {
super.onThreadCreated(thread);
updateThreadImage(thread, threadRequest.getUploadThreadImageRequest());
}
});
}
sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_CREATE_THREAD_WITH_MESSAGE");
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, threadUniqueId);
}
} catch (Throwable e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueIds.get(0), e);
}
return uniqueIds;
}
use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method seenMessage.
/**
* In order to send seen message you have to call this method
*/
public String seenMessage(long messageId, long ownerId, ChatHandler handler) {
String uniqueId;
uniqueId = generateUniqueId();
if (chatReady) {
if (ownerId != getUserId()) {
ChatMessage message = new ChatMessage();
message.setType(Constants.SEEN);
message.setContent(String.valueOf(messageId));
message.setTokenIssuer("1");
message.setToken(getToken());
message.setUniqueId(uniqueId);
message.setTime(1000);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(message);
if (Util.isNullOrEmpty(getTypeCode())) {
jsonObject.remove("typeCode");
} else {
jsonObject.remove("typeCode");
jsonObject.addProperty("typeCode", getTypeCode());
}
jsonObject.remove("contentCount");
jsonObject.remove("systemMetadata");
jsonObject.remove("metadata");
jsonObject.remove("repliedTo");
String asyncContent = jsonObject.toString();
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_SEEN_MESSAGE");
if (handler != null) {
handler.onSeen(uniqueId);
}
}
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
return uniqueId;
}
use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getAllThreads.
private void getAllThreads() {
if (cache) {
String uniqueId = generateUniqueId();
JsonObject content = new JsonObject();
content.addProperty("summary", true);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setContent(content.toString());
chatMessage.setToken(getToken());
chatMessage.setType(Constants.GET_THREADS);
chatMessage.setTypeCode(getTypeCode());
chatMessage.setUniqueId(uniqueId);
ChatHandler handler = new ChatHandler() {
@Override
public void onGetThread(String data) {
super.onGetThread(data);
ArrayList<ResultThreadsSummary> result = gson.fromJson(data, new TypeToken<ArrayList<ResultThreadsSummary>>() {
}.getType());
ArrayList<Long> serverResultThreadIds = new ArrayList<>();
for (ResultThreadsSummary rts : result) {
serverResultThreadIds.add((long) rts.getId());
}
messageDatabaseHelper.getThreadIdsList(t -> {
try {
if (t == null)
return;
List<Long> threadsIdsInCache = (List<Long>) t;
if (threadsIdsInCache.size() > 0) {
threadsIdsInCache.removeAll(serverResultThreadIds);
if (serverResultThreadIds.size() > 0) {
messageDatabaseHelper.deleteThreads(new ArrayList<>(threadsIdsInCache));
showLog("THREADS CACHE UPDATED", "");
}
}
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
});
}
};
// callback
handlerSend.put(uniqueId, handler);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
jsonObject.remove("contentCount");
jsonObject.remove("repliedTo");
jsonObject.remove("subjectId");
jsonObject.remove("time");
sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "UPDATING_THREADS_CACHE");
}
}
Aggregations