Search in sources :

Example 1 with SocialNetwork

use of com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork in project 360-Engine-for-Android by 360.

the class User method createPayload.

/**
     * @param payload
     * @return
     */
private ArrayList<NetworkPresence> createPayload(String userId, Hashtable<String, String> payload) {
    ArrayList<NetworkPresence> presenceList = new ArrayList<NetworkPresence>(payload.size());
    String parsedUserId = parseUserName(userId);
    String key = null;
    SocialNetwork network = null;
    String value = null;
    OnlineStatus status = null;
    for (Enumeration<String> en = payload.keys(); en.hasMoreElements(); ) {
        key = en.nextElement();
        network = SocialNetwork.getValue(key);
        if (network != null) {
            int keyIdx = network.ordinal();
            value = payload.get(key);
            if (value != null) {
                status = OnlineStatus.getValue(value);
                if (status != null) {
                    int valueIdx = status.ordinal();
                    presenceList.add(new NetworkPresence(parsedUserId, keyIdx, valueIdx));
                }
            }
        }
    }
    return presenceList;
}
Also used : ArrayList(java.util.ArrayList) SocialNetwork(com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork) OnlineStatus(com.vodafone360.people.datatypes.ContactSummary.OnlineStatus)

Example 2 with SocialNetwork

use of com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork in project 360-Engine-for-Android by 360.

the class PresenceDbUtils method processMeProfile.

/**
     * This method alters the User wrapper of me profile,
     *  and returns true if me profile information contains the ignored TPC networks information.
     * Based on the result this information may be deleted.
     * @param removePCPresence - if TRUE the PC network will be removed from the network list.
     * @param user - the me profile wrapper.
     * @param ignoredNetworks - the list if ignored integer network ids. 
     * @return
     */
private static boolean processMeProfile(boolean removePCPresence, User user, ArrayList<Integer> ignoredNetworks) {
    if (removePCPresence) {
        int max = OnlineStatus.OFFLINE.ordinal();
        // calculate the new aggregated presence status
        for (NetworkPresence presence : user.getPayload()) {
            if (presence.getOnlineStatusId() > max) {
                max = presence.getOnlineStatusId();
            }
        }
        user.setOverallOnline(max);
    }
    // the list of chat network ids in this User wrapper                
    ArrayList<Integer> userNetworks = new ArrayList<Integer>();
    ArrayList<NetworkPresence> payload = user.getPayload();
    for (NetworkPresence presence : payload) {
        int networkId = presence.getNetworkId();
        userNetworks.add(networkId);
        // 1. ignore offline TPC networks 
        if (presence.getOnlineStatusId() == OnlineStatus.OFFLINE.ordinal()) {
            ignoredNetworks.add(networkId);
        }
    }
    // 2. ignore the TPC networks presence state for which is unknown
    ArrayList<Identity> identities = EngineManager.getInstance().getIdentityEngine().getMyChattableIdentities();
    SocialNetwork network = null;
    for (Identity identity : identities) {
        network = SocialNetwork.getValue(identity.mNetwork);
        if (network != null) {
            if (!userNetworks.contains(network.ordinal())) {
                ignoredNetworks.add(network.ordinal());
            }
        }
    }
    return !ignoredNetworks.isEmpty();
}
Also used : ArrayList(java.util.ArrayList) SocialNetwork(com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork) Identity(com.vodafone360.people.datatypes.Identity)

Example 3 with SocialNetwork

use of com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork in project 360-Engine-for-Android by 360.

the class ChatDbUtilsTest method testConvertUserId.

/***
     * Test ChatDbUtils.convertUserIds() method with a given parameter
     * combination.
     *
     * @param userId User ID.
     * @param networkId Network ID.
     * @param localContactId Local Contact ID.
     * @param expectedUserId Expected User ID.
     * @param expectedNetwork Expected Network ID.
     * @param expectedLocalContactId Expected Local Contact ID.
     */
private void testConvertUserId(final String userId, final int networkId, final Long localContactId, final String expectedUserId, final SocialNetwork expectedNetwork, final Long expectedLocalContactId) {
    ChatMessage chatMessage = new ChatMessage();
    chatMessage.setUserId(userId);
    chatMessage.setNetworkId(networkId);
    chatMessage.setLocalContactId(localContactId);
    ChatDbUtils.convertUserIds(chatMessage, mDatabaseHelper);
    assertEquals("ChatDbUtilsTest.checkChatMessage() Unexpected user ID", expectedUserId, chatMessage.getUserId());
    assertEquals("ChatDbUtilsTest.checkChatMessage() Unexpected network ID [" + expectedNetwork + "]", expectedNetwork.ordinal(), chatMessage.getNetworkId());
    assertEquals("ChatDbUtilsTest.checkChatMessage() Unexpected local contact ID", expectedLocalContactId, chatMessage.getLocalContactId());
}
Also used : ChatMessage(com.vodafone360.people.datatypes.ChatMessage)

Example 4 with SocialNetwork

use of com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork in project 360-Engine-for-Android by 360.

the class ChatDbUtils method convertUserIds.

/***
     * Set the user ID, network ID and local contact ID values in the given
     * ChatMessage.
     *
     * The original msg.getUserId() is formatted <network>::<userId>, meaning
     * if "::" is present the values are split, otherwise the original value is
     * used.
     *
     * @param chatMessage ChatMessage to be altered.
     * @param databaseHelper DatabaseHelper with a readable database.
     */
public static void convertUserIds(final ChatMessage chatMessage, final DatabaseHelper databaseHelper) {
    /**
         * Use original User ID, in case of NumberFormatException (see
         * PAND-2356).
         */
    final String originalUserId = chatMessage.getUserId();
    int index = originalUserId.indexOf(COLUMNS);
    if (index > -1) {
        /** Parse a <networkId>::<userId> formatted user ID. **/
        chatMessage.setUserId(originalUserId.substring(index + COLUMNS.length()));
        String network = originalUserId.substring(0, index);
        /** Parse the <networkId> component. **/
        SocialNetwork sn = SocialNetwork.getValue(network);
        if (sn != null) {
            chatMessage.setNetworkId(sn.ordinal());
        } else {
            chatMessage.setNetworkId(SocialNetwork.INVALID.ordinal());
            LogUtils.logE("ChatUtils.convertUserIds() Invalid Network ID [" + network + "] in [" + originalUserId + "]");
        }
    }
    chatMessage.setLocalContactId(ContactDetailsTable.findLocalContactIdByKey(SocialNetwork.getSocialNetworkValue(chatMessage.getNetworkId()).toString(), chatMessage.getUserId(), ContactDetail.DetailKeys.VCARD_IMADDRESS, databaseHelper.getReadableDatabase()));
}
Also used : SocialNetwork(com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork)

Aggregations

SocialNetwork (com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork)3 ArrayList (java.util.ArrayList)2 ChatMessage (com.vodafone360.people.datatypes.ChatMessage)1 OnlineStatus (com.vodafone360.people.datatypes.ContactSummary.OnlineStatus)1 Identity (com.vodafone360.people.datatypes.Identity)1