Search in sources :

Example 86 with ChatResponse

use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method removeContact.

/**
 * Remove contact with the user id
 *
 * @param userId id of the user that we want to remove from contact list
 */
@Deprecated
public String removeContact(long userId) {
    String uniqueId = generateUniqueId();
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("uniqueId", uniqueId);
    jsonObject.addProperty("id", userId);
    jsonObject.addProperty("tokenIssuer", 1);
    showLog("SEND_REMOVE_CONTACT", getJsonForLog(jsonObject));
    Observable<Response<ContactRemove>> removeContactObservable;
    if (chatReady) {
        if (Util.isNullOrEmpty(getTypeCode())) {
            removeContactObservable = contactApi.removeContact(getToken(), 1, userId);
        } else {
            removeContactObservable = contactApi.removeContact(getToken(), 1, userId, getTypeCode());
        }
        removeContactObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(response -> {
            Log.d("MTAG", response.raw().toString());
            if (response.body() != null && response.isSuccessful()) {
                ContactRemove contactRemove = response.body();
                if (!contactRemove.getHasError()) {
                    ChatResponse<ResultRemoveContact> chatResponse = new ChatResponse<>();
                    chatResponse.setUniqueId(uniqueId);
                    ResultRemoveContact resultRemoveContact = new ResultRemoveContact();
                    resultRemoveContact.setResult(contactRemove.isResult());
                    chatResponse.setResult(resultRemoveContact);
                    String json = gson.toJson(chatResponse);
                    if (cache) {
                        dataSource.deleteContactById(userId);
                    // messageDatabaseHelper.deleteContactById(userId);
                    }
                    listenerManager.callOnRemoveContact(json, chatResponse);
                    showLog("RECEIVED_REMOVE_CONTACT", json);
                } else {
                    captureError(contactRemove.getErrorMessage(), contactRemove.getErrorCode(), uniqueId);
                }
            }
        }, (Throwable throwable) -> captureError(throwable.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, uniqueId, throwable));
    } 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) ContactRemove(com.fanap.podchat.model.ContactRemove) ChatResponse(com.fanap.podchat.model.ChatResponse) JsonObject(com.google.gson.JsonObject) ResultRemoveContact(com.fanap.podchat.model.ResultRemoveContact)

Example 87 with ChatResponse

use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method uploadImageToThread.

// new upload image function
private void uploadImageToThread(RequestUploadImage request, String userGroupHash, String uniqueId, @Nullable ProgressHandler.onProgress handler, OnWorkDone listener) {
    if (needReadStoragePermission(request.getActivity())) {
        String jsonError = captureError(ChatConstant.ERROR_READ_EXTERNAL_STORAGE_PERMISSION, ChatConstant.ERROR_CODE_READ_EXTERNAL_STORAGE_PERMISSION, uniqueId);
        ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_READ_EXTERNAL_STORAGE_PERMISSION, ChatConstant.ERROR_CODE_READ_EXTERNAL_STORAGE_PERMISSION, uniqueId);
        if (handler != null) {
            handler.onError(jsonError, error);
        }
        listener.onWorkDone(null);
        return;
    }
    if (!chatReady) {
        onChatNotReady(uniqueId);
        listener.onWorkDone(null);
        return;
    }
    if (getPodSpaceServer() == null) {
        listener.onWorkDone(null);
        captureError("File server is null", 0, uniqueId);
        return;
    }
    try {
        Subscription subscription = PodUploader.uploadToPodSpace(uniqueId, request.getFileUri(), userGroupHash, context, getPodSpaceServer(), getToken(), TOKEN_ISSUER, String.valueOf(request.getxC()), String.valueOf(request.getyC()), String.valueOf(request.gethC()), String.valueOf(request.getwC()), new PodUploader.IPodUploadFileToPodSpace() {

            @Override
            public void onSuccess(UploadToPodSpaceResult response, File file, String mimeType, long length, int actualWidth, int actualHeight, int width, int height) {
                ChatResponse<ResultImageFile> chatResponse = PodUploader.generateImageUploadResultForSendMessage(response, uniqueId, actualWidth, actualHeight, width, height, getPodSpaceImageUrl(response.getHashCode()));
                String imageJson = gson.toJson(chatResponse);
                listenerManager.callOnUploadImageFile(imageJson, chatResponse);
                if (handler != null) {
                    handler.onFinish(imageJson, chatResponse);
                }
                showLog("RECEIVE_UPLOAD_IMAGE", imageJson);
                listener.onWorkDone(response.getHashCode());
            }

            @Override
            public void onFailure(String cause, Throwable t) {
                String jsonError = captureError(cause, ChatConstant.ERROR_CODE_UPLOAD_FILE, uniqueId, t);
                ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId);
                if (handler != null) {
                    handler.onError(jsonError, error);
                }
                listener.onWorkDone(null);
            }

            @Override
            public void onUploadStarted(String mimeType, File file, long length) {
                showLog("UPLOADING_FILE");
            }

            @Override
            public void onProgressUpdate(int progress, int totalBytesSent, int totalBytesToSend) {
                if (handler != null) {
                    handler.onProgressUpdate(progress);
                    handler.onProgressUpdate(uniqueId, progress, totalBytesSent, totalBytesToSend);
                }
            }
        });
        initCancelUpload(uniqueId, subscription);
    } catch (Exception e) {
        String jsonError = captureError(ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId, e);
        ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId);
        listener.onWorkDone(null);
        if (handler != null) {
            handler.onError(jsonError, error);
        }
    }
}
Also used : PodUploader(com.fanap.podchat.chat.file_manager.upload_file.PodUploader) JSONException(org.json.JSONException) SentryException(io.sentry.core.protocol.SentryException) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) PodChatException(com.fanap.podchat.util.PodChatException) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) UploadToPodSpaceResult(com.fanap.podchat.chat.file_manager.upload_file.UploadToPodSpaceResult) ChatResponse(com.fanap.podchat.model.ChatResponse) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) Subscription(rx.Subscription) MetaDataFile(com.fanap.podchat.model.MetaDataFile) RequestUploadFile(com.fanap.podchat.requestobject.RequestUploadFile) ResultDownloadFile(com.fanap.podchat.chat.file_manager.download_file.model.ResultDownloadFile) ResultFile(com.fanap.podchat.model.ResultFile) RequestGetPodSpaceFile(com.fanap.podchat.requestobject.RequestGetPodSpaceFile) RequestGetFile(com.fanap.podchat.requestobject.RequestGetFile) RequestCreateThreadWithFile(com.fanap.podchat.requestobject.RequestCreateThreadWithFile) File(java.io.File) ResultImageFile(com.fanap.podchat.model.ResultImageFile)

Example 88 with ChatResponse

use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method getTagList.

/**
 * get user tags
 */
public String getTagList(GetTagListRequest request) {
    String uniqueId = generateUniqueId();
    if (cache) {
        messageDatabaseHelper.getTagVos().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).filter(tags -> tags != null && tags.size() > 0).subscribe(tags -> {
            ChatResponse<TagListResult> response = new ChatResponse<>();
            response.setResult(new TagListResult(tags));
            response.setUniqueId(uniqueId);
            response.setCache(true);
            listenerManager.callOnTagList(null, response);
        });
    }
    if (chatReady) {
        String message = TagManager.createTagListRequest(request, uniqueId);
        sendAsyncMessage(message, AsyncAckType.Constants.WITHOUT_ACK, "GET_TAG_LIST");
    } else {
        onChatNotReady(uniqueId);
    }
    return uniqueId;
}
Also used : ResultNewMessage(com.fanap.podchat.model.ResultNewMessage) MessageManager(com.fanap.podchat.chat.messge.MessageManager) RequestGetUserRoles(com.fanap.podchat.requestobject.RequestGetUserRoles) RetrofitHelperPlatformHost(com.fanap.podchat.networking.retrofithelper.RetrofitHelperPlatformHost) PhoneContactDbHelper(com.fanap.podchat.persistance.PhoneContactDbHelper) ChatConstant(com.fanap.podchat.util.ChatConstant) GsonBuilder(com.google.gson.GsonBuilder) MapApi(com.fanap.podchat.networking.api.MapApi) JSONException(org.json.JSONException) ResultClearHistory(com.fanap.podchat.model.ResultClearHistory) Async(com.fanap.podasync.Async) Handler(android.os.Handler) MediaStore(android.provider.MediaStore) Map(java.util.Map) OPEN(com.fanap.podchat.util.ChatStateType.ChatSateConstant.OPEN) Schedulers(rx.schedulers.Schedulers) NetworkStateListener(com.fanap.podchat.util.NetworkUtils.NetworkStateListener) FileMetaDataContent(com.fanap.podchat.model.FileMetaDataContent) CONNECTING(com.fanap.podchat.util.ChatStateType.ChatSateConstant.CONNECTING) EditTagRequest(com.fanap.podchat.chat.tag.request_model.EditTagRequest) Log(android.util.Log) MediaType(okhttp3.MediaType) ConnectivityManager(android.net.ConnectivityManager) RequestGetImage(com.fanap.podchat.requestobject.RequestGetImage) Device(com.fanap.podasync.model.Device) IntentFilter(android.content.IntentFilter) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) ResultCurrentUserRoles(com.fanap.podchat.chat.user.user_roles.model.ResultCurrentUserRoles) RequestAddContact(com.fanap.podchat.requestobject.RequestAddContact) HashTagManager(com.fanap.podchat.chat.hashtag.HashTagManager) RestrictTo(android.support.annotation.RestrictTo) MetaDataFile(com.fanap.podchat.model.MetaDataFile) GetAssistantRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantRequest) MapRout(com.fanap.podchat.mainmodel.MapRout) RequestReplyMessage(com.fanap.podchat.requestobject.RequestReplyMessage) Sentry(io.sentry.core.Sentry) RequestLocationMessage(com.fanap.podchat.requestobject.RequestLocationMessage) TimeoutConfig(com.fanap.podchat.networking.retrofithelper.TimeoutConfig) DeviceResult(com.fanap.podasync.model.DeviceResult) NonNull(android.support.annotation.NonNull) ResultBlockList(com.fanap.podchat.model.ResultBlockList) JsonParser(com.google.gson.JsonParser) ResultAddParticipant(com.fanap.podchat.model.ResultAddParticipant) RegisterAssistantRequest(com.fanap.podchat.chat.assistant.request_model.RegisterAssistantRequest) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultParticipant(com.fanap.podchat.model.ResultParticipant) NosqlListMessageCriteriaVO(com.fanap.podchat.mainmodel.NosqlListMessageCriteriaVO) ResultRemoveContact(com.fanap.podchat.model.ResultRemoveContact) RequestUploadFile(com.fanap.podchat.requestobject.RequestUploadFile) User(io.sentry.core.protocol.User) BuildConfig(com.fanap.podchat.BuildConfig) Admin(com.fanap.podchat.model.Admin) ResultAddContact(com.fanap.podchat.model.ResultAddContact) UserRoles(com.fanap.podchat.chat.user.user_roles.UserRoles) SentryException(io.sentry.core.protocol.SentryException) UpdateContact(com.fanap.podchat.mainmodel.UpdateContact) IOException(java.io.IOException) MemoryDataSource(com.fanap.podchat.repository.MemoryDataSource) CreateTagRequest(com.fanap.podchat.chat.tag.request_model.CreateTagRequest) RequestGetUnreadMessagesCount(com.fanap.podchat.chat.messge.RequestGetUnreadMessagesCount) RequestUpdateProfile(com.fanap.podchat.chat.user.profile.RequestUpdateProfile) TagResult(com.fanap.podchat.chat.tag.result_model.TagResult) UploadingQueueCache(com.fanap.podchat.cachemodel.queue.UploadingQueueCache) ResultMapReverse(com.fanap.podchat.model.ResultMapReverse) RequestCreateThread(com.fanap.podchat.requestobject.RequestCreateThread) OnWorkDone(com.fanap.podchat.util.OnWorkDone) JsonObject(com.google.gson.JsonObject) ResultDownloadFile(com.fanap.podchat.chat.file_manager.download_file.model.ResultDownloadFile) ResultIsNameAvailable(com.fanap.podchat.chat.thread.public_thread.ResultIsNameAvailable) RequestForwardMessage(com.fanap.podchat.requestobject.RequestForwardMessage) Date(java.util.Date) RequestSetAuditor(com.fanap.podchat.requestobject.RequestSetAuditor) ResultFile(com.fanap.podchat.model.ResultFile) NetworkStateReceiver(com.fanap.podchat.util.NetworkUtils.NetworkStateReceiver) JSONObject(org.json.JSONObject) ContactsContract(android.provider.ContactsContract) TagListResult(com.fanap.podchat.chat.tag.result_model.TagListResult) RequestGetContact(com.fanap.podchat.requestobject.RequestGetContact) Gson(com.google.gson.Gson) RequestGetPodSpaceFile(com.fanap.podchat.requestobject.RequestGetPodSpaceFile) SetRuleVO(com.fanap.podchat.localmodel.SetRuleVO) OutPutHistory(com.fanap.podchat.model.OutPutHistory) ContactApi(com.fanap.podchat.networking.api.ContactApi) RequestMapReverse(com.fanap.podchat.requestobject.RequestMapReverse) FilePick(com.fanap.podchat.util.FilePick) RequestGetFile(com.fanap.podchat.requestobject.RequestGetFile) Participant(com.fanap.podchat.mainmodel.Participant) RequestCreateThreadWithFile(com.fanap.podchat.requestobject.RequestCreateThreadWithFile) CacheUserRoles(com.fanap.podchat.chat.user.user_roles.model.CacheUserRoles) ResultPinThread(com.fanap.podchat.chat.pin.pin_thread.model.ResultPinThread) AsyncTask(android.os.AsyncTask) Error(com.fanap.podchat.model.Error) RequestUpdateContact(com.fanap.podchat.requestobject.RequestUpdateContact) ThreadVo(com.fanap.podchat.cachemodel.ThreadVo) RequestSpam(com.fanap.podchat.requestobject.RequestSpam) ChangeThreadTypeRequest(com.fanap.podchat.chat.thread.request.ChangeThreadTypeRequest) UUID(java.util.UUID) ChatMessageContent(com.fanap.podchat.mainmodel.ChatMessageContent) Objects(java.util.Objects) CloseThreadResult(com.fanap.podchat.chat.thread.respone.CloseThreadResult) R(com.fanap.podchat.R) RequestCheckIsNameAvailable(com.fanap.podchat.chat.thread.public_thread.RequestCheckIsNameAvailable) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) GetBlockedAssistantsRequest(com.fanap.podchat.chat.assistant.request_model.GetBlockedAssistantsRequest) RequestSignalMsg(com.fanap.podchat.requestobject.RequestSignalMsg) ResultUserInfo(com.fanap.podchat.model.ResultUserInfo) RequestSetAdmin(com.fanap.podchat.requestobject.RequestSetAdmin) Nullable(android.support.annotation.Nullable) OutPutNotSeenDurations(com.fanap.podchat.model.OutPutNotSeenDurations) Call(retrofit2.Call) Subscription(rx.Subscription) Callback(com.fanap.podchat.util.Callback) RetrofitHelperMap(com.fanap.podchat.networking.retrofithelper.RetrofitHelperMap) DaggerMessageComponent(com.fanap.podchat.persistance.module.DaggerMessageComponent) RequestConnect(com.fanap.podchat.requestobject.RequestConnect) AssistantVo(com.fanap.podchat.chat.assistant.model.AssistantVo) ThreadInfoVO(com.fanap.podchat.mainmodel.ThreadInfoVO) Thread(com.fanap.podchat.mainmodel.Thread) RequestLeaveThread(com.fanap.podchat.requestobject.RequestLeaveThread) Constants(com.fanap.podchat.util.ChatMessageType.Constants) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CursorLoader(android.support.v4.content.CursorLoader) FileUpload(com.fanap.podchat.mainmodel.FileUpload) RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) RequestGetPodSpaceImage(com.fanap.podchat.requestobject.RequestGetPodSpaceImage) PinMessage(com.fanap.podchat.chat.pin.pin_message.PinMessage) RequestBody(okhttp3.RequestBody) HashSet(java.util.HashSet) Inject(javax.inject.Inject) SearchSystemMetadataRequest(com.fanap.podchat.chat.messge.SearchSystemMetadataRequest) GetUserBotsResult(com.fanap.podchat.chat.bot.result_model.GetUserBotsResult) GapMessageVO(com.fanap.podchat.cachemodel.GapMessageVO) Contact(com.fanap.podchat.mainmodel.Contact) RetrofitHelperSsoHost(com.fanap.podchat.networking.retrofithelper.RetrofitHelperSsoHost) RequestSeenMessage(com.fanap.podchat.requestobject.RequestSeenMessage) RequestGetLastSeens(com.fanap.podchat.requestobject.RequestGetLastSeens) JsonSyntaxException(com.google.gson.JsonSyntaxException) CLOSING(com.fanap.podchat.util.ChatStateType.ChatSateConstant.CLOSING) RequestCreateThreadWithMessage(com.fanap.podchat.requestobject.RequestCreateThreadWithMessage) RequestGetMentionList(com.fanap.podchat.chat.mention.model.RequestGetMentionList) ResultPinMessage(com.fanap.podchat.chat.pin.pin_message.model.ResultPinMessage) LFileUpload(com.fanap.podchat.localmodel.LFileUpload) PodDownloader(com.fanap.podchat.chat.file_manager.download_file.PodDownloader) Util(com.fanap.podchat.util.Util) ResultSignalMessage(com.fanap.podchat.model.ResultSignalMessage) HandlerThread(android.os.HandlerThread) Bitmap(android.graphics.Bitmap) SentryLevel(io.sentry.core.SentryLevel) CLOSED(com.fanap.podchat.util.ChatStateType.ChatSateConstant.CLOSED) AppModule(com.fanap.podchat.persistance.module.AppModule) Activity(android.app.Activity) PodNotificationManager(com.fanap.podchat.notification.PodNotificationManager) Mention(com.fanap.podchat.chat.mention.Mention) ResultContact(com.fanap.podchat.model.ResultContact) ResultThreads(com.fanap.podchat.model.ResultThreads) ChatStateType(com.fanap.podchat.util.ChatStateType) StartAndStopBotRequest(com.fanap.podchat.chat.bot.request_model.StartAndStopBotRequest) CustomNotificationConfig(com.fanap.podchat.notification.CustomNotificationConfig) TypeToken(com.google.gson.reflect.TypeToken) SendingQueueCache(com.fanap.podchat.cachemodel.queue.SendingQueueCache) AsyncAckType(com.fanap.podchat.util.AsyncAckType) Uri(android.net.Uri) AddTagParticipantRequest(com.fanap.podchat.chat.tag.request_model.AddTagParticipantRequest) ResultHistory(com.fanap.podchat.model.ResultHistory) SSOApi(com.fanap.podchat.networking.api.SSOApi) RequestRemoveContact(com.fanap.podchat.requestobject.RequestRemoveContact) Looper(android.os.Looper) PinThread(com.fanap.podchat.chat.pin.pin_thread.PinThread) PingManager(com.fanap.podchat.chat.ping.PingManager) BotManager(com.fanap.podchat.chat.bot.BotManager) ProgressResponseBody(com.fanap.podchat.networking.ProgressResponseBody) RemoveTagParticipantRequest(com.fanap.podchat.chat.tag.request_model.RemoveTagParticipantRequest) RequestThreadInnerMessage(com.fanap.podchat.mainmodel.RequestThreadInnerMessage) ResponseBody(okhttp3.ResponseBody) CloseThreadRequest(com.fanap.podchat.chat.thread.request.CloseThreadRequest) RequestReplyFileMessage(com.fanap.podchat.requestobject.RequestReplyFileMessage) RequestDeliveredMessageList(com.fanap.podchat.requestobject.RequestDeliveredMessageList) ResultLeaveThread(com.fanap.podchat.model.ResultLeaveThread) ContactManager(com.fanap.podchat.chat.contact.ContactManager) Permission(com.fanap.podchat.util.Permission) AsyncMessage(com.fanap.podchat.mainmodel.AsyncMessage) Set(java.util.Set) CreateBotResult(com.fanap.podchat.chat.bot.result_model.CreateBotResult) RequestMuteThread(com.fanap.podchat.requestobject.RequestMuteThread) FileApi(com.fanap.podchat.networking.api.FileApi) RetryUpload(com.fanap.podchat.requestobject.RetryUpload) JsonArray(com.google.gson.JsonArray) AppDatabaseModule(com.fanap.podchat.persistance.module.AppDatabaseModule) MultipartBody(okhttp3.MultipartBody) TextMessageType(com.fanap.podchat.util.TextMessageType) RequestDeleteMessage(com.fanap.podchat.requestobject.RequestDeleteMessage) ASYNC_READY(com.fanap.podchat.util.ChatStateType.ChatSateConstant.ASYNC_READY) SentryEvent(io.sentry.core.SentryEvent) ResultDeleteMessage(com.fanap.podchat.mainmodel.ResultDeleteMessage) CacheParticipant(com.fanap.podchat.cachemodel.CacheParticipant) FileUtils(com.fanap.podchat.util.FileUtils) ResultJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.ResultJoinPublicThread) ResultBlock(com.fanap.podchat.model.ResultBlock) ResultUpdateProfile(com.fanap.podchat.chat.user.profile.ResultUpdateProfile) PodChatException(com.fanap.podchat.util.PodChatException) RequestFileMessage(com.fanap.podchat.requestobject.RequestFileMessage) Environment(android.os.Environment) ThreadManager(com.fanap.podchat.chat.thread.ThreadManager) RetrofitHelperFileServer(com.fanap.podchat.networking.retrofithelper.RetrofitHelperFileServer) GetTagListRequest(com.fanap.podchat.chat.tag.request_model.GetTagListRequest) BitmapFactory(android.graphics.BitmapFactory) DefineBotCommandResult(com.fanap.podchat.chat.bot.result_model.DefineBotCommandResult) RequestJoinPublicThread(com.fanap.podchat.chat.thread.public_thread.RequestJoinPublicThread) Response(retrofit2.Response) PublicThread(com.fanap.podchat.chat.thread.public_thread.PublicThread) ArrayList(java.util.ArrayList) ContactRemove(com.fanap.podchat.model.ContactRemove) MapManager(com.fanap.podchat.chat.map.MapManager) SafeLeaveRequest(com.fanap.podchat.chat.thread.request.SafeLeaveRequest) RequestThreadParticipant(com.fanap.podchat.requestobject.RequestThreadParticipant) TagManager(com.fanap.podchat.chat.tag.TagManager) RequestAddParticipants(com.fanap.podchat.requestobject.RequestAddParticipants) RequestUnBlock(com.fanap.podchat.requestobject.RequestUnBlock) RequestThread(com.fanap.podchat.requestobject.RequestThread) RequestMapStaticImage(com.fanap.podchat.requestobject.RequestMapStaticImage) ResultThread(com.fanap.podchat.model.ResultThread) UserProfile(com.fanap.podchat.chat.user.profile.UserProfile) RequestGetHistory(com.fanap.podchat.requestobject.RequestGetHistory) CHAT_READY(com.fanap.podchat.util.ChatStateType.ChatSateConstant.CHAT_READY) TextUtils(android.text.TextUtils) GetMutualGroupRequest(com.fanap.podchat.chat.thread.request.GetMutualGroupRequest) AssistantManager(com.fanap.podchat.chat.assistant.AssistantManager) DeActiveAssistantRequest(com.fanap.podchat.chat.assistant.request_model.DeActiveAssistantRequest) ParticipantsManager(com.fanap.podchat.chat.participant.ParticipantsManager) File(java.io.File) ResultMessage(com.fanap.podchat.model.ResultMessage) OutPutMapRout(com.fanap.podchat.model.OutPutMapRout) BlockUnblockAssistantRequest(com.fanap.podchat.chat.assistant.request_model.BlockUnblockAssistantRequest) ChatDataSource(com.fanap.podchat.repository.ChatDataSource) RequestPinThread(com.fanap.podchat.chat.pin.pin_thread.model.RequestPinThread) CacheMessageVO(com.fanap.podchat.cachemodel.CacheMessageVO) RequestGetAdmin(com.fanap.podchat.requestobject.RequestGetAdmin) DefineBotCommandRequest(com.fanap.podchat.chat.bot.request_model.DefineBotCommandRequest) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) StatusPingResult(com.fanap.podchat.chat.ping.result.StatusPingResult) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) OutputSetRoleToUser(com.fanap.podchat.model.OutputSetRoleToUser) RequestPinMessage(com.fanap.podchat.chat.pin.pin_message.model.RequestPinMessage) PodThreadManager(com.fanap.podchat.util.PodThreadManager) SentryAndroid(io.sentry.android.core.SentryAndroid) AsyncAdapter(com.fanap.podasync.AsyncAdapter) OutPutParticipant(com.fanap.podchat.model.OutPutParticipant) RequestThreadInfo(com.fanap.podchat.requestobject.RequestThreadInfo) RequestBlockList(com.fanap.podchat.requestobject.RequestBlockList) Invitee(com.fanap.podchat.mainmodel.Invitee) RequestUploadImage(com.fanap.podchat.requestobject.RequestUploadImage) FileImageMetaData(com.fanap.podchat.model.FileImageMetaData) SearchManager(com.fanap.podchat.chat.search.SearchManager) OutputSignalMessage(com.fanap.podchat.model.OutputSignalMessage) MessageDatabaseHelper(com.fanap.podchat.persistance.MessageDatabaseHelper) MessageVO(com.fanap.podchat.mainmodel.MessageVO) ResultSetAdmin(com.fanap.podchat.model.ResultSetAdmin) DownloadManager(android.app.DownloadManager) CacheDataSource(com.fanap.podchat.repository.CacheDataSource) AssistantHistoryVo(com.fanap.podchat.chat.assistant.model.AssistantHistoryVo) RequestGetHashTagList(com.fanap.podchat.chat.hashtag.model.RequestGetHashTagList) ResultImageFile(com.fanap.podchat.model.ResultImageFile) RequestSeenMessageList(com.fanap.podchat.requestobject.RequestSeenMessageList) List(java.util.List) RequestMapRouting(com.fanap.podchat.requestobject.RequestMapRouting) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) PublishSubject(rx.subjects.PublishSubject) Contacts(com.fanap.podchat.model.Contacts) Context(android.content.Context) GetAssistantHistoryRequest(com.fanap.podchat.chat.assistant.request_model.GetAssistantHistoryRequest) ContactSyncedResult(com.fanap.podchat.chat.contact.result_model.ContactSyncedResult) History(com.fanap.podchat.mainmodel.History) TagVo(com.fanap.podchat.model.TagVo) NetworkPingSender(com.fanap.podchat.util.NetworkUtils.NetworkPingSender) HashMap(java.util.HashMap) GetUserBotsRequest(com.fanap.podchat.chat.bot.request_model.GetUserBotsRequest) Observable(rx.Observable) JsonElement(com.google.gson.JsonElement) Breadcrumb(io.sentry.core.Breadcrumb) WaitQueueCache(com.fanap.podchat.cachemodel.queue.WaitQueueCache) ResultUnreadMessagesCount(com.fanap.podchat.chat.messge.ResultUnreadMessagesCount) RequestMapSearch(com.fanap.podchat.util.RequestMapSearch) PodUploader(com.fanap.podchat.chat.file_manager.upload_file.PodUploader) TagParticipantResult(com.fanap.podchat.chat.tag.result_model.TagParticipantResult) ResultNotSeenDuration(com.fanap.podchat.model.ResultNotSeenDuration) UploadToPodSpaceResult(com.fanap.podchat.chat.file_manager.upload_file.UploadToPodSpaceResult) UserInfo(com.fanap.podchat.mainmodel.UserInfo) StartStopBotResult(com.fanap.podchat.chat.bot.result_model.StartStopBotResult) ResultThreadsSummary(com.fanap.podchat.model.ResultThreadsSummary) ResultStaticMapImage(com.fanap.podchat.model.ResultStaticMapImage) Cursor(android.database.Cursor) RequestMessage(com.fanap.podchat.requestobject.RequestMessage) ResultMute(com.fanap.podchat.model.ResultMute) RequestClearHistory(com.fanap.podchat.requestobject.RequestClearHistory) CreateBotRequest(com.fanap.podchat.chat.bot.request_model.CreateBotRequest) StatusPingRequest(com.fanap.podchat.chat.ping.request.StatusPingRequest) PhoneContact(com.fanap.podchat.cachemodel.PhoneContact) RequestEditMessage(com.fanap.podchat.requestobject.RequestEditMessage) ProgressRequestBody(com.fanap.podchat.networking.ProgressRequestBody) RequestBlock(com.fanap.podchat.requestobject.RequestBlock) FileImageUpload(com.fanap.podchat.model.FileImageUpload) ProgressHandler(com.fanap.podchat.ProgressHandler) RemoveParticipantRequest(com.fanap.podchat.requestobject.RemoveParticipantRequest) MapReverse(com.fanap.podchat.mainmodel.MapReverse) SecurePreferences(com.securepreferences.SecurePreferences) DeleteTagRequest(com.fanap.podchat.chat.tag.request_model.DeleteTagRequest) Collections(java.util.Collections) MimeTypeMap(android.webkit.MimeTypeMap) ResultUpdateContact(com.fanap.podchat.model.ResultUpdateContact) ChatResponse(com.fanap.podchat.model.ChatResponse) TagListResult(com.fanap.podchat.chat.tag.result_model.TagListResult)

Example 89 with ChatResponse

use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method handleOutPutDeliveredMessageList.

private void handleOutPutDeliveredMessageList(ChatMessage chatMessage, Callback callback) {
    try {
        ChatResponse<ResultParticipant> chatResponse = new ChatResponse<>();
        chatResponse.setUniqueId(chatMessage.getUniqueId());
        ResultParticipant resultParticipant = new ResultParticipant();
        List<Participant> participants = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Participant>>() {
        }.getType());
        resultParticipant.setParticipants(participants);
        resultParticipant.setContentCount(chatMessage.getContentCount());
        resultParticipant.setNextOffset(callback.getOffset() + participants.size());
        resultParticipant.setContentCount(chatMessage.getContentCount());
        resultParticipant.setHasNext(participants.size() + callback.getOffset() < chatMessage.getContentCount());
        chatResponse.setResult(resultParticipant);
        String content = gson.toJson(chatResponse);
        if (sentryResponseLog) {
            showLog("RECEIVE_DELIVERED_MESSAGE_LIST", content);
        } else {
            showLog("RECEIVE_DELIVERED_MESSAGE_LIST");
        }
        listenerManager.callOnDeliveredMessageList(content, chatResponse);
    } catch (Exception e) {
        showErrorLog(e.getMessage());
        onUnknownException(chatMessage.getUniqueId(), e);
    }
}
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) TypeToken(com.google.gson.reflect.TypeToken) ChatResponse(com.fanap.podchat.model.ChatResponse) JSONException(org.json.JSONException) SentryException(io.sentry.core.protocol.SentryException) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) PodChatException(com.fanap.podchat.util.PodChatException) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException)

Example 90 with ChatResponse

use of com.fanap.podchat.model.ChatResponse in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method replyFileMessage.

/**
 * Reply the message in the current thread and send az message and receive at the
 * <p>
 * messageContent content of the reply message
 * threadId       id of the thread
 * messageId      of the message that we want to reply
 * metaData       meta data of the message
 */
public String replyFileMessage(RequestReplyFileMessage request, ProgressHandler.sendFileMessage handler) {
    String uniqueId = generateUniqueId();
    if (needReadStoragePermission(request.getActivity())) {
        String jsonError = captureError(ChatConstant.ERROR_READ_EXTERNAL_STORAGE_PERMISSION, ChatConstant.ERROR_CODE_READ_EXTERNAL_STORAGE_PERMISSION, uniqueId);
        ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_READ_EXTERNAL_STORAGE_PERMISSION, ChatConstant.ERROR_CODE_READ_EXTERNAL_STORAGE_PERMISSION, uniqueId);
        if (handler != null) {
            handler.onError(jsonError, error);
        }
        return uniqueId;
    }
    if (!chatReady) {
        onChatNotReady(uniqueId);
        return uniqueId;
    }
    if (getPodSpaceServer() == null) {
        captureError("PodSpace server is null", 0, uniqueId);
        return uniqueId;
    }
    long threadId = request.getThreadId();
    String messageContent = request.getMessageContent();
    String systemMetaData = request.getSystemMetaData();
    Uri fileUri = request.getFileUri();
    long messageId = request.getMessageId();
    int messageType = request.getMessageType();
    String methodName = ChatConstant.METHOD_REPLY_MSG;
    try {
        Subscription subscription = PodUploader.uploadToPodSpace(uniqueId, request.getFileUri(), request.getUserGroupHashCode(), context, getPodSpaceServer(), getToken(), TOKEN_ISSUER, request.getImageXc(), request.getImageYc(), request.getImageHc(), request.getImageWc(), new PodUploader.IPodUploadFileToPodSpace() {

            @Override
            public void onSuccess(UploadToPodSpaceResult response, File file, String mimeType, long length) {
                removeFromUploadQueue(uniqueId);
                ChatResponse<ResultFile> chatResponse = PodUploader.generateImageUploadResultForSendMessage(response, uniqueId);
                String json = gson.toJson(chatResponse);
                showLog("FILE_UPLOADED_TO_SERVER", json);
                listenerManager.callOnUploadFile(json, chatResponse);
                if (handler != null) {
                    handler.onFinishFile(json, chatResponse);
                }
                String jsonMeta = createFileMetadata(file, response.getHashCode(), 0, mimeType, length, response.getParentHash());
                showLog("SEND_REPLY_FILE_MESSAGE", jsonMeta);
                mainReplyMessage(messageContent, threadId, messageId, systemMetaData, messageType, jsonMeta, uniqueId, null);
            }

            @Override
            public void onSuccess(UploadToPodSpaceResult response, File file, String mimeType, long length, int actualWidth, int actualHeight, int width, int height) {
                removeFromUploadQueue(uniqueId);
                ChatResponse<ResultImageFile> chatResponse = PodUploader.generateImageUploadResultForSendMessage(response, uniqueId, actualWidth, actualHeight, width, height, getPodSpaceImageUrl(response.getHashCode()));
                String imageJson = gson.toJson(chatResponse);
                listenerManager.callOnUploadImageFile(imageJson, chatResponse);
                if (handler != null) {
                    handler.onFinishImage(imageJson, chatResponse);
                }
                showLog("RECEIVE_UPLOAD_IMAGE", imageJson);
                String jsonMeta = createImageMetadata(file, response.getHashCode(), 0, height, width, mimeType, length, response.getParentHash(), false, null);
                showLog("SEND_REPLY_FILE_MESSAGE", jsonMeta);
                mainReplyMessage(messageContent, threadId, messageId, systemMetaData, messageType, jsonMeta, uniqueId, null);
            }

            @Override
            public void onFailure(String cause, Throwable t) {
                String jsonError = captureError(cause, ChatConstant.ERROR_CODE_UPLOAD_FILE, uniqueId, t);
                ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId);
                if (handler != null) {
                    handler.onError(jsonError, error);
                }
            }

            @Override
            public void onUploadStarted(String mimeType, File file, long length) {
                addToUploadQueue(messageContent, fileUri, messageType, threadId, request.getUserGroupHashCode(), uniqueId, systemMetaData, messageId, mimeType, null, methodName, file, length);
                showLog("UPLOAD_FILE_TO_SERVER");
            }

            @Override
            public void onProgressUpdate(int progress, int totalBytesSent, int totalBytesToSend) {
                if (handler != null)
                    handler.onProgressUpdate(uniqueId, progress, totalBytesSent, totalBytesToSend);
            }
        });
        initCancelUpload(uniqueId, subscription);
    } catch (Exception e) {
        String jsonError = captureError(ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId, e);
        ErrorOutPut error = new ErrorOutPut(true, ChatConstant.ERROR_INVALID_FILE_URI, ChatConstant.ERROR_CODE_INVALID_FILE_URI, uniqueId);
        if (handler != null) {
            handler.onError(jsonError, error);
        }
    }
    return uniqueId;
}
Also used : Uri(android.net.Uri) PodUploader(com.fanap.podchat.chat.file_manager.upload_file.PodUploader) JSONException(org.json.JSONException) SentryException(io.sentry.core.protocol.SentryException) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException) PodChatException(com.fanap.podchat.util.PodChatException) RoomIntegrityException(com.fanap.podchat.persistance.RoomIntegrityException) UploadToPodSpaceResult(com.fanap.podchat.chat.file_manager.upload_file.UploadToPodSpaceResult) ChatResponse(com.fanap.podchat.model.ChatResponse) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) Subscription(rx.Subscription) MetaDataFile(com.fanap.podchat.model.MetaDataFile) RequestUploadFile(com.fanap.podchat.requestobject.RequestUploadFile) ResultDownloadFile(com.fanap.podchat.chat.file_manager.download_file.model.ResultDownloadFile) ResultFile(com.fanap.podchat.model.ResultFile) RequestGetPodSpaceFile(com.fanap.podchat.requestobject.RequestGetPodSpaceFile) RequestGetFile(com.fanap.podchat.requestobject.RequestGetFile) RequestCreateThreadWithFile(com.fanap.podchat.requestobject.RequestCreateThreadWithFile) File(java.io.File) ResultImageFile(com.fanap.podchat.model.ResultImageFile)

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