Search in sources :

Example 1 with RoomIntegrityException

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();
    }
}
Also used : ResultAddParticipant(com.fanap.podchat.model.ResultAddParticipant) ResultParticipant(com.fanap.podchat.model.ResultParticipant) Participant(com.fanap.podchat.mainmodel.Participant) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) RequestThreadParticipant(com.fanap.podchat.requestobject.RequestThreadParticipant) OutPutParticipant(com.fanap.podchat.model.OutPutParticipant) ResultParticipant(com.fanap.podchat.model.ResultParticipant) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultBlockList(com.fanap.podchat.model.ResultBlockList) RequestGetMentionList(com.fanap.podchat.chat.mention.model.RequestGetMentionList) RequestDeliveredMessageList(com.fanap.podchat.requestobject.RequestDeliveredMessageList) ArrayList(java.util.ArrayList) RequestBlockList(com.fanap.podchat.requestobject.RequestBlockList) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) RequestSeenMessageList(com.fanap.podchat.requestobject.RequestSeenMessageList) List(java.util.List) OutPutParticipant(com.fanap.podchat.model.OutPutParticipant)

Example 2 with RoomIntegrityException

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();
    }
}
Also used : ResultAddParticipant(com.fanap.podchat.model.ResultAddParticipant) ResultParticipant(com.fanap.podchat.model.ResultParticipant) Participant(com.fanap.podchat.mainmodel.Participant) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) RequestThreadParticipant(com.fanap.podchat.requestobject.RequestThreadParticipant) OutPutParticipant(com.fanap.podchat.model.OutPutParticipant) ResultParticipant(com.fanap.podchat.model.ResultParticipant) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultBlockList(com.fanap.podchat.model.ResultBlockList) RequestGetMentionList(com.fanap.podchat.chat.mention.model.RequestGetMentionList) RequestDeliveredMessageList(com.fanap.podchat.requestobject.RequestDeliveredMessageList) ArrayList(java.util.ArrayList) RequestBlockList(com.fanap.podchat.requestobject.RequestBlockList) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) RequestSeenMessageList(com.fanap.podchat.requestobject.RequestSeenMessageList) List(java.util.List)

Example 3 with RoomIntegrityException

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);
}
Also used : RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) Arrays(java.util.Arrays) TypeToken(com.google.gson.reflect.TypeToken) Date(java.util.Date) GsonBuilder(com.google.gson.GsonBuilder) PodThreadManager(com.fanap.podchat.util.PodThreadManager) Future(java.util.concurrent.Future) Gson(com.google.gson.Gson) Locale(java.util.Locale) App(com.fanap.podchat.chat.App) Invitee(com.fanap.podchat.mainmodel.Invitee) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) InviteType(com.fanap.podchat.util.InviteType) Log(android.util.Log) Participant(com.fanap.podchat.mainmodel.Participant) RequestCreatePublicThread(com.fanap.podchat.chat.thread.public_thread.RequestCreatePublicThread) Predicate(java.util.function.Predicate) BlockingQueue(java.util.concurrent.BlockingQueue) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) DataTypeConverter(com.fanap.podchat.util.DataTypeConverter) JsonArray(com.google.gson.JsonArray) List(java.util.List) Type(java.lang.reflect.Type) Assert.assertFalse(org.junit.Assert.assertFalse) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) Nullable(android.support.annotation.Nullable) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ThreadManager(com.fanap.podchat.chat.thread.ThreadManager) CacheCallParticipant(com.fanap.podchat.call.persist.CacheCallParticipant) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) NonNull(android.support.annotation.NonNull) ArrayList(java.util.ArrayList) Observable(rx.Observable) JsonElement(com.google.gson.JsonElement) Calendar(java.util.Calendar) Build(android.os.Build) Contact(com.fanap.podchat.mainmodel.Contact) ExecutorService(java.util.concurrent.ExecutorService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) PhoneContact(com.fanap.podchat.cachemodel.PhoneContact) Util(com.fanap.podchat.util.Util) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) Assert(org.junit.Assert) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) Test(org.junit.Test)

Example 4 with RoomIntegrityException

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);
        }
    });
}
Also used : PodChatException(com.fanap.podchat.util.PodChatException) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) ArrayList(java.util.ArrayList) List(java.util.List) PodChatException(com.fanap.podchat.util.PodChatException) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException)

Example 5 with RoomIntegrityException

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;
}
Also used : AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) JsonObject(com.google.gson.JsonObject) ChatMessageContent(com.fanap.podchat.mainmodel.ChatMessageContent)

Aggregations

RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Participant (com.fanap.podchat.mainmodel.Participant)3 CacheParticipant (com.fanap.podchat.cachemodel.CacheParticipant)2 RequestGetHashTagList (com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList)2 RequestGetMentionList (com.fanap.podchat.chat.mention.model.RequestGetMentionList)2 ChatResponse (com.fanap.podchat.model.ChatResponse)2 OutPutParticipant (com.fanap.podchat.model.OutPutParticipant)2 ResultAddParticipant (com.fanap.podchat.model.ResultAddParticipant)2 ResultBlockList (com.fanap.podchat.model.ResultBlockList)2 ResultParticipant (com.fanap.podchat.model.ResultParticipant)2 RequestBlockList (com.fanap.podchat.requestobject.RequestBlockList)2 RequestDeliveredMessageList (com.fanap.podchat.requestobject.RequestDeliveredMessageList)2 RequestSeenMessageList (com.fanap.podchat.requestobject.RequestSeenMessageList)2 RequestThreadParticipant (com.fanap.podchat.requestobject.RequestThreadParticipant)2 Build (android.os.Build)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 Log (android.util.Log)1