/* Jappix - An open social platform These are the chatstate JS script for Jappix ------------------------------------------------- License: AGPL Author: Vanaryon Last revision: 25/08/11 */ // Sends a given chatstate to a given entity function chatStateSend(state, xid, hash) { var user_type = $('#' + hash).attr('data-type'); // If the friend client supports chatstates and is online if((user_type == 'groupchat') || ((user_type == 'chat') && $('#' + hash + ' .message-area').attr('data-chatstates') && !exists('#page-switch .' + hash + ' .unavailable'))) { // Already sent? if(getDB('currentchatstate', xid) == state) return; // Write the state setDB('currentchatstate', xid, state); // New message stanza var aMsg = new JSJaCMessage(); aMsg.setTo(xid); aMsg.setType(user_type); // Append the chatstate node aMsg.appendNode(state, {'xmlns': NS_CHATSTATES}); // Send this! con.send(aMsg); } } // Displays a given chatstate in a given chat function displayChatState(state, hash, type) { // Groupchat? if(type == 'groupchat') { resetChatState(hash, type); // "gone" state not allowed if(state != 'gone') $('#page-engine .page-engine-chan .user.' + hash).addClass(state); } // Chat else { // We change the buddy name color in the page-switch resetChatState(hash, type); $('#page-switch .' + hash + ' .name').addClass(state); // We generate the chatstate text var text = ''; switch(state) { // Active case 'active': text = _e("Your friend is paying attention to the conversation."); break; // Composing case 'composing': text = _e("Your friend is writing a message..."); break; // Paused case 'paused': text = _e("Your friend stopped writing a message."); break; // Inactive case 'inactive': text = _e("Your friend is doing something else."); break; // Gone case 'gone': text = _e("Your friend closed the chat."); break; } // We reset the previous state $('#' + hash + ' .chatstate').remove(); // We create the chatstate $('#' + hash + ' .content').after('