use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleClearHistory.
private void handleClearHistory(ChatMessage chatMessage) {
ChatResponse<ResultClearHistory> chatResponseClrHistory = new ChatResponse<>();
ResultClearHistory resultClearHistory = new ResultClearHistory();
long clrHistoryThreadId = gson.fromJson(chatMessage.getContent(), Long.class);
resultClearHistory.setThreadId(clrHistoryThreadId);
chatResponseClrHistory.setResult(resultClearHistory);
chatResponseClrHistory.setUniqueId(chatMessage.getUniqueId());
chatResponseClrHistory.setSubjectId(chatMessage.getSubjectId());
String jsonClrHistory = gson.toJson(chatResponseClrHistory);
if (sentryResponseLog) {
showLog("RECEIVE_CLEAR_HISTORY", jsonClrHistory);
} else {
showLog("RECEIVE_CLEAR_HISTORY");
}
if (cache) {
messageDatabaseHelper.deleteMessagesOfThread(chatMessage.getSubjectId());
}
listenerManager.callOnClearHistory(jsonClrHistory, chatResponseClrHistory);
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method addContact.
/**
* Add one contact to the contact list
* <p>
* firstName and cellphoneNumber or email or username are required
*
* @param username username of contact
* @param firstName Notice: if just put fistName without lastName its ok.
* @param lastName last name of the contact
* @param cellphoneNumber Notice: If you just put the cellPhoneNumber doesn't necessary to add email
* @param email email of the contact
*/
@Deprecated
public String addContact(String firstName, String lastName, String cellphoneNumber, String email, String typeCode, String username) {
if (Util.isNullOrEmpty(firstName)) {
firstName = "";
}
if (Util.isNullOrEmpty(lastName)) {
lastName = "";
}
if (Util.isNullOrEmpty(email)) {
email = "";
}
if (Util.isNullOrEmpty(cellphoneNumber)) {
cellphoneNumber = "";
}
if (Util.isNullOrEmpty(username)) {
username = "";
}
String uniqueId = generateUniqueId();
typeCode = Util.isNullOrEmpty(typeCode) ? getTypeCode() : typeCode;
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("uniqueId", uniqueId);
jsonObject.addProperty("tokenIssuer", 1);
jsonObject.addProperty("firstName", firstName);
jsonObject.addProperty("lastName", lastName);
if (!Util.isNullOrEmpty(cellphoneNumber))
jsonObject.addProperty("cellphoneNumber", cellphoneNumber);
if (!Util.isNullOrEmpty(email))
jsonObject.addProperty("email", email);
if (!Util.isNullOrEmpty(typeCode))
jsonObject.addProperty("typeCode", typeCode);
if (!Util.isNullOrEmpty(username))
jsonObject.addProperty("username", username);
showLog("SEND_ADD_CONTACT", getJsonForLog(jsonObject));
Observable<Response<Contacts>> addContactObservable;
if (chatReady) {
if (!Util.isNullOrEmpty(username)) {
addContactObservable = contactApi.addContactWithUserName(getToken(), 1, firstName, lastName, username, uniqueId, typeCode, "", "");
} else if (Util.isNullOrEmpty(typeCode)) {
addContactObservable = contactApi.addContact(getToken(), 1, firstName, lastName, email, uniqueId, cellphoneNumber);
} else {
addContactObservable = contactApi.addContact(getToken(), 1, firstName, lastName, email, uniqueId, cellphoneNumber, typeCode);
}
addContactObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(addContactResponse -> {
if (addContactResponse.isSuccessful()) {
Contacts contacts = addContactResponse.body();
if (contacts != null) {
if (!contacts.getHasError()) {
ChatResponse<ResultAddContact> chatResponse = Util.getReformatOutPutAddContact(contacts, uniqueId);
String contactsJson = gson.toJson(chatResponse);
listenerManager.callOnAddContact(contactsJson, chatResponse);
showLog("RECEIVED_ADD_CONTACT", contactsJson);
if (cache) {
// messageDatabaseHelper.saveContact(chatResponse.getResult().getContact(), getExpireAmount());
dataSource.saveContactResultFromServer(chatResponse.getResult().getContact());
}
} else {
captureError(contacts.getMessage(), contacts.getErrorCode(), uniqueId);
}
}
}
}, (Throwable throwable) -> {
captureError(throwable.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, uniqueId, throwable);
Log.e(TAG, throwable.getMessage());
});
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
return uniqueId;
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleSeen.
private void handleSeen(ChatMessage chatMessage, String messageUniqueId, long threadId) {
if (threadCallbacks.containsKey(threadId)) {
ArrayList<Callback> callbacks = threadCallbacks.get(threadId);
if (callbacks != null) {
for (Callback callback : callbacks) {
if (messageUniqueId.equals(callback.getUniqueId())) {
int indexUnique = callbacks.indexOf(callback);
while (indexUnique > -1) {
if (callbacks.get(indexUnique).isSeen()) {
ResultMessage resultMessage = gson.fromJson(chatMessage.getContent(), ResultMessage.class);
if (callbacks.get(indexUnique).isDelivery()) {
ChatResponse<ResultMessage> chatResponse = new ChatResponse<>();
chatResponse.setErrorMessage("");
chatResponse.setErrorCode(0);
chatResponse.setHasError(false);
chatResponse.setUniqueId(callback.getUniqueId());
chatResponse.setResult(resultMessage);
String json = gson.toJson(chatResponse);
listenerManager.callOnDeliveryMessage(json, chatResponse);
Callback callbackUpdateSent = new Callback();
callbackUpdateSent.setSent(callback.isSent());
callbackUpdateSent.setDelivery(false);
callbackUpdateSent.setSeen(callback.isSeen());
callbackUpdateSent.setUniqueId(callback.getUniqueId());
callbacks.set(indexUnique, callbackUpdateSent);
threadCallbacks.put(threadId, callbacks);
if (sentryResponseLog) {
showLog("RECEIVED_DELIVERED_MESSAGE", json);
} else {
showLog("RECEIVED_DELIVERED_MESSAGE");
}
}
ChatResponse<ResultMessage> chatResponse = new ChatResponse<>();
chatResponse.setErrorMessage("");
chatResponse.setErrorCode(0);
chatResponse.setHasError(false);
chatResponse.setUniqueId(callback.getUniqueId());
chatResponse.setResult(resultMessage);
String json = gson.toJson(chatResponse);
listenerManager.callOnSeenMessage(json, chatResponse);
callbacks.remove(indexUnique);
threadCallbacks.put(threadId, callbacks);
if (sentryResponseLog) {
showLog("RECEIVED_SEEN_MESSAGE", json);
} else {
showLog("RECEIVED_SEEN_MESSAGE");
}
}
indexUnique--;
}
break;
}
}
}
}
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method publishMutualThreadsList.
private String publishMutualThreadsList(String uniqueId, Long finalOffset, ThreadManager.ThreadResponse cacheThreadResponse) {
ChatResponse<ResultThreads> chatResponse = new ChatResponse<>();
List<Thread> threadList = cacheThreadResponse.getThreadList();
chatResponse.setCache(true);
long contentCount = cacheThreadResponse.getContentCount();
ResultThreads resultThreads = new ResultThreads();
resultThreads.setThreads(threadList);
resultThreads.setContentCount(contentCount);
chatResponse.setCache(true);
if (threadList.size() + finalOffset < contentCount) {
resultThreads.setHasNext(true);
} else {
resultThreads.setHasNext(false);
}
resultThreads.setNextOffset(finalOffset + threadList.size());
chatResponse.setResult(resultThreads);
chatResponse.setUniqueId(uniqueId);
String result = gson.toJson(chatResponse);
listenerManager.callOnGetMutualGroup(result, chatResponse);
return result;
}
use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method loadAdminsFromCache.
private void loadAdminsFromCache(String uniqueId, int count, int offset, long threadId) {
try {
messageDatabaseHelper.getThreadAdmins(offset, count, threadId, (obj, listData) -> {
List<Participant> participants = (List<Participant>) listData;
long participantCount = (long) obj;
if (participants != null) {
ChatResponse<ResultParticipant> chatResponse = new ChatResponse<>();
ResultParticipant resultParticipant = new ResultParticipant();
resultParticipant.setThreadId(threadId);
resultParticipant.setContentCount(participants.size());
resultParticipant.setHasNext(participants.size() + offset < participantCount);
resultParticipant.setParticipants(participants);
chatResponse.setResult(resultParticipant);
chatResponse.setCache(true);
chatResponse.setUniqueId(uniqueId);
chatResponse.setSubjectId(threadId);
resultParticipant.setNextOffset(offset + participants.size());
String jsonParticipant = gson.toJson(chatResponse);
OutPutParticipant outPutParticipant = new OutPutParticipant();
outPutParticipant.setResult(resultParticipant);
listenerManager.callOnGetThreadAdmin(jsonParticipant, chatResponse);
showLog("RECEIVE ADMINS FROM CACHE", jsonParticipant);
}
});
} catch (RoomIntegrityException e) {
disableCache();
}
}
Aggregations