Mercurial > eldonilo > lightstring
changeset 32:8b739d4e094b
[presence] Don’t require the object to be passed.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 28 Jan 2012 04:02:10 +0100 |
parents | fbb08a31921d |
children | 88d24231bf24 |
files | plugins/presence.js |
diffstat | 1 files changed, 21 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/presence.js +++ b/plugins/presence.js @@ -24,32 +24,34 @@ 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) { + var payloads = ""; + var attributs = ""; + if (object.type && legal_types.indexOf(object.type) !== -1) + attributs += " type='" + object.type + "'"; - if (object.type && legal_types.indexOf(object.type) !== -1) - attributs += " type='" + object.type + "'"; + if (object.priority) + payloads += "<priority>" + object.priority + "</priority>"; - if (object.priority) - payloads += "<priority>" + object.priority + "</priority>"; + if (object.show) + payloads += "<show>" + object.show + "</show>"; - if (object.show) - payloads += "<show>" + object.show + "</show>"; + if (object.status) + payloads += "<status>" + object.status + "</status>"; - if (object.status) - payloads += "<status>" + object.status + "</status>"; + if (object.payload) + payloads += object.payload; - if (object.payload) - payloads += object.payload; + if (payloads) + return "<presence" + attributs + ">" + payloads + "</presence>"; + else + return "<presence" + attributs + "/>"; - if (payloads) - return "<presence" + attributs + ">" + payloads + "</presence>"; - else - return "<presence" + attributs + "/>"; + } else + return "<presence/>"; }; - Lightstring.presence = function(aConnection, aPriority) { - aConnection.send(Lightstring.stanza.presence(aPriority)); + Lightstring.presence = function(aConnection, aObject) { + aConnection.send(Lightstring.stanza.presence(aObject)); }; })();