use of com.fanap.podchat.util.PodThreadManager 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.util.PodThreadManager in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method createThreadWithFile.
//
// 1. Create thread.
// 2.1. Upload thread image and update thread info if RequestUploadImage is set.
// 2.2. Upload file to server with thread userGroupHash and send uploaded file as message by sendFileMessage.
//
public ArrayList<String> createThreadWithFile(RequestCreateThreadWithFile request, @Nullable ProgressHandler.sendFileMessage progressHandler) {
ArrayList<String> uniqueIds = new ArrayList<>();
String requestUniqueId = generateUniqueId();
uniqueIds.add(requestUniqueId);
if (needReadStoragePermission(request.getFile().getActivity()))
return uniqueIds;
if (chatReady) {
handlerSend.put(requestUniqueId, new ChatHandler() {
@Override
public void onThreadCreated(ResultThread thread) {
super.onThreadCreated(thread);
if (request.getUploadThreadImageRequest() != null)
new PodThreadManager().doThisAndGo(() -> updateThreadImage(thread, request.getUploadThreadImageRequest()));
RequestFileMessage.Builder requestFileBuilder = new RequestFileMessage.Builder(request.getMessage() != null ? request.getMessage().getText() : null, request.getFile().getActivity(), thread.getThread().getId(), request.getFile().getFileUri(), request.getMessage() != null ? request.getMessage().getSystemMetadata() : null, request.getMessageType(), thread.getThread().getUserGroupHash());
if (request.getFile() instanceof RequestUploadImage) {
requestFileBuilder.setImageHc(String.valueOf(((RequestUploadImage) request.getFile()).gethC()));
requestFileBuilder.setImageWc(String.valueOf(((RequestUploadImage) request.getFile()).getwC()));
requestFileBuilder.setImageXc(String.valueOf(((RequestUploadImage) request.getFile()).getxC()));
requestFileBuilder.setImageYc(String.valueOf(((RequestUploadImage) request.getFile()).getyC()));
}
RequestFileMessage requestFile = requestFileBuilder.build();
sendFileMessage(requestFile, requestUniqueId, progressHandler);
}
});
RequestCreateThread requestCreateThread = new RequestCreateThread.Builder(request.getType(), request.getInvitees()).title(request.getTitle()).withDescription(request.getDescription()).withImage(request.getImage()).withMetadata(request.getMessage() != null ? request.getMessage().getSystemMetadata() : null).build();
createThread(requestCreateThread, requestUniqueId);
// prepareCreateThreadWithFile(request, requestUniqueId, innerMessageUniqueId, forwardUniqueIds, "");
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, requestUniqueId);
}
return uniqueIds;
}
use of com.fanap.podchat.util.PodThreadManager 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