Search in sources :

Example 6 with ChatMessage

use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.

the class PresenceEngine method handleNewConversationId.

private void handleNewConversationId(Conversation conversation) {
    if (conversation.getTos() != null) {
        String to = conversation.getTos().get(0);
        if (mSendMessagesHash.containsKey(to)) {
            ChatMessage message = mSendMessagesHash.get(to);
            message.setConversationId(conversation.getConversationId());
            /**
             * Update the DB with an outgoing message. *
             */
            updateChatDatabase(message, TimelineSummaryItem.Type.OUTGOING);
            Chat.sendChatMessage(message);
            // clean check if DB needs a cleaning (except for
            // the current conversation id)
            ChatDbUtils.cleanOldConversationsExceptForContact(message.getLocalContactId(), mDbHelper);
        }
    }
}
Also used : ChatMessage(com.vodafone360.people.datatypes.ChatMessage)

Example 7 with ChatMessage

use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.

the class PresenceEngine method updateChatDatabase.

/**
 * Updates the database with the given ChatMessage and Type.
 *
 * @param message ChatMessage.
 * @param type TimelineSummaryItem.Type.
 */
private void updateChatDatabase(ChatMessage message, TimelineSummaryItem.Type type) {
    ChatDbUtils.convertUserIds(message, mDbHelper);
    LogUtils.logD("PresenceEngine.updateChatDatabase() with [" + type.name() + "] message");
    if (message.getLocalContactId() == null || message.getLocalContactId() < 0) {
        LogUtils.logE("PresenceEngine.updateChatDatabase() " + "WILL NOT UPDATE THE DB! - INVALID localContactId = " + message.getLocalContactId());
        return;
    }
    /**
     * We mark all incoming messages as unread. *
     */
    ChatDbUtils.saveChatMessageAsATimeline(message, type, mDbHelper);
    UiAgent uiAgent = mEventCallback.getUiAgent();
    if (uiAgent != null && (message.getLocalContactId() != -1)) {
        uiAgent.updateChat(message.getLocalContactId(), true, message.getNetworkId());
    }
}
Also used : UiAgent(com.vodafone360.people.service.agent.UiAgent)

Example 8 with ChatMessage

use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.

the class PresenceEngine method processUiRequest.

@Override
protected void processUiRequest(ServiceUiRequest requestId, Object data) {
    if (!isFirstTimeSyncComplete()) {
        LogUtils.logE("PresenceEngine.processUIRequest():" + " Can't run PresenceEngine before the contact list is downloaded:1");
        return;
    }
    LogUtils.logW("PresenceEngine.processUiRequest() requestId.name[" + requestId.name() + "]");
    if (data == null && requestId != ServiceUiRequest.GET_PRESENCE_LIST) {
        LogUtils.logW("PresenceEngine.processUiRequest() skipping processing for request with no data!");
        return;
    }
    switch(requestId) {
        case SET_MY_AVAILABILITY:
            Hashtable<String, String> presenceHash = (Hashtable<String, String>) data;
            notifyUiAgentOfRequest(Presence.setMyAvailability(presenceHash), presenceHash);
            break;
        case GET_PRESENCE_LIST:
            Presence.getPresenceList(EngineId.PRESENCE_ENGINE, null);
            break;
        case CREATE_CONVERSATION:
            List<String> tos = ((ChatMessage) data).getTos();
            LogUtils.logW("PresenceEngine processUiRequest() CREATE_CONVERSATION with: " + tos);
            Chat.startChat(tos);
            break;
        case SEND_CHAT_MESSAGE:
            ChatMessage msg = (ChatMessage) data;
            updateChatDatabase(msg, TimelineSummaryItem.Type.OUTGOING);
            // cache the message (necessary for failed message sending failures)
            mSendMessagesHash.put(msg.getTos().get(0), msg);
            Chat.sendChatMessage(msg);
            break;
        default:
            LogUtils.logE("PresenceEngine processUiRequest() Unhandled UI request [" + requestId.name() + "]");
            // don't complete with success and schedule the next runtime
            return;
    }
    completeUiRequest(ServiceStatus.SUCCESS, null);
    setTimeout(CHECK_FREQUENCY);
}
Also used : ChatMessage(com.vodafone360.people.datatypes.ChatMessage) Hashtable(java.util.Hashtable)

Example 9 with ChatMessage

use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.

the class PresenceEngine method handleSystemNotification.

private void handleSystemNotification(SystemNotification sn) {
    LogUtils.logE("PresenceEngine.handleServerResponse(): " + sn);
    switch(sn.getSysCode()) {
        case SEND_MESSAGE_FAILED:
            ChatMessage msg = mSendMessagesHash.get(sn.getInfo().get(Tags.TOS.toString()));
            if (msg != null) {
                ChatDbUtils.deleteUnsentMessage(mDbHelper, msg);
            }
            showErrorNotification(ServiceUiRequest.UNSOLICITED_CHAT_ERROR_REFRESH, null);
            break;
        case CONVERSATION_NULL:
            if (!mSendMessagesHash.isEmpty()) {
                mSendMessagesHash.remove(sn.getInfo().get(Tags.TOS.toString()));
            }
            showErrorNotification(ServiceUiRequest.UNSOLICITED_CHAT_ERROR, null);
            break;
        case COMMUNITY_LOGOUT_SUCCESSFUL:
            break;
        default:
            LogUtils.logE("PresenceEngine.handleServerResponse()" + " - unhandled notification: " + sn);
    }
}
Also used : ChatMessage(com.vodafone360.people.datatypes.ChatMessage)

Example 10 with ChatMessage

use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.

the class Chat method sendChatMessage.

// function?
/**
 * Sends chat message to server
 *
 * @param msg - ChatMessage to be sent
 * @return request id
 */
public static int sendChatMessage(ChatMessage msg) {
    if (msg.getTos() == null) {
        LogUtils.logE("Chat.sentChatMessage() msg.mTos can't be null");
        return -1;
    }
    if (msg.getBody() == null) {
        LogUtils.logE("Chat.sentChatMessage() msg.mBody can't be null");
        return -1;
    }
    if (msg.getConversationId() == null) {
        LogUtils.logE("Chat.sentChatMessage() msg.mConversationId can't be null");
        return -1;
    }
    Request request = new Request(EMPTY, Request.Type.SEND_CHAT_MESSAGE, EngineId.PRESENCE_ENGINE, true, Settings.API_REQUESTS_TIMEOUT_CHAT_SEND_MESSAGE);
    request.addData(ChatMessage.Tags.BODY.tag(), msg.getBody());
    request.addData(ChatMessage.Tags.RECIPIENTS_LIST.tag(), msg.getTos());
    request.addData(ChatMessage.Tags.CONVERSATION_ID.tag(), msg.getConversationId());
    QueueManager queue = QueueManager.getInstance();
    int requestId = queue.addRequest(request);
    queue.fireQueueStateChanged();
    return requestId;
}
Also used : Request(com.vodafone360.people.service.io.Request) QueueManager(com.vodafone360.people.service.io.QueueManager)

Aggregations

ChatMessage (com.vodafone360.people.datatypes.ChatMessage)5 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 TimelineSummaryItem (com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem)1 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)1 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)1 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)1 SocialNetwork (com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork)1 ServiceStatus (com.vodafone360.people.service.ServiceStatus)1 UiAgent (com.vodafone360.people.service.agent.UiAgent)1 QueueManager (com.vodafone360.people.service.io.QueueManager)1 Request (com.vodafone360.people.service.io.Request)1 Date (java.util.Date)1 Hashtable (java.util.Hashtable)1