# HG changeset patch # User Emmanuel Gil Peyrot # Date 1327715925 -3600 # Node ID fbb08a31921de22e01efae6c3a3f4ac17b68feca # Parent 1506992c33e247c0164b9e3eb1938354a6ec1961 Improve the presence plugin. diff --git a/plugins/presence.js b/plugins/presence.js --- a/plugins/presence.js +++ b/plugins/presence.js @@ -2,6 +2,7 @@ /** Copyright (c) 2011, Sonny Piers + Copyright (c) 2012, Emmanuel Gil Peyrot Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -19,12 +20,36 @@ //////////// //Presence// http://xmpp.org/rfcs/rfc6121.html#presence //////////// -Lightstring.stanza.presence = function(aPriority) { - if(aPriority) - return ""+aPriority+""; - else - return ""; -}; -Lightstring.presence = function(aConnection, aPriority) { - aConnection.send(Lightstring.stanza.presence(aPriority)); -}; +(function() { + var legal_types = ['error', 'probe', 'subscribe', 'subscribed', 'unavailable', 'unsubscribe', 'unsubscribed']; + + Lightstring.stanza.presence = function(object) { + var aPriority, aShow, aStatus; + var payloads = ""; + var attributs = ""; + + if (object.type && legal_types.indexOf(object.type) !== -1) + attributs += " type='" + object.type + "'"; + + if (object.priority) + payloads += "" + object.priority + ""; + + if (object.show) + payloads += "" + object.show + ""; + + if (object.status) + payloads += "" + object.status + ""; + + if (object.payload) + payloads += object.payload; + + if (payloads) + return "" + payloads + ""; + else + return ""; + }; + + Lightstring.presence = function(aConnection, aPriority) { + aConnection.send(Lightstring.stanza.presence(aPriority)); + }; +})();