use of com.fanap.podchat.model.ResultUserInfo in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getUserInfo.
/**
* It Gets the information of the current user
*/
public String getUserInfo(ChatHandler handler) {
String uniqueId = generateUniqueId();
Runnable cacheLoading = () -> {
if (permit && cache && handler != null) {
try {
UserInfo userInfo = messageDatabaseHelper.getUserInfo();
if (userInfo != null) {
ChatResponse<ResultUserInfo> chatResponse = new ChatResponse<>();
ResultUserInfo result = new ResultUserInfo();
setUserId(userInfo.getId());
result.setUser(userInfo);
chatResponse.setResult(result);
chatResponse.setCache(true);
chatResponse.setUniqueId(uniqueId);
String userInfoJson = gson.toJson(chatResponse);
listenerManager.callOnUserInfo(userInfoJson, chatResponse);
showLog("CACHE_USER_INFO", userInfoJson);
}
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
}
};
Runnable requestServer = () -> {
if (asyncReady) {
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(Constants.USER_INFO);
chatMessage.setUniqueId(uniqueId);
chatMessage.setToken(getToken());
chatMessage.setTokenIssuer("1");
setCallBacks(null, null, null, true, Constants.USER_INFO, null, uniqueId);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
if (Util.isNullOrEmpty(getTypeCode())) {
jsonObject.remove("typeCode");
} else {
jsonObject.remove("typeCode");
jsonObject.addProperty("typeCode", getTypeCode());
}
String asyncContent = jsonObject.toString();
showLog("SEND_USER_INFO", asyncContent);
async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
if (handler != null) {
handler.onGetUserInfo(uniqueId);
}
}
};
new PodThreadManager().addNewTask(cacheLoading).addNewTask(requestServer).runTasksSynced();
return uniqueId;
}
use of com.fanap.podchat.model.ResultUserInfo in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleOnGetUserInfo.
/**
* Its check the Failed Queue {@link #checkMessageQueue()} to send all the message that is waiting to be send.
*/
private void handleOnGetUserInfo(ChatMessage chatMessage, String messageUniqueId, Callback callback) {
if (callback.isResult()) {
// if there is a key its ok if not it will go for the key and then chat ready
ChatResponse<ResultUserInfo> chatResponse = new ChatResponse<>();
UserInfo userInfo = gson.fromJson(chatMessage.getContent(), UserInfo.class);
setUserId(userInfo.getId());
setChatReady("CHAT_READY", true);
userInfoResponse = true;
// add user info for sentry
setSentryUser(userInfo);
String userInfoJson = reformatUserInfo(chatMessage, chatResponse, userInfo);
if (sentryResponseLog) {
showLog("RECEIVE_USER_INFO", userInfoJson);
} else {
showLog("RECEIVE_USER_INFO");
}
pingWithDelay();
messageCallbacks.remove(messageUniqueId);
listenerManager.callOnUserInfo(userInfoJson, chatResponse);
}
}
use of com.fanap.podchat.model.ResultUserInfo in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method reformatUserInfo.
private String reformatUserInfo(ChatMessage chatMessage, ChatResponse<ResultUserInfo> outPutUserInfo, UserInfo userInfo) {
ResultUserInfo result = new ResultUserInfo();
if (cache && permit) {
messageDatabaseHelper.saveUserInfo(userInfo);
// messageDatabaseHelper.saveUserInfo(userInfo, handleDBError(() -> {
//
// messageDatabaseHelper.saveUserInfo(userInfo);
// }, () -> {
// }));
}
setUserId(userInfo.getId());
result.setUser(userInfo);
outPutUserInfo.setErrorCode(0);
outPutUserInfo.setErrorMessage("");
outPutUserInfo.setHasError(false);
outPutUserInfo.setResult(result);
outPutUserInfo.setUniqueId(chatMessage.getUniqueId());
return gson.toJson(outPutUserInfo);
}
use of com.fanap.podchat.model.ResultUserInfo in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getUserInfo.
/**
* It Gets the information of the current user
* <p>
* set useCache = false to disable cache for only this function
*/
public String getUserInfo(boolean useCache, ChatHandler handler) {
String uniqueId = generateUniqueId();
Runnable cacheLoading = () -> {
if (cache && useCache) {
try {
UserInfo userInfo = messageDatabaseHelper.getUserInfo();
if (userInfo != null) {
ChatResponse<ResultUserInfo> chatResponse = new ChatResponse<>();
ResultUserInfo result = new ResultUserInfo();
setUserId(userInfo.getId());
result.setUser(userInfo);
chatResponse.setResult(result);
chatResponse.setCache(true);
chatResponse.setUniqueId(uniqueId);
String userInfoJson = gson.toJson(chatResponse);
listenerManager.callOnUserInfo(userInfoJson, chatResponse);
showLog("CACHE_USER_INFO", userInfoJson);
}
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
}
};
Runnable requestServer = () -> {
if (chatReady) {
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(Constants.USER_INFO);
chatMessage.setUniqueId(uniqueId);
chatMessage.setToken(getToken());
chatMessage.setTokenIssuer("1");
setCallBacks(null, null, null, true, Constants.USER_INFO, null, uniqueId);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
if (Util.isNullOrEmpty(getTypeCode())) {
jsonObject.remove("typeCode");
} else {
jsonObject.remove("typeCode");
jsonObject.addProperty("typeCode", getTypeCode());
}
String asyncContent = jsonObject.toString();
showLog("SEND_USER_INFO", asyncContent);
async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
if (handler != null) {
handler.onGetUserInfo(uniqueId);
}
} else
onChatNotReady(uniqueId);
};
new PodThreadManager().addNewTask(cacheLoading).addNewTask(requestServer).runTasksSynced();
return uniqueId;
}
Aggregations