use of com.fanap.podchat.mainmodel.RequestThreadInnerMessage 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.RequestThreadInnerMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method prepareCreateThreadWithFile.
private void prepareCreateThreadWithFile(RequestCreateThreadWithFile request, String requestUniqueId, String innerMessageUniqueId, List<String> forwardUniqueIds, String metaData) {
RequestThreadInnerMessage requestThreadInnerMessage = generateInnerMessageForCreateThreadWithFile(request, metaData);
request.setMessage(requestThreadInnerMessage);
request.setMessageType(request.getMessageType());
request.setFile(null);
// createThreadWithMessage(request, requestUniqueId, innerMessageUniqueId, forwardUniqueIds);
}
use of com.fanap.podchat.mainmodel.RequestThreadInnerMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method generateInnerMessageForCreateThreadWithFile.
private RequestThreadInnerMessage generateInnerMessageForCreateThreadWithFile(RequestCreateThreadWithFile request, String metaData) {
RequestThreadInnerMessage requestThreadInnerMessage;
if (request.getMessage() == null) {
requestThreadInnerMessage = new RequestThreadInnerMessage.Builder(request.getType()).metadata(metaData).type(request.getMessageType()).build();
} else {
requestThreadInnerMessage = request.getMessage();
requestThreadInnerMessage.setMetadata(metaData);
requestThreadInnerMessage.setType(request.getMessageType());
}
return requestThreadInnerMessage;
}
use of com.fanap.podchat.mainmodel.RequestThreadInnerMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatActivity method createThreadWithMessage.
private void createThreadWithMessage() {
List<Invitee> invite = new ArrayList<>();
invite.add(new Invitee(1151568, InviteType.Constants.TO_BE_USER_CONTACT_ID));
invite.add(new Invitee(1512305, InviteType.Constants.TO_BE_USER_CONTACT_ID));
RequestUploadImage requestUploadThreadImageImage = new RequestUploadImage.Builder(ChatActivity.this, getUri()).setwC(140).sethC(140).build();
RequestThreadInnerMessage message = new RequestThreadInnerMessage.Builder("Hi at " + new Date().toString(), TextMessageType.Constants.TEXT).build();
RequestCreateThread requestCreateThread = new RequestCreateThread.Builder(ThreadType.Constants.OWNER_GROUP, invite).message(message).setUploadThreadImageRequest(requestUploadThreadImageImage).build();
presenter.createThreadWithMessage(requestCreateThread);
}
Aggregations