Search in sources :

Example 1 with ChatResponse

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);
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) ResultClearHistory(com.fanap.podchat.model.ResultClearHistory)

Example 2 with ChatResponse

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;
}
Also used : ChatResponse(com.fanap.podchat.model.ChatResponse) Response(retrofit2.Response) Contacts(com.fanap.podchat.model.Contacts) JsonObject(com.google.gson.JsonObject) ResultAddContact(com.fanap.podchat.model.ResultAddContact)

Example 3 with ChatResponse

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;
                }
            }
        }
    }
}
Also used : Callback(com.fanap.podchat.util.Callback) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultMessage(com.fanap.podchat.model.ResultMessage)

Example 4 with ChatResponse

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;
}
Also used : ResultThreads(com.fanap.podchat.model.ResultThreads) ChatResponse(com.fanap.podchat.model.ChatResponse) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) HandlerThread(android.os.HandlerThread) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) RequestThread(com.fanap.podchat.requestobject.RequestThread) ResultThread(com.fanap.podchat.model.ResultThread) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread)

Example 5 with ChatResponse

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();
    }
}
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)

Aggregations

ChatResponse (com.fanap.podchat.model.ChatResponse)162 ChatListener (com.fanap.podchat.chat.ChatListener)38 Test (org.junit.Test)38 ArrayList (java.util.ArrayList)35 Thread (com.fanap.podchat.mainmodel.Thread)29 JsonSyntaxException (com.google.gson.JsonSyntaxException)29 ResultHistory (com.fanap.podchat.model.ResultHistory)28 LargeTest (android.support.test.filters.LargeTest)27 RequestThread (com.fanap.podchat.requestobject.RequestThread)27 PodChatException (com.fanap.podchat.util.PodChatException)26 MessageVO (com.fanap.podchat.mainmodel.MessageVO)25 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)23 IOException (java.io.IOException)23 JSONException (org.json.JSONException)22 ResultThreads (com.fanap.podchat.model.ResultThreads)21 RequestGetHistory (com.fanap.podchat.requestobject.RequestGetHistory)21 SentryException (io.sentry.core.protocol.SentryException)21 FlakyTest (android.support.test.filters.FlakyTest)19 MediumTest (android.support.test.filters.MediumTest)19 Activity (android.app.Activity)17