/* Jappix - An open social platform These are the chatstate JS script for Jappix ------------------------------------------------- License: AGPL Author: Valérian Saliou */ // Bundle var ChatState = (function () { /** * Alias of this * @private */ var self = {}; /** * Sends a given chatstate to a given entity * @public * @param {string} state * @param {string} xid * @param {string} hash * @return {undefined} */ self.send = function(state, xid, hash) { try { 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') && !Common.exists('#page-switch .' + hash + ' .unavailable'))) { // Already sent? if(DataStore.getDB(Connection.desktop_hash, 'currentchatstate', xid) == state) { return; } // Write the state DataStore.setDB(Connection.desktop_hash, '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); } } catch(e) { Console.error('ChatState.send', e); } }; /** * Displays a given chatstate in a given chat * @public * @param {string} state * @param {string} hash * @param {string} type * @return {undefined} */ self.display = function(state, hash, type) { try { // Groupchat? if(type == 'groupchat') { self.reset(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 self.reset(hash, type); $('#page-switch .' + hash + ' .name').addClass(state); // We generate the chatstate text var text = ''; switch(state) { // Active case 'active': text = Common._e("Your friend is paying attention to the conversation."); break; // Composing case 'composing': text = Common._e("Your friend is writing a message..."); break; // Paused case 'paused': text = Common._e("Your friend stopped writing a message."); break; // Inactive case 'inactive': text = Common._e("Your friend is doing something else."); break; // Gone case 'gone': text = Common._e("Your friend closed the chat."); break; } // We reset the previous state $('#' + hash + ' .chatstate').remove(); // We create the chatstate $('#' + hash + ' .content').after( '