Search in sources :

Example 1 with Constants

use of com.fanap.podchat.util.ChatMessageType.Constants in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method onReceivedMessage.

/**
 * First we check the message messageType and then we set the
 * the callback for it.
 * Here its showed the raw log.
 */
@Override
public void onReceivedMessage(String textMessage) throws IOException {
    super.onReceivedMessage(textMessage);
    int messageType = 0;
    ChatMessage chatMessage = gson.fromJson(textMessage, ChatMessage.class);
    if (rawLog) {
        Log.i(TAG, "RAW_LOG");
        Log.i(TAG, textMessage);
    }
    String messageUniqueId = chatMessage != null ? chatMessage.getUniqueId() : null;
    long threadId = chatMessage != null ? chatMessage.getSubjectId() : 0;
    Callback callback = null;
    if (messageCallbacks.containsKey(messageUniqueId)) {
        callback = messageCallbacks.get(messageUniqueId);
    }
    if (chatMessage != null) {
        messageType = chatMessage.getType();
    }
    @Constants int currentMessageType = messageType;
    switch(currentMessageType) {
        case Constants.ADD_PARTICIPANT:
        case Constants.SEEN_MESSAGE_LIST:
        case Constants.DELIVERED_MESSAGE_LIST:
        case Constants.UNBLOCK:
        case Constants.GET_CONTACTS:
        case Constants.MUTE_THREAD:
        case Constants.GET_BLOCKED:
        case Constants.RENAME:
        case Constants.THREAD_PARTICIPANTS:
        case Constants.UN_MUTE_THREAD:
        case Constants.USER_INFO:
        case Constants.LOCATION_PING:
        case Constants.GET_ACTIVE_CALL_PARTICIPANTS:
            handleResponseMessage(callback, chatMessage, messageUniqueId);
            break;
        case Constants.MUTE_CALL_PARTICIPANT:
            {
                handleOnCallParticipantMuted(callback, chatMessage);
                break;
            }
        case Constants.UN_MUTE_CALL_PARTICIPANT:
            {
                handleOnCallParticipantUnMuted(callback, chatMessage);
                break;
            }
        case Constants.CALL_CREATED:
            if (callback != null)
                handleOnCallCreated(chatMessage);
            break;
        case Constants.CONTACT_SYNCED:
            {
                handleOnContactsSynced(chatMessage);
                break;
            }
        case Constants.CLOSE_THREAD:
            {
                handleOnThreadClosed(chatMessage);
                break;
            }
        case Constants.CHANGE_THREAD_TYPE:
            {
                handleOnChangeThreadType(chatMessage);
                break;
            }
        case Constants.CREATE_BOT:
            {
                handleOnBotCreated(chatMessage);
                break;
            }
        case Constants.DEFINE_BOT_COMMAND:
            {
                handleOnBotCommandDefined(chatMessage);
                break;
            }
        case Constants.START_BOT:
            {
                handleOnBotStarted(chatMessage);
                break;
            }
        case Constants.GET_USER_BOTS:
            {
                handleOnUserBots(chatMessage);
                break;
            }
        case Constants.STOP_BOT:
            {
                handleOnBotStopped(chatMessage);
                break;
            }
        case Constants.REGISTER_FCM_USER_DEVICE:
            {
                PodNotificationManager.handleOnUserAndDeviceRegistered(chatMessage, context);
                break;
            }
        case Constants.UPDATE_FCM_APP_USERS_DEVICE:
            {
                PodNotificationManager.handleOnFCMTokenRefreshed(chatMessage, context);
                break;
            }
        case Constants.CALL_REQUEST:
            handleOnCallRequestReceived(chatMessage);
            break;
        case Constants.GROUP_CALL_REQUEST:
            handleOnGroupCallRequestReceived(chatMessage);
            break;
        case Constants.DELIVER_CALL_REQUEST:
            handleOnCallRequestDelivered(chatMessage, callback);
            break;
        case Constants.REJECT_CALL:
            handleOnCallRequestRejected(chatMessage);
            break;
        case Constants.CANCEL_GROUP_CALL:
            handleOnCallParticipantCanceledCall(chatMessage);
            break;
        // todo: handle multiple device start call
        case Constants.START_CALL:
            handleOnCallStarted(callback, chatMessage);
            break;
        case Constants.END_CALL:
            handleOnVoiceCallEnded(chatMessage);
            break;
        case Constants.LEAVE_CALL:
            handleOnCallParticipantLeft(chatMessage);
            break;
        case Constants.CALL_PARTICIPANT_JOINED:
            handleOnNewCallParticipantJoined(chatMessage);
            break;
        case Constants.REMOVE_CALL_PARTICIPANT:
            handleOnCallParticipantRemoved(chatMessage);
            break;
        case Constants.TURN_ON_VIDEO_CALL:
            handOnCallParticipantAddedVideo(chatMessage);
            break;
        case Constants.TURN_OFF_VIDEO_CALL:
            handleOnCallParticipantRemovedVideo(chatMessage);
            break;
        case Constants.START_SHARE_SCREEN:
            handOnShareScreenStarted(chatMessage, callback);
            break;
        case Constants.END_SHARE_SCREEN:
            handOnShareScreenEnded(chatMessage, callback);
            break;
        case Constants.START_RECORD_CALL:
            handleOnStartedCallRecord(chatMessage, callback);
            break;
        case Constants.END_RECORD_CALL:
            handleOnEndedCallRecord(chatMessage, callback);
            break;
        case Constants.GET_CALLS:
            handleOnGetCallsHistory(chatMessage, callback);
            break;
        case Constants.GET_CALLS_TO_JOIN:
            handleOnGetActiveCalls(chatMessage, callback);
            break;
        case Constants.CALL_RECONNECT:
            handleOnReceivedCallReconnect(chatMessage);
            break;
        case Constants.CALL_CONNECT:
            handleOnReceivedCallConnect(chatMessage);
            break;
        case Constants.CALL_CLIENT_ERRORS:
            handleOnReceivedClientCallErrors(chatMessage);
            break;
        case Constants.ALL_UNREAD_MESSAGE_COUNT:
            handleOnGetUnreadMessagesCount(chatMessage);
            break;
        case Constants.IS_NAME_AVAILABLE:
            handleIsNameAvailable(chatMessage);
            break;
        case Constants.JOIN_THREAD:
            handleOnJoinPublicThread(chatMessage);
            break;
        case Constants.UPDATE_CHAT_PROFILE:
            {
                handleOnChatProfileUpdated(chatMessage);
                break;
            }
        case Constants.REGISTER_ASSISTANT:
            {
                handleOnRegisterAssistant(chatMessage);
                break;
            }
        case Constants.DEACTIVE_ASSISTANT:
            {
                handleOnDeActiveAssistant(chatMessage);
                break;
            }
        case Constants.GET_ASSISTANTS:
            {
                handleOnGetAssistants(chatMessage);
                break;
            }
        case Constants.GET_ASSISTANT_HISTORY:
            {
                handleOnGetAssistantHistory(chatMessage);
                break;
            }
        case Constants.MUTUAL_GROUPS:
            {
                handleOnGetMutualGroups(chatMessage);
                break;
            }
        case Constants.BLOCK_ASSISTANT:
            {
                handleOnAssistantBlocked(chatMessage);
                break;
            }
        case Constants.UNBLOCK_ASSISTANT:
            {
                handleOnAssistantUnBlocked(chatMessage);
                break;
            }
        case Constants.GET_BLOCKED_ASSISTANTS:
            {
                handleOnAssistantsBlocks(chatMessage);
                break;
            }
        case Constants.GET_USER_ROLES:
            {
                handleOnGetUserRoles(chatMessage);
                break;
            }
        case Constants.UPDATE_LAST_SEEN:
            {
                handleUpdateLastSeen(chatMessage);
                break;
            }
        case Constants.PIN_MESSAGE:
            {
                handleOnPinMessage(chatMessage);
                break;
            }
        case Constants.UNPIN_MESSAGE:
            {
                handleOnUnPinMessage(chatMessage);
                break;
            }
        case Constants.EDIT_MESSAGE:
            handleEditMessage(chatMessage, messageUniqueId);
            break;
        case Constants.DELETE_MESSAGE:
            handleOutPutDeleteMsg(chatMessage);
            break;
        case Constants.UPDATE_THREAD_INFO:
            handleUpdateThreadInfo(chatMessage, messageUniqueId, callback);
            break;
        case Constants.BLOCK:
            handleOutPutBlock(chatMessage, messageUniqueId);
            break;
        case Constants.CHANGE_TYPE:
        case Constants.USER_STATUS:
        case Constants.RELATION_INFO:
        case Constants.GET_STATUS:
            break;
        case Constants.CREATE_TAG:
            handleOutPutAddTag(chatMessage, messageUniqueId);
            break;
        case Constants.EDIT_TAG:
            handleOutPutEditTag(chatMessage, messageUniqueId);
            break;
        case Constants.DELETE_TAG:
            handleOutPutDeleteTag(chatMessage, messageUniqueId);
            break;
        case Constants.ADD_TAG_PARTICIPANT:
            if (callback != null)
                handleOutPutAddParticipantTag(chatMessage, messageUniqueId, callback.getTagId());
            break;
        case Constants.ADD_CONTACT:
            handleOutPutAddContact(chatMessage);
            break;
        case Constants.REMOVE_CONTACT:
            if (callback != null)
                handleOutPutRemoveContact(chatMessage, callback.getUserId());
            break;
        case Constants.REMOVE_TAG_PARTICIPANT:
            if (callback != null)
                handleOutPutRemoveParticipantTag(chatMessage, messageUniqueId, callback.getTagId());
            break;
        case Constants.GET_TAG_LIST:
            handleOnTagList(chatMessage);
            break;
        case Constants.SENT:
            handleSent(chatMessage, messageUniqueId, threadId);
            break;
        case Constants.DELIVERY:
            handleDelivery(chatMessage, messageUniqueId, threadId);
            break;
        case Constants.SEEN:
            handleSeen(chatMessage, messageUniqueId, threadId);
            break;
        case Constants.ERROR:
            handleError(chatMessage);
            break;
        case Constants.FORWARD_MESSAGE:
            handleForwardMessage(chatMessage);
            break;
        case Constants.GET_HISTORY:
            /*Remove uniqueIds from waitQueue /***/
            if (callback == null) {
                if (hashTagCallBacks.get(messageUniqueId) != null) {
                    handleOnGetHashTagList(chatMessage);
                    hashTagCallBacks.remove(chatMessage.getUniqueId());
                } else if (handlerSend.get(messageUniqueId) != null)
                    handleRemoveFromWaitQueue(chatMessage);
                else
                    handleOnGetMentionList(chatMessage);
            } else {
                handleOnGetThreadHistory(callback, chatMessage);
            }
            break;
        case Constants.GET_THREADS:
            {
                if (threadInfoCompletor.containsKey(messageUniqueId)) {
                    threadInfoCompletor.get(messageUniqueId).onThreadInfoReceived(chatMessage);
                } else if (callback == null) {
                    handleGetThreads(null, chatMessage, messageUniqueId);
                } else
                    handleResponseMessage(callback, chatMessage, messageUniqueId);
                break;
            }
        case Constants.INVITATION:
            if (callback == null) {
                handleCreateThread(chatMessage, messageUniqueId);
            } else
                handleResponseMessage(callback, chatMessage, messageUniqueId);
            break;
        case Constants.REMOVED_FROM_THREAD:
            handleRemoveFromThread(chatMessage);
            break;
        case Constants.LEAVE_THREAD:
            handleOutPutLeaveThread(null, chatMessage, messageUniqueId);
            break;
        case Constants.MESSAGE:
            {
                handleNewMessage(chatMessage);
                break;
            }
        case Constants.PING:
            handleOnPing(chatMessage);
            break;
        case Constants.REMOVE_PARTICIPANT:
            if (callback == null) {
                handleOutPutRemoveParticipant(null, chatMessage, messageUniqueId);
            } else
                handleResponseMessage(callback, chatMessage, messageUniqueId);
            break;
        case Constants.THREAD_INFO_UPDATED:
            handleThreadInfoUpdated(chatMessage);
            break;
        case Constants.LAST_MESSAGE_DELETED:
            {
                handleOnLastMessageDeleted(chatMessage);
                break;
            }
        case Constants.LAST_MESSAGE_EDITED:
            {
                handleOnLastMessageEdited(chatMessage);
                break;
            }
        case Constants.LAST_SEEN_UPDATED:
            handleLastSeenUpdated(chatMessage);
            break;
        case Constants.SPAM_PV_THREAD:
            handleOutPutSpamPVThread(chatMessage, messageUniqueId);
            break;
        case Constants.SET_ROLE_TO_USER:
            handleSetRole(chatMessage);
            break;
        case Constants.REMOVE_ROLE_FROM_USER:
            handleRemoveRole(chatMessage);
            break;
        case Constants.CLEAR_HISTORY:
            handleClearHistory(chatMessage);
            break;
        case Constants.PIN_THREAD:
            handleOnPinThread(chatMessage);
            break;
        case Constants.UNPIN_THREAD:
            handOnUnPinThread(chatMessage);
            break;
        case Constants.GET_NOT_SEEN_DURATION:
            handleGetNotSeenDuration(callback, chatMessage, messageUniqueId);
            break;
        case Constants.SYSTEM_MESSAGE:
            handleSystemMessage(callback, chatMessage, messageUniqueId);
            break;
    }
}
Also used : Callback(com.fanap.podchat.util.Callback) ChatMessage(com.fanap.podchat.mainmodel.ChatMessage) Constants(com.fanap.podchat.util.ChatMessageType.Constants)

Aggregations

ChatMessage (com.fanap.podchat.mainmodel.ChatMessage)1 Callback (com.fanap.podchat.util.Callback)1 Constants (com.fanap.podchat.util.ChatMessageType.Constants)1