use of com.fanap.podchat.persistance.RoomIntegrityException 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();
}
}
use of com.fanap.podchat.persistance.RoomIntegrityException in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method loadParticipantsFromCache.
@SuppressWarnings("unchecked")
private void loadParticipantsFromCache(String uniqueId, int count, int offset, long threadId) {
try {
messageDatabaseHelper.getThreadParticipant(offset, count, threadId, (obj, listData) -> {
if (listData != null) {
List<Participant> participantsList = (List<Participant>) listData;
long participantCount = (long) obj;
ChatResponse<ResultParticipant> chatResponse = new ChatResponse<>();
ResultParticipant resultParticipant = new ResultParticipant();
resultParticipant.setContentCount(participantsList.size());
resultParticipant.setHasNext(participantsList.size() + offset < participantCount);
resultParticipant.setParticipants(participantsList);
chatResponse.setResult(resultParticipant);
chatResponse.setCache(true);
chatResponse.setUniqueId(uniqueId);
resultParticipant.setNextOffset(offset + participantsList.size());
String jsonParticipant = gson.toJson(chatResponse);
listenerManager.callOnGetThreadParticipant(jsonParticipant, chatResponse);
showLog("PARTICIPANT FROM CACHE", jsonParticipant);
}
});
} catch (RoomIntegrityException e) {
disableCache();
}
}
use of com.fanap.podchat.persistance.RoomIntegrityException in project pod-chat-android-sdk by FanapSoft.
the class ExampleUnitTest method runCompleteAfterError.
@Test
public void runCompleteAfterError() {
Observable<String> a = Observable.create(subscriber -> {
System.out.println("1");
try {
Thread.sleep(3000);
subscriber.onError(new RoomIntegrityException());
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("2");
subscriber.onNext("Hello");
});
a.subscribeOn(Schedulers.immediate()).onErrorResumeNext(tt -> {
System.out.println("onError res: " + tt);
return Observable.empty();
}).observeOn(Schedulers.immediate()).doOnCompleted(() -> System.out.println("Comp")).subscribe(System.out::println);
}
use of com.fanap.podchat.persistance.RoomIntegrityException in project pod-chat-android-sdk by FanapSoft.
the class CacheDataSource method getWaitQueueUniqueIdList.
public Observable<List<String>> getWaitQueueUniqueIdList() {
return Observable.create(emitter -> {
try {
databaseHelper.getWaitQueueUniqueIdList(o -> {
try {
if (o != null) {
List<String> data = (List<String>) o;
emitter.onNext(data);
} else {
emitter.onError(new PodChatException("No uniqueId found", ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION));
}
} catch (Exception e) {
emitter.onError(e);
}
});
} catch (RoomIntegrityException e) {
emitter.onError(e);
}
});
}
use of com.fanap.podchat.persistance.RoomIntegrityException in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getContactMain.
private String getContactMain(int count, long offset, String username, boolean syncContact, String typeCode, boolean useCache, ChatHandler handler) {
String uniqueId = generateUniqueId();
int mCount = count > 0 ? count : 50;
Runnable serverRequestTask = () -> {
if (chatReady) {
ChatMessageContent chatMessageContent = new ChatMessageContent();
chatMessageContent.setOffset(offset);
JsonObject jObj = (JsonObject) gson.toJsonTree(chatMessageContent);
jObj.remove("lastMessageId");
jObj.remove("firstMessageId");
jObj.remove("count");
jObj.addProperty("size", mCount);
if (username != null)
jObj.addProperty("username", username);
AsyncMessage chatMessage = new AsyncMessage();
chatMessage.setContent(jObj.toString());
chatMessage.setType(Constants.GET_CONTACTS);
chatMessage.setToken(getToken());
chatMessage.setUniqueId(uniqueId);
chatMessage.setTypeCode(Util.isNotNullOrEmpty(typeCode) ? typeCode : getTypeCode());
chatMessage.setTokenIssuer("1");
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
String asyncContent = jsonObject.toString();
setCallBacks(null, null, null, !syncContact, Constants.GET_CONTACTS, offset, uniqueId);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "GET_CONTACT_SEND");
if (handler != null) {
handler.onGetContact(uniqueId);
}
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
};
if (cache && useCache) {
dataSource.getContactData(count, offset, username).doOnCompleted(serverRequestTask::run).doOnError(exception -> {
if (exception instanceof RoomIntegrityException) {
disableCache();
} else {
captureError(exception.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, uniqueId);
}
}).onErrorResumeNext(Observable.empty()).subscribe(response -> {
if (response != null && Util.isNotNullOrEmpty(response.getContactsList())) {
showLog("SOURCE: " + response.getSource());
publishContactResult(uniqueId, offset, new ArrayList<>(response.getContactsList()), (int) response.getContentCount());
}
});
} else {
serverRequestTask.run();
}
return uniqueId;
}
Aggregations