use of com.fanap.podchat.mainmodel.AsyncMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getThreadParticipantsMain.
private String getThreadParticipantsMain(int count, int offset, long threadId, String typeCode, boolean useCache, ChatHandler handler) {
String uniqueId = generateUniqueId();
final int mCount = count != 0 ? count : 50;
PodThreadManager podThreadManager = new PodThreadManager();
podThreadManager.addTask(() -> {
if (cache && useCache) {
loadParticipantsFromCache(uniqueId, mCount, offset, threadId);
}
});
podThreadManager.addTask(() -> {
if (chatReady) {
JsonObject content = new JsonObject();
content.addProperty("count", mCount);
content.addProperty("offset", offset);
AsyncMessage chatMessage = new AsyncMessage();
chatMessage.setContent(content.toString());
chatMessage.setType(Constants.THREAD_PARTICIPANTS);
chatMessage.setTokenIssuer("1");
chatMessage.setToken(getToken());
chatMessage.setUniqueId(uniqueId);
chatMessage.setSubjectId(threadId);
chatMessage.setTypeCode(Util.isNullOrEmpty(typeCode) ? getTypeCode() : typeCode);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
String asyncContent = jsonObject.toString();
setCallBacks(null, null, null, true, Constants.THREAD_PARTICIPANTS, (long) offset, uniqueId);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_GET_THREAD_PARTICIPANT");
if (handler != null) {
handler.onGetThreadParticipant(uniqueId);
}
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
});
podThreadManager.runTasksSynced();
return uniqueId;
}
use of com.fanap.podchat.mainmodel.AsyncMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method pingAfterSetToken.
private void pingAfterSetToken() {
AsyncMessage chatMessage = new AsyncMessage();
chatMessage.setType(Constants.PING);
chatMessage.setTokenIssuer("1");
chatMessage.setToken(getToken());
checkToken = true;
String asyncContent = gson.toJson(chatMessage);
async.sendMessage(asyncContent, AsyncAckType.Constants.WITH_ACK);
showLog("**SEND_CHAT PING FOR CHECK TOKEN AUTHENTICATION", asyncContent);
}
use of com.fanap.podchat.mainmodel.AsyncMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method ping.
/**
* Ping for staying chat alive
*/
private void ping() {
if (chatReady && async.getPeerId() != null) {
AsyncMessage chatMessage = new AsyncMessage();
chatMessage.setType(Constants.PING);
chatMessage.setTokenIssuer("1");
chatMessage.setToken(getToken());
String asyncContent = gson.toJson(chatMessage);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITH_ACK, "CHAT PING");
}
}
use of com.fanap.podchat.mainmodel.AsyncMessage in project pod-chat-android-sdk by FanapSoft.
the class BotManager method createCreateBotRequest.
public static String createCreateBotRequest(CreateBotRequest request, String uniqueId) throws PodChatException {
validateBotName(request.getBotName());
JsonObject content = new JsonObject();
content.addProperty("botName", request.getBotName());
AsyncMessage message = new AsyncMessage();
message.setContent(request.getBotName());
message.setToken(CoreConfig.token);
message.setType(ChatMessageType.Constants.CREATE_BOT);
message.setTokenIssuer(CoreConfig.tokenIssuer);
message.setUniqueId(uniqueId);
message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
return App.getGson().toJson(message);
}
use of com.fanap.podchat.mainmodel.AsyncMessage in project pod-chat-android-sdk by FanapSoft.
the class BotManager method createStartBotRequest.
public static String createStartBotRequest(StartAndStopBotRequest request, String uniqueId) throws PodChatException {
validateThreadId(request.getThreadId());
validateBotName(request.getBotName());
JsonObject content = new JsonObject();
content.addProperty("botName", request.getBotName());
AsyncMessage message = new AsyncMessage();
message.setContent(content.toString());
message.setToken(CoreConfig.token);
message.setType(ChatMessageType.Constants.START_BOT);
message.setTokenIssuer(CoreConfig.tokenIssuer);
message.setUniqueId(uniqueId);
message.setSubjectId(request.getThreadId());
message.setTypeCode(request.getTypeCode() != null ? request.getTypeCode() : CoreConfig.typeCode);
return App.getGson().toJson(message);
}
Aggregations