use of com.fanap.podchat.mainmodel.AsyncMessage 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.AsyncMessage in project pod-chat-android-sdk by FanapSoft.
the class ThreadManager method createMutaulGroupRequest.
public static String createMutaulGroupRequest(GetMutualGroupRequest request, String uniqueId) {
JsonObject content = (JsonObject) App.getGson().toJsonTree(request);
content.remove("useCache");
AsyncMessage message = new ChatMessage();
message.setType(ChatMessageType.Constants.MUTUAL_GROUPS);
message.setToken(CoreConfig.token);
message.setTokenIssuer(CoreConfig.tokenIssuer);
message.setContent(content.toString());
message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
message.setUniqueId(uniqueId);
return App.getGson().toJson(message);
}
use of com.fanap.podchat.mainmodel.AsyncMessage in project pod-chat-android-sdk by FanapSoft.
the class ThreadManager method createCloseThreadRequest.
public static String createCloseThreadRequest(CloseThreadRequest request, String uniqueId) throws PodChatException {
validateThreadId(request, uniqueId);
AsyncMessage message = new ChatMessage();
message.setType(ChatMessageType.Constants.CLOSE_THREAD);
message.setToken(CoreConfig.token);
message.setTokenIssuer(CoreConfig.tokenIssuer);
message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
message.setSubjectId(request.getThreadId());
message.setUniqueId(uniqueId);
return App.getGson().toJson(message);
}
use of com.fanap.podchat.mainmodel.AsyncMessage in project pod-chat-android-sdk by FanapSoft.
the class ThreadManager method prepareCreateThread.
public static String prepareCreateThread(RequestCreateThread request, String uniqueId, String typecode, String token) {
JsonObject chatMessageContent = (JsonObject) App.getGson().toJsonTree(request);
if (request instanceof RequestCreatePublicThread) {
String uniqueName = ((RequestCreatePublicThread) request).getUniqueName();
chatMessageContent.addProperty("uniqueName", uniqueName);
}
AsyncMessage chatMessage = new AsyncMessage();
chatMessage.setContent(chatMessageContent.toString());
chatMessage.setType(ChatMessageType.Constants.INVITATION);
chatMessage.setToken(token);
chatMessage.setUniqueId(uniqueId);
chatMessage.setTokenIssuer("1");
chatMessage.setTypeCode(Util.isNullOrEmpty(request.getTypeCode()) ? typecode : request.getTypeCode());
String asyncContent = App.getGson().toJson(chatMessage);
return asyncContent;
}
use of com.fanap.podchat.mainmodel.AsyncMessage in project pod-chat-android-sdk by FanapSoft.
the class PublicThread method checkIfNameIsAvailable.
public static String checkIfNameIsAvailable(RequestCheckIsNameAvailable request, String uniqueId) {
AsyncMessage message = new AsyncMessage();
message.setContent(request.getUniqueName());
message.setToken(CoreConfig.token);
message.setType(ChatMessageType.Constants.IS_NAME_AVAILABLE);
message.setTokenIssuer(CoreConfig.tokenIssuer);
message.setUniqueId(uniqueId);
message.setTypeCode(!Util.isNullOrEmpty(request.getTypeCode()) ? request.getTypeCode() : CoreConfig.typeCode);
return App.getGson().toJson(message);
}
Aggregations