use of com.fanap.podchat.model.ResultThread 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.model.ResultThread in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleRemoveFromThread.
private void handleRemoveFromThread(ChatMessage chatMessage) {
ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
ResultThread resultThread = new ResultThread();
Thread thread = new Thread();
thread.setId(chatMessage.getSubjectId());
resultThread.setThread(thread);
String content = gson.toJson(chatResponse);
if (cache) {
messageDatabaseHelper.deleteThread(chatMessage.getSubjectId());
}
if (sentryResponseLog) {
showLog("RECEIVED_REMOVED_FROM_THREAD", content);
} else {
showLog("RECEIVED_REMOVED_FROM_THREAD");
}
listenerManager.callOnRemovedFromThread(content, chatResponse);
}
use of com.fanap.podchat.model.ResultThread in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method onThreadLastMessageUpdated.
private void onThreadLastMessageUpdated(Thread thread, String uniqueId) {
ResultThread resultThread = new ResultThread();
resultThread.setThread(thread);
ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
chatResponse.setResult(resultThread);
chatResponse.setUniqueId(uniqueId);
chatResponse.setSubjectId(thread.getId());
if (sentryResponseLog) {
showLog("THREAD_INFO_UPDATED", chatResponse.getJson());
} else {
showLog("THREAD_INFO_UPDATED");
}
if (cache) {
dataSource.saveThreadResultFromCache(thread);
}
listenerManager.callOnThreadInfoUpdated(chatResponse.getJson(), chatResponse);
}
use of com.fanap.podchat.model.ResultThread in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleThreadInfoUpdated.
private void handleThreadInfoUpdated(Thread thread, String uniqueId) {
ResultThread resultThread = new ResultThread();
resultThread.setThread(thread);
ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
chatResponse.setResult(resultThread);
chatResponse.setUniqueId(uniqueId);
listenerManager.callOnThreadInfoUpdated(chatResponse.getJson(), chatResponse);
if (sentryResponseLog) {
showLog("THREAD_INFO_UPDATED", chatResponse.getJson());
} else {
showLog("THREAD_INFO_UPDATED");
}
if (cache) {
// messageDatabaseHelper.saveNewThread(resultThread.getThread());
dataSource.saveThreadResultFromServer(thread);
}
}
use of com.fanap.podchat.model.ResultThread in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleThreadInfoUpdated.
private void handleThreadInfoUpdated(ChatMessage chatMessage) {
ResultThread resultThread = new ResultThread();
Thread thread = gson.fromJson(chatMessage.getContent(), Thread.class);
resultThread.setThread(thread);
ChatResponse<ResultThread> chatResponse = new ChatResponse<>();
chatResponse.setResult(resultThread);
chatResponse.setUniqueId(chatMessage.getUniqueId());
if (sentryResponseLog) {
showLog("THREAD_INFO_UPDATED", chatMessage.getContent());
} else {
showLog("THREAD_INFO_UPDATED");
}
if (cache) {
dataSource.saveThreadResultFromServer(resultThread.getThread());
}
listenerManager.callOnThreadInfoUpdated(chatMessage.getContent(), chatResponse);
}
Aggregations