use of com.fanap.podchat.mainmodel.ChatMessageContent in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method retrieveThreadInfoFromServer.
private void retrieveThreadInfoFromServer(long threadId, boolean isThreadInfoUpdate) {
if (chatReady) {
String uniqueId = generateUniqueId();
ChatMessageContent chatMessageContent = new ChatMessageContent();
chatMessageContent.setCount(1);
chatMessageContent.setOffset(0);
ArrayList<Integer> threadIds = new ArrayList<>();
threadIds.add((int) threadId);
chatMessageContent.setThreadIds(threadIds);
JsonObject content = (JsonObject) gson.toJsonTree(chatMessageContent);
AsyncMessage asyncMessage = new AsyncMessage();
asyncMessage.setContent(content.toString());
asyncMessage.setType(Constants.GET_THREADS);
asyncMessage.setTokenIssuer("1");
asyncMessage.setToken(getToken());
asyncMessage.setUniqueId(uniqueId);
asyncMessage.setTypeCode(typeCode != null ? typeCode : getTypeCode());
JsonObject jsonObject = (JsonObject) gson.toJsonTree(asyncMessage);
threadInfoCompletor.put(uniqueId, chatMessage -> {
ArrayList<Thread> threads = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Thread>>() {
}.getType());
if (!Util.isNullOrEmpty(threads)) {
if (isThreadInfoUpdate)
onThreadInfoUpdated(threads.get(0), chatMessage.getUniqueId(), true);
else
handleThreadInfoUpdated(threads.get(0), chatMessage.getUniqueId());
threadInfoCompletor.remove(uniqueId);
}
});
sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "SEND_GET_THREAD_INFO");
} else {
showErrorLog("Couldn't complete thread info because chat is not ready");
}
}
use of com.fanap.podchat.mainmodel.ChatMessageContent in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getContactMain.
private String getContactMain(int count, long offset, String username, boolean syncContact, String typeCode, boolean useCache, ChatHandler handler) {
String uniqueId = generateUniqueId();
int mCount = count > 0 ? count : 50;
Runnable serverRequestTask = () -> {
if (chatReady) {
ChatMessageContent chatMessageContent = new ChatMessageContent();
chatMessageContent.setOffset(offset);
JsonObject jObj = (JsonObject) gson.toJsonTree(chatMessageContent);
jObj.remove("lastMessageId");
jObj.remove("firstMessageId");
jObj.remove("count");
jObj.addProperty("size", mCount);
if (username != null)
jObj.addProperty("username", username);
AsyncMessage chatMessage = new AsyncMessage();
chatMessage.setContent(jObj.toString());
chatMessage.setType(Constants.GET_CONTACTS);
chatMessage.setToken(getToken());
chatMessage.setUniqueId(uniqueId);
chatMessage.setTypeCode(Util.isNotNullOrEmpty(typeCode) ? typeCode : getTypeCode());
chatMessage.setTokenIssuer("1");
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
String asyncContent = jsonObject.toString();
setCallBacks(null, null, null, !syncContact, Constants.GET_CONTACTS, offset, uniqueId);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "GET_CONTACT_SEND");
if (handler != null) {
handler.onGetContact(uniqueId);
}
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
};
if (cache && useCache) {
dataSource.getContactData(count, offset, username).doOnCompleted(serverRequestTask::run).doOnError(exception -> {
if (exception instanceof RoomIntegrityException) {
disableCache();
} else {
captureError(exception.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, uniqueId);
}
}).onErrorResumeNext(Observable.empty()).subscribe(response -> {
if (response != null && Util.isNotNullOrEmpty(response.getContactsList())) {
showLog("SOURCE: " + response.getSource());
publishContactResult(uniqueId, offset, new ArrayList<>(response.getContactsList()), (int) response.getContentCount());
}
});
} else {
serverRequestTask.run();
}
return uniqueId;
}
use of com.fanap.podchat.mainmodel.ChatMessageContent in project pod-chat-android-sdk by FanapSoft.
the class ThreadManager method prepareThreadInfoFromServer.
public static String prepareThreadInfoFromServer(long threadId, String uniqueId, String typeCode, String mtypeCode, String token) {
ChatMessageContent chatMessageContent = new ChatMessageContent();
chatMessageContent.setCount(1);
chatMessageContent.setOffset(0);
ArrayList<Integer> threadIds = new ArrayList<>();
threadIds.add((int) threadId);
chatMessageContent.setThreadIds(threadIds);
JsonObject content = (JsonObject) App.getGson().toJsonTree(chatMessageContent);
AsyncMessage asyncMessage = new AsyncMessage();
asyncMessage.setContent(content.toString());
asyncMessage.setType(ChatMessageType.Constants.GET_THREADS);
asyncMessage.setTokenIssuer("1");
asyncMessage.setToken(token);
asyncMessage.setUniqueId(uniqueId);
asyncMessage.setTypeCode(typeCode != null ? typeCode : mtypeCode);
JsonObject jsonObject = (JsonObject) App.getGson().toJsonTree(asyncMessage);
return jsonObject.toString();
}
use of com.fanap.podchat.mainmodel.ChatMessageContent in project pod-chat-android-sdk by FanapSoft.
the class ThreadManager method prepareGetThreadRequest.
public static String prepareGetThreadRequest(boolean isNew, int finalCount, long finalOffset, String threadName, ArrayList<Integer> threadIds, long creatorCoreUserId, long partnerCoreUserId, long partnerCoreContactId, String uniqueId, String typeCode, String mtypeCode, String token) {
ChatMessageContent chatMessageContent = new ChatMessageContent();
chatMessageContent.setNew(isNew);
chatMessageContent.setCount(finalCount);
chatMessageContent.setOffset(finalOffset);
if (threadName != null) {
chatMessageContent.setName(threadName);
}
JsonObject content;
if (!Util.isNullOrEmpty(threadIds)) {
chatMessageContent.setThreadIds(threadIds);
content = (JsonObject) App.getGson().toJsonTree(chatMessageContent);
} else {
content = (JsonObject) App.getGson().toJsonTree(chatMessageContent);
content.remove("threadIds");
}
if (creatorCoreUserId > 0) {
content.addProperty("creatorCoreUserId", creatorCoreUserId);
}
if (partnerCoreUserId > 0) {
content.addProperty("partnerCoreUserId", partnerCoreUserId);
}
if (partnerCoreContactId > 0) {
content.addProperty("partnerCoreContactId", partnerCoreContactId);
}
if (!isNew)
content.remove("new");
content.remove("lastMessageId");
content.remove("firstMessageId");
AsyncMessage chatMessage = new AsyncMessage();
chatMessage.setContent(content.toString());
chatMessage.setType(ChatMessageType.Constants.GET_THREADS);
chatMessage.setTokenIssuer("1");
chatMessage.setToken(token);
chatMessage.setUniqueId(uniqueId);
chatMessage.setTypeCode(typeCode != null ? typeCode : mtypeCode);
JsonObject jsonObject = (JsonObject) App.getGson().toJsonTree(chatMessage);
jsonObject.remove("subjectId");
return jsonObject.toString();
}
Aggregations