Search in sources :

Example 1 with UserInfo

use of com.fanap.podchat.mainmodel.UserInfo in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method getUserInfo.

/**
 * It Gets the information of the current user
 */
public String getUserInfo(ChatHandler handler) {
    String uniqueId = generateUniqueId();
    Runnable cacheLoading = () -> {
        if (permit && cache && handler != null) {
            try {
                UserInfo userInfo = messageDatabaseHelper.getUserInfo();
                if (userInfo != null) {
                    ChatResponse<ResultUserInfo> chatResponse = new ChatResponse<>();
                    ResultUserInfo result = new ResultUserInfo();
                    setUserId(userInfo.getId());
                    result.setUser(userInfo);
                    chatResponse.setResult(result);
                    chatResponse.setCache(true);
                    chatResponse.setUniqueId(uniqueId);
                    String userInfoJson = gson.toJson(chatResponse);
                    listenerManager.callOnUserInfo(userInfoJson, chatResponse);
                    showLog("CACHE_USER_INFO", userInfoJson);
                }
            } catch (Exception e) {
                showErrorLog(e.getMessage());
                onUnknownException(uniqueId, e);
            }
        }
    };
    Runnable requestServer = () -> {
        if (asyncReady) {
            ChatMessage chatMessage = new ChatMessage();
            chatMessage.setType(Constants.USER_INFO);
            chatMessage.setUniqueId(uniqueId);
            chatMessage.setToken(getToken());
            chatMessage.setTokenIssuer("1");
            setCallBacks(null, null, null, true, Constants.USER_INFO, null, uniqueId);
            JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
            if (Util.isNullOrEmpty(getTypeCode())) {
                jsonObject.remove("typeCode");
            } else {
                jsonObject.remove("typeCode");
                jsonObject.addProperty("typeCode", getTypeCode());
            }
            String asyncContent = jsonObject.toString();
            showLog("SEND_USER_INFO", asyncContent);
            async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
            if (handler != null) {
                handler.onGetUserInfo(uniqueId);
            }
        }
    };
    new PodThreadManager().addNewTask(cacheLoading).addNewTask(requestServer).runTasksSynced();
    return uniqueId;
}
Also used : PodThreadManager(com.fanap.podchat.util.PodThreadManager) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) ResultUserInfo(com.fanap.podchat.model.ResultUserInfo) ChatResponse(com.fanap.podchat.model.ChatResponse) JsonObject(com.google.gson.JsonObject) ResultUserInfo(com.fanap.podchat.model.ResultUserInfo) UserInfo(com.fanap.podchat.mainmodel.UserInfo) 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 2 with UserInfo

use of com.fanap.podchat.mainmodel.UserInfo in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method updateChatProfile.

public void updateChatProfile(ResultUpdateProfile result) {
    worker(() -> {
        UserInfo userInfo = getUserInfo();
        ChatProfileVO chatProfileVO = new ChatProfileVO();
        chatProfileVO.setId(userInfo.getId());
        chatProfileVO.setBio(result.getBio());
        userInfo.setChatProfileVO(chatProfileVO);
        messageDao.insertChatProfile(chatProfileVO);
        messageDao.insertUserInfo(userInfo);
    });
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) UserInfo(com.fanap.podchat.mainmodel.UserInfo)

Example 3 with UserInfo

use of com.fanap.podchat.mainmodel.UserInfo in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method handleOnGetUserInfo.

/**
 * Its check the Failed Queue {@link #checkMessageQueue()} to send all the message that is waiting to be send.
 */
private void handleOnGetUserInfo(ChatMessage chatMessage, String messageUniqueId, Callback callback) {
    if (callback.isResult()) {
        // if there is a key its ok if not it will go for the key and then chat ready
        ChatResponse<ResultUserInfo> chatResponse = new ChatResponse<>();
        UserInfo userInfo = gson.fromJson(chatMessage.getContent(), UserInfo.class);
        setUserId(userInfo.getId());
        setChatReady("CHAT_READY", true);
        userInfoResponse = true;
        // add user info for sentry
        setSentryUser(userInfo);
        String userInfoJson = reformatUserInfo(chatMessage, chatResponse, userInfo);
        if (sentryResponseLog) {
            showLog("RECEIVE_USER_INFO", userInfoJson);
        } else {
            showLog("RECEIVE_USER_INFO");
        }
        pingWithDelay();
        messageCallbacks.remove(messageUniqueId);
        listenerManager.callOnUserInfo(userInfoJson, chatResponse);
    }
}
Also used : ResultUserInfo(com.fanap.podchat.model.ResultUserInfo) ChatResponse(com.fanap.podchat.model.ChatResponse) ResultUserInfo(com.fanap.podchat.model.ResultUserInfo) UserInfo(com.fanap.podchat.mainmodel.UserInfo)

Example 4 with UserInfo

use of com.fanap.podchat.mainmodel.UserInfo in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method getUserInfo.

/**
 * It Gets the information of the current user
 * <p>
 * set useCache = false to disable cache for only this function
 */
public String getUserInfo(boolean useCache, ChatHandler handler) {
    String uniqueId = generateUniqueId();
    Runnable cacheLoading = () -> {
        if (cache && useCache) {
            try {
                UserInfo userInfo = messageDatabaseHelper.getUserInfo();
                if (userInfo != null) {
                    ChatResponse<ResultUserInfo> chatResponse = new ChatResponse<>();
                    ResultUserInfo result = new ResultUserInfo();
                    setUserId(userInfo.getId());
                    result.setUser(userInfo);
                    chatResponse.setResult(result);
                    chatResponse.setCache(true);
                    chatResponse.setUniqueId(uniqueId);
                    String userInfoJson = gson.toJson(chatResponse);
                    listenerManager.callOnUserInfo(userInfoJson, chatResponse);
                    showLog("CACHE_USER_INFO", userInfoJson);
                }
            } catch (Exception e) {
                showErrorLog(e.getMessage());
                onUnknownException(uniqueId, e);
            }
        }
    };
    Runnable requestServer = () -> {
        if (chatReady) {
            ChatMessage chatMessage = new ChatMessage();
            chatMessage.setType(Constants.USER_INFO);
            chatMessage.setUniqueId(uniqueId);
            chatMessage.setToken(getToken());
            chatMessage.setTokenIssuer("1");
            setCallBacks(null, null, null, true, Constants.USER_INFO, null, uniqueId);
            JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
            if (Util.isNullOrEmpty(getTypeCode())) {
                jsonObject.remove("typeCode");
            } else {
                jsonObject.remove("typeCode");
                jsonObject.addProperty("typeCode", getTypeCode());
            }
            String asyncContent = jsonObject.toString();
            showLog("SEND_USER_INFO", asyncContent);
            async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
            if (handler != null) {
                handler.onGetUserInfo(uniqueId);
            }
        } else
            onChatNotReady(uniqueId);
    };
    new PodThreadManager().addNewTask(cacheLoading).addNewTask(requestServer).runTasksSynced();
    return uniqueId;
}
Also used : PodThreadManager(com.fanap.podchat.util.PodThreadManager) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) ResultUserInfo(com.fanap.podchat.model.ResultUserInfo) ChatResponse(com.fanap.podchat.model.ChatResponse) JsonObject(com.google.gson.JsonObject) ResultUserInfo(com.fanap.podchat.model.ResultUserInfo) UserInfo(com.fanap.podchat.mainmodel.UserInfo) 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 5 with UserInfo

use of com.fanap.podchat.mainmodel.UserInfo in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getUserInfo.

public UserInfo getUserInfo() {
    UserInfo userInfo = new UserInfo();
    if (messageDao.getUserInfo() != null) {
        userInfo = messageDao.getUserInfo();
        if (userInfo != null && userInfo.getId() > 0) {
            ChatProfileVO chatProfileVO = getChatProfile(userInfo.getId());
            userInfo.setChatProfileVO(chatProfileVO);
        }
    }
    return userInfo;
}
Also used : ChatProfileVO(com.fanap.podchat.chat.user.profile.ChatProfileVO) UserInfo(com.fanap.podchat.mainmodel.UserInfo)

Aggregations

UserInfo (com.fanap.podchat.mainmodel.UserInfo)5 ChatResponse (com.fanap.podchat.model.ChatResponse)3 ResultUserInfo (com.fanap.podchat.model.ResultUserInfo)3 ChatProfileVO (com.fanap.podchat.chat.user.profile.ChatProfileVO)2 ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)2 RoomIntegrityException (com.fanap.podchat.persistance.RoomIntegrityException)2 PodChatException (com.fanap.podchat.util.PodChatException)2 PodThreadManager (com.fanap.podchat.util.PodThreadManager)2 JsonObject (com.google.gson.JsonObject)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 SentryException (io.sentry.core.protocol.SentryException)2 IOException (java.io.IOException)2 JSONException (org.json.JSONException)2