Search in sources :

Example 1 with ConversationType

use of com.zoho.livechat.android.constants.ConversationType in project SalesIQ-Mobilisten-ReactNative by zoho.

the class RNZohoSalesIQ method getChatsWithFilter.

@ReactMethod
public void getChatsWithFilter(@NonNull final String filter, @NonNull final Callback listCallback) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {

        public void run() {
            try {
                if (isValidFilterName(filter)) {
                    ConversationType filterName = getFilterName(filter);
                    ZohoSalesIQ.Chat.getList(filterName, new ConversationListener() {

                        @Override
                        public void onSuccess(ArrayList<VisitorChat> arrayList) {
                            if (arrayList != null) {
                                WritableArray array = new WritableNativeArray();
                                for (int i = 0; i < arrayList.size(); i++) {
                                    VisitorChat chat = arrayList.get(i);
                                    WritableMap visitorMap = getChatMapObject(chat);
                                    array.pushMap(visitorMap);
                                }
                                listCallback.invoke(null, array);
                            }
                        }

                        @Override
                        public void onFailure(int code, String message) {
                            WritableMap errorMap = new WritableNativeMap();
                            // No I18N
                            errorMap.putInt("code", code);
                            // No I18N
                            errorMap.putString("message", message);
                            listCallback.invoke(errorMap, null);
                        }
                    });
                } else {
                    WritableMap errorMap = new WritableNativeMap();
                    // No I18N
                    errorMap.putInt("code", INVALID_FILTER_CODE);
                    // No I18N
                    errorMap.putString("message", INVALID_FILTER_TYPE);
                    listCallback.invoke(errorMap, null);
                }
            } catch (Exception e) {
                LiveChatUtil.log(e);
            }
        }
    });
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) ArrayList(java.util.ArrayList) Handler(android.os.Handler) VisitorChat(com.zoho.livechat.android.VisitorChat) WritableNativeArray(com.facebook.react.bridge.WritableNativeArray) InvalidEmailException(com.zoho.livechat.android.exception.InvalidEmailException) InvalidVisitorIDException(com.zoho.livechat.android.exception.InvalidVisitorIDException) ConversationType(com.zoho.livechat.android.constants.ConversationType) ConversationListener(com.zoho.livechat.android.listeners.ConversationListener) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

Handler (android.os.Handler)1 ReactMethod (com.facebook.react.bridge.ReactMethod)1 WritableArray (com.facebook.react.bridge.WritableArray)1 WritableMap (com.facebook.react.bridge.WritableMap)1 WritableNativeArray (com.facebook.react.bridge.WritableNativeArray)1 WritableNativeMap (com.facebook.react.bridge.WritableNativeMap)1 VisitorChat (com.zoho.livechat.android.VisitorChat)1 ConversationType (com.zoho.livechat.android.constants.ConversationType)1 InvalidEmailException (com.zoho.livechat.android.exception.InvalidEmailException)1 InvalidVisitorIDException (com.zoho.livechat.android.exception.InvalidVisitorIDException)1 ConversationListener (com.zoho.livechat.android.listeners.ConversationListener)1 ArrayList (java.util.ArrayList)1